def test_provided_stop_func(self): s = Spawnable() q = Mock() f_stop = s.make_default_stop_func(q) f_stop() q.put.assert_called_once_with(Spawnable.STOP)
def test_wait_called(self): s = Spawnable() process = Mock() f1 = Mock() s.add_spawn_function(f1) s.start(process) s.stop() timeout = Mock() s.wait(timeout) process.spawn.return_value.wait.assert_called_once_with( timeout=timeout)
def test_start_stop(self): s = Spawnable() process = Mock() f1 = Mock() f1_stop = Mock() f2 = Mock() s.add_spawn_function(f1, f1_stop) s.add_spawn_function(f2) s.start(process) spawned_args = process.spawn.call_args_list self.assertEqual([call(f1), call(f2)], spawned_args) s.stop() f1_stop.assert_called_once_with()
def test_start_default_values(self): s = Spawnable() s.process = Mock() f = Mock() s.add_spawn_function(f) s.start() s.process.spawn.assert_called_once_with(f)
def test_start_stop_order(self): s = Spawnable() f1, f1_stop = Mock(), Mock() f2, f2_stop = Mock(), Mock() f3 = Mock() f4, f4_stop = Mock(), Mock() stop_parent = Mock() stop_parent.attach_mock(f1_stop, "f1_stop") stop_parent.attach_mock(f2_stop, "f2_stop") stop_parent.attach_mock(f4_stop, "f4_stop") s.add_spawn_function(f1, f1_stop) s.add_spawn_function(f2, f2_stop) s.add_spawn_function(f3) s.add_spawn_function(f4, f4_stop) process = Mock() s.start(process) self.assertEquals([call(f1), call(f2), call(f3), call(f4)], process.spawn.call_args_list) s.stop() self.assertEquals( [call.f4_stop(), call.f2_stop(), call.f1_stop()], stop_parent.method_calls)
def test_start_stop_order(self): s = Spawnable() f1, f1_stop = Mock(), Mock() f2, f2_stop = Mock(), Mock() f3 = Mock() f4, f4_stop = Mock(), Mock() stop_parent = Mock() stop_parent.attach_mock(f1_stop, "f1_stop") stop_parent.attach_mock(f2_stop, "f2_stop") stop_parent.attach_mock(f4_stop, "f4_stop") s.add_spawn_function(f1, f1_stop) s.add_spawn_function(f2, f2_stop) s.add_spawn_function(f3) s.add_spawn_function(f4, f4_stop) process = Mock() s.start(process) self.assertEquals([call(f1), call(f2), call(f3), call(f4)], process.spawn.call_args_list) s.stop() self.assertEquals([call.f4_stop(), call.f2_stop(), call.f1_stop()], stop_parent.method_calls)