コード例 #1
0
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")
コード例 #2
0
ファイル: test_registry.py プロジェクト: Mitchell-boop/gaphor
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
コード例 #3
0
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
コード例 #4
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
 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)
コード例 #5
0
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
コード例 #6
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
    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)
コード例 #7
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
    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)
コード例 #8
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
 def test_lookup_too_many_keys(self):
     registry = Registry(("name", SimpleAxis()))
     self.assertRaises(ValueError, registry.lookup, "one", "two")
コード例 #9
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
 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")
コード例 #10
0
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
コード例 #11
0
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"
コード例 #12
0
def test_conflict_error():
    registry = Registry(("name", SimpleAxis()))
    registry.register(object(), name="foo")
    with pytest.raises(ValueError):
        registry.register(object, "foo")
コード例 #13
0
def test_lookup_too_many_keys():
    registry = Registry(("name", SimpleAxis()))
    with pytest.raises(ValueError):
        registry.register(registry.lookup("one", "two"))
コード例 #14
0
def test_register_too_many_keys():
    registry = Registry(("name", SimpleAxis()))
    with pytest.raises(ValueError):
        registry.register(object, "one", "two")
コード例 #15
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
 def test_conflict_error(self):
     registry = Registry(("name", SimpleAxis()))
     registry.register(object(), name="foo")
     self.assertRaises(ValueError, registry.register, object(), "foo")
コード例 #16
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
 def test_register_too_many_keys(self):
     registry = Registry(("name", SimpleAxis()))
     self.assertRaises(ValueError, registry.register, object(), "one", "two")
コード例 #17
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
 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")
コード例 #18
0
ファイル: test_registry.py プロジェクト: paulopperman/gaphor
 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)