Пример #1
0
 def test_add_callback_append(self):
     callback = lambda: None
     config = ConfigurationWithCallbacks()
     config.register_callback("foo", callback)
     self.assertEqual([callback], config.callbacks["foo"])
     config.register_callback("foo", callback, append=True)
     self.assertEqual([callback, callback], config.callbacks["foo"])
Пример #2
0
 def test_clear_callbacks(self):
     callback = lambda *_: None
     config = ConfigurationWithCallbacks()
     config.register_callback("foo", callback)
     config["foo"] = True
     config.clear(callbacks=True)
     self.assertEqual(config, {})
     self.assertEqual(config.callbacks, {})
Пример #3
0
    def test_callback_on_change(self):
        results = []

        def callback(change_type, key, value, old_value):
            results.append((change_type, key, value))

        config = ConfigurationWithCallbacks()
        config.register_callback("foo", callback)
        config["foo"] = True
        config["foo"] = False
        del config["foo"]

        self.assertEqual(results, [
            (LoggingConfiguration.CREATED, "foo", True),
            (LoggingConfiguration.MODIFIED, "foo", False),
            (LoggingConfiguration.DELETED, "foo", NOTSET)])
Пример #4
0
 def test_deregister_multiple_callback(self):
     callback = lambda: None
     config = ConfigurationWithCallbacks()
     config.register_callback("foo", callback)
     config.register_callback("foo", callback, append=True)
     config.deregister_callback("foo", callback)
     self.assertNotIn("foo", config.callbacks)
Пример #5
0
 def test_assert_callable(self):
     config = ConfigurationWithCallbacks()
     with self.assertRaises(AssertionError):
         config.register_callback("", None)