38 lines
2.0 KiB
Python
38 lines
2.0 KiB
Python
"""Pure temporary-file supervisor bookkeeping tests, no actual child launch."""
|
|
from pathlib import Path
|
|
import tempfile
|
|
from types import SimpleNamespace
|
|
import unittest
|
|
from unittest.mock import patch
|
|
import run_normal as R
|
|
|
|
class SupervisorTests(unittest.TestCase):
|
|
def test_launch_is_exclusive_not_completion(self):
|
|
with tempfile.TemporaryDirectory() as temp,patch.object(R,'CONTROL',Path(temp)),patch.object(R,'authority',return_value={}):
|
|
with patch.object(R.subprocess,'Popen',return_value=SimpleNamespace(pid=123)) as spawn:
|
|
record=R.launch('a'*64)
|
|
self.assertEqual(spawn.call_count,1)
|
|
self.assertTrue(spawn.call_args.kwargs['start_new_session'])
|
|
self.assertFalse(record['final_exit_observed'])
|
|
self.assertFalse((Path(temp)/'exit.json').exists())
|
|
with self.assertRaises(ValueError):R.launch('a'*64)
|
|
self.assertEqual(spawn.call_count,1)
|
|
|
|
def test_final_exit_is_parent_observed_not_learning(self):
|
|
with tempfile.TemporaryDirectory() as temp,patch.object(R,'CONTROL',Path(temp)),patch.object(R,'authority',return_value={}):
|
|
with patch.object(R.subprocess,'run',return_value=SimpleNamespace(returncode=0)):
|
|
self.assertEqual(R.supervise('b'*64),0)
|
|
record=R.read(Path(temp)/'exit.json')
|
|
self.assertTrue(record['complete'] and record['final_exit_observed'])
|
|
self.assertFalse(record['learning_success_claimed'])
|
|
|
|
def test_failed_spawn_has_no_fabricated_exit(self):
|
|
with tempfile.TemporaryDirectory() as temp,patch.object(R,'CONTROL',Path(temp)),patch.object(R,'authority',return_value={}):
|
|
with patch.object(R.subprocess,'run',side_effect=OSError('fixture')):
|
|
self.assertEqual(R.supervise('b'*64),1)
|
|
record=R.read(Path(temp)/'exit.json')
|
|
self.assertIsNone(record['exit_code'])
|
|
self.assertFalse(record['complete'] or record['final_exit_observed'])
|
|
|
|
if __name__=='__main__':unittest.main()
|