File size: 2,130 Bytes
095f297 5711ab3 095f297 5711ab3 26006ef 8f37329 26006ef 8f37329 9de8f1b 7105268 8f37329 7e8e4e0 8f37329 7e8e4e0 8f37329 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 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))
|