Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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()])
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
 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()])
Esempio n. 13
0
 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)
Esempio n. 14
0
 def test_init(self):
     p = Mock()
     n = Monitorable()
     self.assertIsNone(n._parent)
     n.set_parent(p, "notifier")
     self.assertEqual("notifier", n._name)
Esempio n. 15
0
 def test_init(self):
     p = Mock()
     n = Monitorable()
     self.assertFalse(hasattr(n, 'parent'))
     n.set_parent(p, "notifier")
     self.assertEqual("notifier", n.name)
Esempio n. 16
0
 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)
Esempio n. 17
0
 def test_init(self):
     m = Monitorable("mon")
     self.assertEqual("mon", m.name)
Esempio n. 18
0
 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)
Esempio n. 19
0
 def test_init(self):
     p = Mock()
     n = Monitorable()
     n.set_process_path(p, ["notifier"])
     self.assertEqual(["notifier"], n.process_path)