示例#1
0
def test_cannot_build_path_with_two_consecutive_rels():
    try:
        _ = Path(Node(name="Alice"), Rel("KNOWS"), Rel("KNOWS"), Node(name="Bob"))
    except JoinError:
        assert True
    else:
        assert False
示例#2
0
def test_path_hashes(graph):
    p1 = Path(Node("Person", name="Alice"), Rel("KNOWS", since=1999),
              Node("Person", name="Bob"))
    p2 = Path(Node("Person", name="Alice"), Rel("KNOWS", since=1999),
              Node("Person", name="Bob"))
    assert hash(p1) == hash(p2)
    graph.create(p1)
    assert hash(p1) != hash(p2)
示例#3
0
def test_changing_type_of_unbound_rel_mirrors_to_pair_rev():
    rel = Rel("KNOWS")
    assert rel.pair is None
    rev = -rel
    assert rel.pair is rev
    assert rev.pair is rel
    assert rel.type == "KNOWS"
    assert rev.type == "KNOWS"
    rel.type = "LIKES"
    assert rel.type == "LIKES"
    assert rev.type == "LIKES"
示例#4
0
def test_rel_and_rev_hashes(graph):
    assert hash(Rel("KNOWS")) == hash(Rel("KNOWS"))
    assert hash(Rel("KNOWS")) == -hash(Rev("KNOWS"))
    assert hash(Rel("KNOWS", well=True,
                    since=1999)) == hash(Rel("KNOWS", since=1999, well=True))
    rel_1 = Node("KNOWS", since=1999)
    graph.create(rel_1)
    rel_2 = Node("KNOWS", since=1999)
    rel_2.bind(rel_1.uri)
    assert rel_1 is not rel_2
    assert hash(rel_1) == hash(rel_2)
示例#5
0
def test_rel_cast():
    knows = Rel("KNOWS", since=1999)
    assert Rel.cast() == Rel()
    assert Rel.cast(None) is None
    assert Rel.cast(knows) is knows
    assert Rel.cast("KNOWS") == Rel("KNOWS")
    assert Rel.cast(since=1999) == Rel(since=1999)
    assert Rel.cast("KNOWS", since=1999) == Rel("KNOWS", since=1999)
    assert Rel.cast({"since": 1999}) == Rel(since=1999)
    assert Rel.cast(("KNOWS", {"since": 1999})) == knows
    assert Rel.cast(Relationship({}, "KNOWS", {})) == Rel("KNOWS")
示例#6
0
def test_rel_cannot_have_multiple_types():
    try:
        _ = Rel("LIKES", "HATES")
    except ValueError:
        assert True
    else:
        assert False
示例#7
0
def test_minimal_rel_hydrate():
    dehydrated = {
        "self": "http://localhost:7474/db/data/relationship/11",
    }
    hydrated = Rel.hydrate(dehydrated)
    assert isinstance(hydrated, Rel)
    assert hydrated.bound
    assert hydrated.resource.uri == dehydrated["self"]
示例#8
0
def test_rel_hydrate_with_type():
    dehydrated = {
        "self": "http://localhost:7474/db/data/relationship/11",
        "type": "KNOWS",
    }
    hydrated = Rel.hydrate(dehydrated)
    assert isinstance(hydrated, Rel)
    assert hydrated.type == dehydrated["type"]
    assert hydrated.bound
    assert hydrated.resource.uri == dehydrated["self"]
示例#9
0
def test_rel_hydrate_with_properties():
    dehydrated = {
        "self": "http://localhost:7474/db/data/relationship/11",
        "data": {
            "since": 1999,
        },
    }
    hydrated = Rel.hydrate(dehydrated)
    assert isinstance(hydrated, Rel)
    assert hydrated.properties == dehydrated["data"]
    assert hydrated.bound
    assert hydrated.resource.uri == dehydrated["self"]
示例#10
0
def test_full_rel_hydrate():
    dehydrated = {
        "extensions": {
        },
        "start": "http://localhost:7474/db/data/node/23",
        "property": "http://localhost:7474/db/data/relationship/11/properties/{key}",
        "self": "http://localhost:7474/db/data/relationship/11",
        "properties": "http://localhost:7474/db/data/relationship/11/properties",
        "type": "KNOWS",
        "end": "http://localhost:7474/db/data/node/22",
        "data": {
            "since": 1999,
        },
    }
    hydrated = Rel.hydrate(dehydrated)
    assert isinstance(hydrated, Rel)
    assert hydrated.type == dehydrated["type"]
    assert hydrated.properties == dehydrated["data"]
    assert hydrated.bound
    assert hydrated.resource.uri == dehydrated["self"]
示例#11
0
def test_rel_cast():
    knows = Rel("KNOWS", since=1999)
    assert Rel.cast() == Rel()
    assert Rel.cast(None) is None
    assert Rel.cast(knows) is knows
    assert Rel.cast("KNOWS") == Rel("KNOWS")
    assert Rel.cast(since=1999) == Rel(since=1999)
    assert Rel.cast("KNOWS", since=1999) == Rel("KNOWS", since=1999)
    assert Rel.cast({"since": 1999}) == Rel(since=1999)
    assert Rel.cast(("KNOWS", {"since": 1999})) == knows
    assert Rel.cast(Relationship({}, "KNOWS", {})) == Rel("KNOWS")
示例#12
0
def test_can_apply_unary_absolute_to_rel():
    before = Rel("KNOWS", since=1999)
    after = abs(before)
    assert isinstance(after, Rel)
    assert after.type == before.type
    assert after.properties == before.properties
示例#13
0
def test_can_apply_unary_negative_to_rel():
    before = Rel("KNOWS", since=1999)
    after = -before
    assert isinstance(after, Rev)
    assert after.type == before.type
    assert after.properties == before.properties
示例#14
0
def test_rel_never_equals_none():
    rel = Rel("KNOWS")
    none = None
    assert rel != none
示例#15
0
def test_type_of_unbound_rel_is_mutable():
    ab = Rel("KNOWS")
    ab.type = "LIKES"
    assert ab.type == "LIKES"
示例#16
0
def test_unbound_rel_representation():
    likes = Rel("LIKES")
    assert repr(likes) == "-[:LIKES]->"