def test_bad_lookup(): registry = Registry(("name", SimpleAxis()), ("grade", SimpleAxis())) with pytest.raises(ValueError): registry.register(1, foo=1) with pytest.raises(ValueError): registry.lookup(foo=1) with pytest.raises(ValueError): registry.register(1, "foo", name="foo")
def test_two_axes(): registry: Registry[Union[str, object]] = Registry(("type", TypeAxis()), ("name", SimpleAxis())) target1 = "one" registry.register(target1, object) target2 = "two" registry.register(target2, DummyA) target3 = "three" registry.register(target3, DummyA, "foo") context1 = object() assert registry.lookup(context1) == target1 context2 = DummyB() assert registry.lookup(context2) == target2 assert registry.lookup(context2, "foo") == target3 target4 = object() registry.register(target4, DummyB) assert registry.lookup(context2) == target4 assert registry.lookup(context2, "foo") == target3
def test_get_registration(): registry = Registry(("type", TypeAxis()), ("name", SimpleAxis())) registry.register("one", object) registry.register("two", DummyA, "foo") assert registry.get_registration(object) == "one" assert registry.get_registration(DummyA, "foo") == "two" assert registry.get_registration(object, "foo") is None assert registry.get_registration(DummyA) is None
def test_get_registration(self): registry = Registry(("type", TypeAxis()), ("name", SimpleAxis())) registry.register("one", object) registry.register("two", DummyA, "foo") self.assertEqual(registry.get_registration(object), "one") self.assertEqual(registry.get_registration(DummyA, "foo"), "two") self.assertEqual(registry.get_registration(object, "foo"), None) self.assertEqual(registry.get_registration(DummyA), None)
def test_one_axis_no_specificity(): registry = Registry(("foo", SimpleAxis())) a = object() b = object() registry.register(a) registry.register(b, "foo") assert registry.lookup() == a assert registry.lookup("foo") == b assert registry.lookup("bar") is None
def test_one_axis_no_specificity(self): registry = Registry(("foo", SimpleAxis())) a = object() b = object() registry.register(a) registry.register(b, "foo") self.assertEqual(registry.lookup(), a) self.assertEqual(registry.lookup("foo"), b) self.assertEqual(registry.lookup("bar"), None)
def test_two_axes(self): registry = Registry(("type", TypeAxis()), ("name", SimpleAxis())) target1 = "one" registry.register(target1, object) target2 = "two" registry.register(target2, DummyA) target3 = "three" registry.register(target3, DummyA, "foo") context1 = object() self.assertEqual(registry.lookup(context1), target1) context2 = DummyB() self.assertEqual(registry.lookup(context2), target2) self.assertEqual(registry.lookup(context2, "foo"), target3) target4 = object() registry.register(target4, DummyB) self.assertEqual(registry.lookup(context2), target4) self.assertEqual(registry.lookup(context2, "foo"), target3)
def test_lookup_too_many_keys(self): registry = Registry(("name", SimpleAxis())) self.assertRaises(ValueError, registry.lookup, "one", "two")
def test_skip_nodes(self): registry = Registry( ("one", SimpleAxis()), ("two", SimpleAxis()), ("three", SimpleAxis()) ) registry.register("foo", one=1, three=3) self.assertEqual(registry.lookup(1, three=3), "foo")
def test_miss(): registry = Registry( ("one", SimpleAxis()), ("two", SimpleAxis()), ("three", SimpleAxis()) ) registry.register("foo", 1, 2) assert registry.lookup(one=1, three=3) is None
def test_skip_nodes(): registry = Registry( ("one", SimpleAxis()), ("two", SimpleAxis()), ("three", SimpleAxis()) ) registry.register("foo", one=1, three=3) assert registry.lookup(1, three=3) == "foo"
def test_conflict_error(): registry = Registry(("name", SimpleAxis())) registry.register(object(), name="foo") with pytest.raises(ValueError): registry.register(object, "foo")
def test_lookup_too_many_keys(): registry = Registry(("name", SimpleAxis())) with pytest.raises(ValueError): registry.register(registry.lookup("one", "two"))
def test_register_too_many_keys(): registry = Registry(("name", SimpleAxis())) with pytest.raises(ValueError): registry.register(object, "one", "two")
def test_conflict_error(self): registry = Registry(("name", SimpleAxis())) registry.register(object(), name="foo") self.assertRaises(ValueError, registry.register, object(), "foo")
def test_register_too_many_keys(self): registry = Registry(("name", SimpleAxis())) self.assertRaises(ValueError, registry.register, object(), "one", "two")
def test_bad_lookup(self): registry = Registry(("name", SimpleAxis()), ("grade", SimpleAxis())) self.assertRaises(ValueError, registry.register, 1, foo=1) self.assertRaises(ValueError, registry.lookup, foo=1) self.assertRaises(ValueError, registry.register, 1, "foo", name="foo")
def test_miss(self): registry = Registry( ("one", SimpleAxis()), ("two", SimpleAxis()), ("three", SimpleAxis()) ) registry.register("foo", 1, 2) self.assertEqual(registry.lookup(one=1, three=3), None)