| import os |
| import unittest |
| from unittest.mock import patch |
|
|
| from Jobs.submit import _github_secrets, _status_json |
|
|
|
|
| class SubmitSecretTests(unittest.TestCase): |
| def test_smoke_does_not_require_github_secret(self): |
| with patch.dict(os.environ, {}, clear=True): |
| self.assertIsNone(_github_secrets("smoke")) |
|
|
| def test_backfill_reads_github_token(self): |
| with patch.dict(os.environ, {"GITHUB_TOKEN": "token-value"}, clear=True): |
| self.assertEqual(_github_secrets("backfill"), {"GITHUB_TOKEN": "token-value"}) |
|
|
| def test_schedule_accepts_gh_token_alias(self): |
| with patch.dict(os.environ, {"GH_TOKEN": "token-value"}, clear=True): |
| self.assertEqual(_github_secrets("schedule"), {"GITHUB_TOKEN": "token-value"}) |
|
|
| def test_publishing_fails_closed_without_token(self): |
| with patch.dict(os.environ, {}, clear=True): |
| with self.assertRaisesRegex(RuntimeError, "GITHUB_TOKEN or GH_TOKEN"): |
| _github_secrets("backfill") |
|
|
| def test_status_is_json_safe(self): |
| class Stage: |
| value = "RUNNING" |
|
|
| class Status: |
| stage = Stage() |
| message = None |
|
|
| class Job: |
| status = Status() |
|
|
| self.assertEqual(_status_json(Job()), {"stage": "RUNNING", "message": None}) |
|
|
| def test_job_uses_python3_executable(self): |
| from Jobs.submit import BOOTSTRAP |
|
|
| self.assertIn("snapshot_download", BOOTSTRAP) |
| self.assertIn("huggingface-hub==1.8.0", BOOTSTRAP) |
| self.assertIn("wheel>=0.38", BOOTSTRAP) |
| self.assertIn("os.execvpe", BOOTSTRAP) |
|
|
| def test_job_arguments_use_downloaded_config_path(self): |
| from Jobs.submit import _command_arguments |
|
|
| arguments = _command_arguments("smoke", "a" * 40) |
| self.assertIn("/tmp/translation-runner/configs/transformers-ja-job.yml", arguments) |
| self.assertEqual(arguments[0], "smoke-batching") |
|
|
| def test_backfill_arguments_include_force_flag(self): |
| from Jobs.submit import _command_arguments |
|
|
| self.assertIn("--force-backfill", _command_arguments("backfill", "a" * 40)) |
|
|