import unittest from model_server.session import Session class TestGetSessionObject(unittest.TestCase): def setUp(self) -> None: pass def test_single_session_instance(self): sesh = Session() self.assertIs(sesh, Session(), 'Re-initializing Session class returned a new object') from os.path import exists self.assertTrue(exists(sesh.session_log), 'Session did not create a log file in the correct place') self.assertTrue(exists(sesh.manifest_json), 'Session did not create a manifest JSON file in the correct place') def test_restart_session(self): sesh = Session() logfile1 = sesh.session_log sesh.restart() logfile2 = sesh.session_log self.assertIsNot(logfile1, logfile2, 'Restarting session does not generate new logfile') def test_session_records_workflow(self): import json from model_server.workflow import WorkflowRunRecord sesh = Session() di = WorkflowRunRecord( model_id='test_model', ) sesh.record_workflow_run(di) with open(sesh.manifest_json, 'r') as fh: do = json.load(fh) self.assertEqual(di.dict(), do, 'Manifest record is not correct')