class TestDaemons(unittest.TestCase): @classmethod def setUpClass(self): self.d1 = mock.Mock(name='d1', spec=Daemon) self.d1.name = 'd1' self.d2 = mock.Mock(name='d2', spec=Daemon) self.d2.name = 'd2' self.d3 = mock.Mock(name='d3', spec=Daemon) self.d3.name = 'd3' def setUp(self): self.daemons = Daemons( self.d1, g1=[self.d2, self.d3] ) def test_single_daemon(self): assert self.daemons['d1'] == DaemonGroup([self.d1]) def test_single_daemon_of_group(self): assert self.daemons['d2'] == DaemonGroup([self.d2]) def test_group_daemon(self): assert self.daemons['g1'] == DaemonGroup([self.d2, self.d3]) def test_no_daemon(self): with self.assertRaises(KeyError): self.daemons['g2'] def test_list(self): assert set(self.daemons) == {self.d1, self.d2, self.d3} def test_groups(self): assert list(self.daemons.groups()) == [DaemonGroup([self.d2, self.d3])] def test_all(self): assert self.daemons['all'] == DaemonGroup([self.d1, self.d2, self.d3]) def test_re_register_daemon(self): g1 = mock.Mock(name='g1', spec=Daemon) g1.name = 'g1' with self.assertRaises(ValueError): self.daemons.register(g1) def test_re_register_group(self): d4 = mock.Mock(name='d4', spec=Daemon) d4.name = 'd4' with self.assertRaises(ValueError): self.daemons.register(d4, group='d1')
def setUp(self): self.daemons = Daemons( self.d1, g1=[self.d2, self.d3] )