def test_component_kill(self): """ Check the kill is propagated. The case when component wasn't started yet is already tested elsewhere. """ class Process: def __init__(self): self.killed = False self.terminated = False def kill(self): self.killed = True def terminate(self): self.terminated = True process = Process() class ProcInfo: def __init__(self): self.process = process self.pid = 42 component = Component('component', self, 'needed', 'Address', [], ProcInfo) component.start() self.assertTrue(component.is_running()) component.kill() self.assertTrue(process.terminated) self.assertFalse(process.killed) process.terminated = False component.kill(True) self.assertTrue(process.killed) self.assertFalse(process.terminated)
def test_component_attributes(self): """ Test the default attributes of Component (not BaseComponent) and some of the methods we might be allowed to call. """ class TestProcInfo: def __init__(self): self.pid = 42 component = Component('component', self, 'needed', 'Address', ['hello'], TestProcInfo) self.assertEqual('component', component._process) self.assertEqual('component', component.name()) self.assertIsNone(component._procinfo) self.assertIsNone(component.pid()) self.assertEqual(['hello'], component._params) self.assertEqual('Address', component._address) self.assertFalse(component.is_running()) self.assertEqual({}, self.__registered_processes) component.start() self.assertTrue(component.is_running()) # Some versions of unittest miss assertIsInstance self.assertTrue(isinstance(component._procinfo, TestProcInfo)) self.assertEqual(42, component.pid()) self.assertEqual(component, self.__registered_processes.get(42))
def test_component_kill(self): """ Check the kill is propagated. The case when component wasn't started yet is already tested elsewhere. """ class Process: def __init__(self): self.killed = False self.terminated = False def kill(self): self.killed = True def terminate(self): self.terminated = True process = Process() class ProcInfo: def __init__(self): self.process = process self.pid = 42 component = Component('component', self, 'needed', 'Address', [], ProcInfo) component.start() self.assertTrue(component.running()) component.kill() self.assertTrue(process.terminated) self.assertFalse(process.killed) process.terminated = False component.kill(True) self.assertTrue(process.killed) self.assertFalse(process.terminated)
def test_component_start_stop_internal(self): """ Test the behavior of _stop_internal and _start_internal. """ component = Component('component', self, 'needed', 'Address') component.start() self.assertTrue(component.is_running()) self.assertEqual('component', self.__start_simple_params) component.pid = lambda: 42 component.stop() self.assertFalse(component.is_running()) self.assertEqual(('component', 'Address', 42), self.__stop_process_params)
def test_component_start_stop_internal(self): """ Test the behavior of _stop_internal and _start_internal. """ component = Component('component', self, 'needed', 'Address') component.start() self.assertTrue(component.running()) self.assertEqual('component', self.__start_simple_params) component.pid = lambda: 42 component.stop() self.assertFalse(component.running()) self.assertEqual(('component', 'Address', 42), self.__stop_process_params)
def test_component_attributes(self): """ Test the default attributes of Component (not BaseComponent) and some of the methods we might be allowed to call. """ class TestProcInfo: def __init__(self): self.pid = 42 component = Component('component', self, 'needed', 'Address', ['hello'], TestProcInfo) self.assertEqual('component', component._process) self.assertEqual('component', component.name()) self.assertIsNone(component._procinfo) self.assertIsNone(component.pid()) self.assertEqual(['hello'], component._params) self.assertEqual('Address', component._address) self.assertFalse(component.running()) self.assertEqual({}, self.__registered_processes) component.start() self.assertTrue(component.running()) # Some versions of unittest miss assertIsInstance self.assertTrue(isinstance(component._procinfo, TestProcInfo)) self.assertEqual(42, component.pid()) self.assertEqual(component, self.__registered_processes.get(42))