Skip to content

armgit / peach

Public Imported from GitHub
0

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

test(ci): 隔离源码布局与 CI 提供商环境

longmeidao7b4e35cf4c30
diff --git a/tests/test_reporting_transport.py b/tests/test_reporting_transport.py
index ec6d05f28..37a8b5cb8 100644
--- a/tests/test_reporting_transport.py
+++ b/tests/test_reporting_transport.py
@@ -96,7 +96,10 @@ class ReportingTransportTests(unittest.TestCase):
self.assertEqual(reporting.snapshot(self.config)["delivery"], {})
def test_identity_uses_only_finite_environment_and_verified_build_commit(self):
- with mock.patch.object(reporting_identity.sys, "frozen", False, create=True), \
+ source_root = Path(self.enterContext(tempfile.TemporaryDirectory())).resolve()
+ (source_root / ".git").write_text("gitdir: ../shared.git/worktrees/fixture\n", encoding="utf-8")
+ with mock.patch("peach.settings_file.PROJECT_ROOT", source_root), \
+ mock.patch.object(reporting_identity.sys, "frozen", False, create=True), \
mock.patch.object(reporting_identity, "_source_commit", return_value="a" * 40), \
mock.patch.dict(os.environ, {"PEACH_REPORTING_ENVIRONMENT": "private-host"}):
metadata = reporting_identity.event_metadata("errors")
diff --git a/tests/test_web_e2e.py b/tests/test_web_e2e.py
index 1ded1f561..c7b571715 100644
--- a/tests/test_web_e2e.py
+++ b/tests/test_web_e2e.py
@@ -605,10 +605,12 @@ class MissingPrerequisiteTests(unittest.TestCase):
e2e_concurrency(invalid)
def test_missing_prerequisites_skip_locally_and_fail_on_ci(self):
- with mock.patch.dict(os.environ, {"GITHUB_ACTIONS": "true"}):
- with self.assertRaisesRegex(AssertionError, "没有 npm"):
- missing_prerequisite("没有 npm")
- local = {key: value for key, value in os.environ.items() if key != "GITHUB_ACTIONS"}
+ for provider in ("GITHUB_ACTIONS", "GITLAB_CI"):
+ with self.subTest(provider=provider), mock.patch.dict(os.environ, {provider: "true"}, clear=True):
+ with self.assertRaisesRegex(AssertionError, "没有 npm"):
+ missing_prerequisite("没有 npm")
+ local = {key: value for key, value in os.environ.items()
+ if key not in {"GITHUB_ACTIONS", "GITLAB_CI"}}
with mock.patch.dict(os.environ, local, clear=True):
with self.assertRaises(unittest.SkipTest):
missing_prerequisite("没有 npm")