def test_parent(self): parent = Mock() parent.name = "parent" m = Monitorable("mon") m.set_parent(parent) self.assertIs(parent, m.parent) self.assertEquals("parent.mon", m._logger_name)
def test_nop_with_no_parent(self): change = [["test"], 123] n = Monitorable() with self.assertRaises(AttributeError): p = n.parent n.on_changed(change) self.assertEquals([["test"], 123], change)
def test_on_changed(self): changes = [ (["test_attr", "test_value"], 12), (["test_thing"], 231) ] parent = Mock() m = Monitorable("test_m") m.set_parent(parent) m.on_changed(changes) expected = [ (["test_m", "test_attr", "test_value"], 12), (["test_m", "test_thing"], 231) ] parent.on_changed.assert_called_once_with(expected)
def test_on_change_notify_flag_default(self): parent = Mock() n = Monitorable() n.set_parent(parent, "test_n") change = [[], Mock()] n.on_changed(change) parent.on_changed.assert_called_once_with(change, True)
def test_set_endpoint_no_notify(self): n = Monitorable() parent = Mock() endpoint = Mock() # Check that the mock looks like it is serializable self.assertTrue(hasattr(endpoint, "to_dict")) n.set_parent(parent, "test_n") n.endpoints = ["end"] n.set_endpoint_data("end", endpoint, notify=False) self.assertEqual(n.end, endpoint) self.assertEqual(parent.report_changes.called, False)
def test_set_endpoint(self): n = Monitorable() parent = Mock() endpoint = Mock() # Check that the mock looks like it is serializable self.assertTrue(hasattr(endpoint, "to_dict")) n.set_parent(parent, "test_n") n.endpoints = ["end"] n.set_endpoint_data("end", endpoint, notify=True) self.assertEqual(n.end, endpoint) parent.report_changes.assert_called_once_with([["test_n", "end"], endpoint.to_dict()])
def test_report_changed(self): change = [["test_attr", "test_value"], 12] parent = Mock() n = Monitorable() n.set_parent(parent, "test_n") notify = Mock() n.report_changes(change) expected = [["test_n", "test_attr", "test_value"], 12] parent.report_changes.assert_called_once_with(expected)
def test_on_changed(self): changes = [(["test_attr", "test_value"], 12), (["test_thing"], 231)] parent = Mock() m = Monitorable("test_m") m.set_parent(parent) m.on_changed(changes) expected = [(["test_m", "test_attr", "test_value"], 12), (["test_m", "test_thing"], 231)] parent.on_changed.assert_called_once_with(expected)
def test_set_endpoint_no_notify(self): n = Monitorable() parent = Mock() endpoint = Mock() # Check that the mock looks like it is serializable self.assertTrue(hasattr(endpoint, "to_dict")) n.set_process_path(parent, ("test_n",)) n.endpoints = ["end"] n.set_endpoint_data("end", endpoint, notify=False) self.assertEqual(n.end, endpoint) self.assertEqual(parent.report_changes.called, False)
def test_set_endpoint(self): n = Monitorable() parent = Mock() endpoint = Mock() # Check that the mock looks like it is serializable self.assertTrue(hasattr(endpoint, "to_dict")) notify = Mock() n.set_parent(parent, "test_n") n.set_endpoint(NO_VALIDATE, "end", endpoint, notify) self.assertEqual(n.end, endpoint) parent.on_changed.assert_called_once_with( [["test_n", "end"], endpoint.to_dict()], notify)
def test_set_endpoint(self): n = Monitorable() parent = Mock() endpoint = Mock() # Check that the mock looks like it is serializable self.assertTrue(hasattr(endpoint, "to_dict")) n.set_process_path(parent, ["test_n"]) n.endpoints = ["end"] n.set_endpoint_data("end", endpoint, notify=True) self.assertEqual(n.end, endpoint) parent.report_changes.assert_called_once_with( [["test_n", "end"], endpoint.to_dict()])
def test_nop_with_no_parent(self): change = [["test"], 123] n = Monitorable() self.assertIsNone(n._parent) n.report_changes(change) self.assertEquals([["test"], 123], change)
def test_init(self): p = Mock() n = Monitorable() self.assertIsNone(n._parent) n.set_parent(p, "notifier") self.assertEqual("notifier", n._name)
def test_init(self): p = Mock() n = Monitorable() self.assertFalse(hasattr(n, 'parent')) n.set_parent(p, "notifier") self.assertEqual("notifier", n.name)
def test_nop_with_no_parent(self): changes = [(["test"], 123)] m = Monitorable("test_m") self.assertIsNone(m.parent) m.on_changed(changes) self.assertEquals([(["test"], 123)], changes)
def test_init(self): m = Monitorable("mon") self.assertEqual("mon", m.name)
def test_nop_with_no_parent(self): changes = [ (["test"], 123) ] m = Monitorable("test_m") self.assertIsNone(m.parent) m.on_changed(changes) self.assertEquals([(["test"], 123)], changes)
def test_init(self): p = Mock() n = Monitorable() n.set_process_path(p, ["notifier"]) self.assertEqual(["notifier"], n.process_path)