Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(test): 以实际内容识别验证环境并隔离超时夹具

longmeidao23d97356db61
diff --git a/scripts/test_environment_identity.py b/scripts/test_environment_identity.py
index 314ed6fb2..a0a788c08 100644
--- a/scripts/test_environment_identity.py
+++ b/scripts/test_environment_identity.py
@@ -1,7 +1,6 @@
"""测试运行时的内容身份与浏览器定位。"""
from __future__ import annotations
-from functools import lru_cache
import hashlib
import json
import os
@@ -30,8 +29,7 @@ ENTRY_FLAGS = frozenset({'PYTHONPATH', 'PEACH_REPORTING_TEST_MODE', 'PEACH_TEST_
'PEACH_E2E_CHROME'})
-@lru_cache(maxsize=128)
-def _file_digest(path: str, modified: int, size: int) -> str:
+def _file_digest(path: str) -> str:
with open(path, 'rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
@@ -41,8 +39,7 @@ def file_identity(path) -> dict:
return {'available': False}
try:
item = Path(path)
- stat = item.stat()
- return {'sha256': _file_digest(str(item), stat.st_mtime_ns, stat.st_size)}
+ return {'sha256': _file_digest(str(item))}
except OSError as error:
return {'unavailable': type(error).__name__}
diff --git a/tests/test_media_io.py b/tests/test_media_io.py
index d22c66e05..eb90292c4 100644
--- a/tests/test_media_io.py
+++ b/tests/test_media_io.py
@@ -46,7 +46,7 @@ class MediaIoTests(unittest.TestCase):
children.append(child)
return child
def blocked(_command, **options):
- return original_run([sys.executable, '-c', 'import time; time.sleep(60)'], **options)
+ return original_run([sys._base_executable, '-c', 'import time; time.sleep(60)'], **options)
with patch.object(media_io, 'TIMEOUT_SECONDS', 0.2), \
patch.object(media_io.subprocess, 'run', side_effect=blocked), \
patch.object(media_io.subprocess, 'Popen', side_effect=spawn), \
diff --git a/tests/test_test_evidence.py b/tests/test_test_evidence.py
index 1cb37b5c6..a6a4e6eea 100644
--- a/tests/test_test_evidence.py
+++ b/tests/test_test_evidence.py
@@ -166,6 +166,7 @@ class EnvironmentIdentityTests(unittest.TestCase):
self.enterContext(mock.patch.object(evidence, 'python_identity', return_value={
'version': 'fixture-python', 'sites': []}))
self.enterContext(mock.patch.object(evidence, 'tool_identities', return_value={}))
+ self.enterContext(mock.patch.object(evidence.platform, 'platform', return_value='fixture-platform'))
self.packages = self.enterContext(mock.patch.object(evidence.importlib.metadata, 'distributions', return_value=[]))
def test_equivalent_interpreters_in_separate_worktrees_share_identity(self):
@@ -175,7 +176,9 @@ class EnvironmentIdentityTests(unittest.TestCase):
first = evidence.environment(self.root)
with mock.patch.object(evidence, 'interpreter', return_value=other):
self.assertEqual(evidence.environment(self.root), first)
+ stamp = other.stat()
other.write_bytes(b'another-runtime')
+ os.utime(other, ns=(stamp.st_atime_ns, stamp.st_mtime_ns))
with mock.patch.object(evidence, 'interpreter', return_value=other):
self.assertNotEqual(evidence.environment(self.root), first)