MCPcopy Create free account
hub / github.com/tiny-pilot/tinypilot / ExecuteTest

Class ExecuteTest

app/execute_test.py:52–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51
52class ExecuteTest(unittest.TestCase):
53
54 def test_process_with_result_child_completed(self):
55 process = execute.ProcessWithResult(target=do_nothing, daemon=True)
56 process.start()
57 process.join()
58 result = process.result()
59 self.assertTrue(result.was_successful())
60 self.assertEqual(
61 execute.ProcessResult(return_value=None, exception=None), result)
62
63 def test_process_with_result_child_not_completed(self):
64 process = execute.ProcessWithResult(target=sleep_1_second, daemon=True)
65 process.start()
66 # Get the result before the child process has completed.
67 self.assertIsNone(process.result())
68
69 # Clean up the running child process.
70 process.kill()
71
72 def test_process_with_result_child_exception(self):
73 # Silence stderr while the child exception is being raised to avoid
74 # polluting the terminal output.
75 with silence_stderr():
76 process = execute.ProcessWithResult(target=raise_exception,
77 daemon=True)
78 process.start()
79 process.join()
80 result = process.result()
81 self.assertFalse(result.was_successful())
82 self.assertEqual(
83 execute.ProcessResult(return_value=None, exception=mock.ANY),
84 result)
85 self.assertEqual('Child exception', str(result.exception))
86
87 def test_process_with_result_return_value(self):
88 process = execute.ProcessWithResult(target=return_string, daemon=True)
89 process.start()
90 process.join()
91 result = process.result()
92 self.assertTrue(result.was_successful())
93 self.assertEqual(
94 execute.ProcessResult(return_value='Done!', exception=None), result)
95
96 def test_execute_with_timeout_and_timeout_reached(self):
97 with self.assertRaises(TimeoutError):
98 execute.with_timeout(sleep_1_second, timeout_in_seconds=0.5)
99
100 def test_execute_with_timeout_return_value(self):
101 return_value = execute.with_timeout(return_string,
102 timeout_in_seconds=0.5)
103 self.assertEqual('Done!', return_value)
104
105 def test_execute_with_timeout_child_exception(self):
106 with silence_stderr():
107 with self.assertRaises(Exception) as ctx:
108 execute.with_timeout(raise_exception, timeout_in_seconds=0.5)
109 self.assertEqual('Child exception', str(ctx.exception))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected