def test__run_side_effects__with_return_value(self): """Test return_value is passed""" r = registry.Registry() def has_return_value(*args, **kwargs): assert "return_value" in kwargs r.add("foo", has_return_value) r._run_side_effects("foo", return_value=None)
def test_by_label(self): def test_func(): pass r = registry.Registry() r.add("foo", test_func) self.assertEqual(r.by_label("foo").items(), r.items()) self.assertEqual(r.by_label("foo"), {"foo": [test_func]}) self.assertEqual(r.by_label("bar"), {})
def test__run_side_effects__no_return_value(self, mock_run): """Test return_value is not passed""" def no_return_value(*args, **kwargz): assert "return_value" not in kwargz r = registry.Registry() r.add("foo", no_return_value) r._run_side_effects("foo") r._run_side_effects("foo", return_value=None)
def test_registry_add_contains(self): """Check that add and contains functions work together.""" def test_func(): pass r = registry.Registry() self.assertFalse(r.contains("foo", test_func)) r.add("foo", test_func) self.assertTrue(r.contains("foo", test_func))
def test_try_bind_all(self): def foo1(return_value): pass def foo2(arg1, return_value): pass def foo3(*args, return_value): pass def foo4(return_value, **kwargs): pass def foo5(arg1, **kwargs): pass r = registry.Registry() r.add("foo", foo1) r.add("foo", foo2) r.add("foo", foo3) r.add("foo", foo4) r.add("foo", foo5) r.try_bind_all("foo", 1) self.assertRaises(registry.SignatureMismatch, r.try_bind_all, "foo", 1, 2)