def test_task_file(self): """Test task file handling""" for ext in (".pulse", ".out", ".err", ".task", ".sh"): filename = os.path.join( os.path.expanduser("~"), ".sos", "tasks", "ffffffffffffffff" + ext ) if os.path.isfile(filename): os.remove(filename) params = TaskParams( name="ffffffffffffffff", global_def={}, task="b=a", sos_dict={"a": 1}, tags=["b", "a"], ) a = TaskFile("ffffffffffffffff") a.save(params) self.assertEqual(a.tags, "a b") for ext in (".pulse", ".out", ".err", ".sh"): with open( os.path.join( os.path.expanduser("~"), ".sos", "tasks", "ffffffffffffffff" + ext ), "w", ) as fh: fh.write(ext) self.assertFalse(a.has_stdout()) self.assertFalse(a.has_stderr()) a.add_outputs() # self.assertEqual(a.params.sos_dict["a"], 1) self.assertEqual(a.status, "new") a.status = "completed" self.assertLess(time.time() - a.last_updated, 2) self.assertEqual(a.status, "completed") # # get and reset info info = a.info a.status = "running" self.assertEqual(a.status, "running") a.info = info self.assertEqual(a.status, "completed") self.assertTrue(a.has_stdout()) # a.add_result({"ret_code": 5}) # a.tags = ["ee", "d"] self.assertEqual(a.tags, "d ee") # a.add_tags(['kk']) # self.assertEqual(a.tags.split(), ['d', 'ee', 'kk']) # self.assertEqual(a.params.sos_dict["a"], 1) self.assertEqual(a.params.task, "b=a") # self.assertEqual(a.stdout, ".out") self.assertEqual(a.stderr, ".err") self.assertEqual(a.pulse, ".pulse") self.assertEqual(a.shell, ".sh") self.assertTrue(a.has_stdout()) self.assertTrue(a.has_stderr()) self.assertTrue(a.has_pulse()) self.assertTrue(a.has_shell()) # # a.reset() self.assertEqual(a.status, "new") self.assertEqual(a.stdout, "") self.assertEqual(a.stderr, "") self.assertEqual(a.signature, {}) a.add_outputs() a.add_result({"ret_code": 5}) self.assertEqual(a.result["ret_code"], 5)
def testTaskFile(self): '''Test task file handling''' for ext in ('.pulse', '.out', '.err', '.task', '.sh'): filename = os.path.join(os.path.expanduser('~'), '.sos', 'tasks', 'ffffffffffffffff' + ext) if os.path.isfile(filename): os.remove(filename) params = TaskParams(name='ffffffffffffffff', global_def={}, task='b=a', sos_dict={'a': 1}, tags=['b', 'a']) a = TaskFile('ffffffffffffffff') a.save(params) self.assertEqual(a.tags, 'a b') for ext in ('.pulse', '.out', '.err', '.sh'): with open( os.path.join(os.path.expanduser('~'), '.sos', 'tasks', 'ffffffffffffffff' + ext), 'w') as fh: fh.write(ext) self.assertFalse(a.has_stdout()) self.assertFalse(a.has_stderr()) a.add_outputs() # self.assertEqual(a.params.sos_dict['a'], 1) self.assertEqual(a.status, 'new') a.status = 'completed' self.assertLess(time.time() - a.last_updated, 2) self.assertEqual(a.status, 'completed') # # get and reset info info = a.info a.status = 'running' self.assertEqual(a.status, 'running') a.info = info self.assertEqual(a.status, 'completed') self.assertTrue(a.has_stdout()) # a.add_result({'ret_code': 5}) # a.tags = ['ee', 'd'] self.assertEqual(a.tags, 'd ee') #a.add_tags(['kk']) #self.assertEqual(a.tags.split(), ['d', 'ee', 'kk']) # self.assertEqual(a.params.sos_dict['a'], 1) self.assertEqual(a.params.task, 'b=a') # self.assertEqual(a.stdout, '.out') self.assertEqual(a.stderr, '.err') self.assertEqual(a.pulse, '.pulse') self.assertEqual(a.shell, '.sh') self.assertTrue(a.has_stdout()) self.assertTrue(a.has_stderr()) self.assertTrue(a.has_pulse()) self.assertTrue(a.has_shell()) # # a.reset() self.assertEqual(a.status, 'new') self.assertEqual(a.stdout, '') self.assertEqual(a.stderr, '') self.assertEqual(a.signature, {}) a.add_outputs() a.add_result({'ret_code': 5}) self.assertEqual(a.result['ret_code'], 5)