31 lines
1.8 KiB
Python
31 lines
1.8 KiB
Python
import json
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
import run_s2_pilot_when_ready as waiter
|
|
|
|
|
|
class WaiterTests(unittest.TestCase):
|
|
def test_terminal_gate_requires_full_roster_no_global_stop(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
source=Path(tmp);self.assertFalse(waiter.preparation_terminal(source))
|
|
batch=dict(status='ATTEMPTS_COMPLETE',stop_reason=None,not_run_indices=[],jobs=[dict(index=i) for i in range(499)])
|
|
p=source/'batch-complete.json';p.write_text(json.dumps(batch));self.assertTrue(waiter.preparation_terminal(source))
|
|
for change in [dict(status='STOPPED'),dict(stop_reason='GLOBAL_CPU_LIMIT'),dict(not_run_indices=[498]),dict(jobs=batch['jobs'][:-1]),dict(jobs=[dict(index=0)]*499)]:
|
|
p.write_text(json.dumps(dict(batch,**change)))
|
|
with self.assertRaises((RuntimeError,ValueError)):waiter.preparation_terminal(source)
|
|
def test_stopped_preparation_does_not_finalize_or_use_gpu(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
source=Path(tmp)/'source';source.mkdir();(source/'batch-started.json').write_text('{}');(source/'contract.json').write_text('{}')
|
|
(source/'batch-complete.json').write_text('{"status":"STOPPED"}')
|
|
watch=Path(tmp)/'watch';root=Path(tmp)/'pilot'
|
|
with patch.object(waiter,'finalize') as finalize,patch.object(waiter,'pilot') as pilot:
|
|
with self.assertRaises(RuntimeError):waiter.run(source,root,watch,'synthetic')
|
|
finalize.assert_not_called();pilot.assert_not_called()
|
|
with self.assertRaises(FileExistsError):waiter.run(source,root,watch,'synthetic')
|
|
self.assertTrue((watch/'failure.json').exists());self.assertFalse(root.exists())
|
|
|
|
|
|
if __name__=='__main__':unittest.main(verbosity=2)
|