def test_command_tasks_handles_errors_correctly(self): # Given s = self._make_scheduler() cmd = 'python --junk' t = CommandTask(cmd, output_dir=self.sim_dir) self.assertFalse(t.complete()) # When t.run(s) try: wait_until(lambda: not t.complete()) except RuntimeError: pass # Then self.assertFalse(t.complete()) self.assertEqual(t.job_proxy.status(), 'error') # A new command task should still detect that the run failed, even # though the output directory exists. # Given t = CommandTask(cmd, output_dir=self.sim_dir) # When/Then self.assertFalse(t.complete())
def test_command_tasks_converts_dollar_output_dir(self): # Given s = self._make_scheduler() cmd = '''python -c "print('$output_dir')"''' t = CommandTask(cmd, output_dir=self.sim_dir) self.assertFalse(t.complete()) # When t.run(s) wait_until(lambda: not t.complete()) # Then self.assertTrue(t.complete()) self.assertEqual(t.job_proxy.status(), 'done') self.assertEqual(t.job_proxy.get_stdout().strip(), self.sim_dir)
def test_remote_command_tasks_complete_method_works(self): # Given s = self._make_scheduler() cmd = 'python -c "print(1)"' t = CommandTask(cmd, output_dir=self.sim_dir) self.assertFalse(t.complete()) self.assertFalse( os.path.exists(os.path.join(self.sim_dir, 'stdout.txt'))) # When t.run(s) wait_until(lambda: not t.complete()) # Then self.assertTrue(t.complete()) self.assertTrue( os.path.exists(os.path.join(self.sim_dir, 'stdout.txt'))) # Test that if we call it repeatedly that it does indeed return True self.assertTrue(t.complete())