Skip to content

Commit

Permalink
add and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-880 committed Nov 28, 2024
1 parent fbebc01 commit fa14f59
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 24 deletions.
170 changes: 163 additions & 7 deletions python/tests/test_graphdb/test_graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@ def test_graph_properties():
assert g.properties["prop 5"] == {"x": 1, "y": "ok"}

props = {"prop 4": 11, "prop 5": "world", "prop 6": False}
g.add_property(1, props)
g.add_properties(1, props)

props = {"prop 6": True}
g.add_property(2, props)
g.add_properties(2, props)

def history_test(key, value):
if value is None:
Expand Down Expand Up @@ -2054,7 +2054,7 @@ def check(g):
assert mg.nodes.collect()[0].name == "1"

props = {"prop 4": 11, "prop 5": "world", "prop 6": False}
mg.add_property(1, props)
mg.add_properties(1, props)

props = {"prop 1": 1, "prop 2": "hi", "prop 3": True}
mg.add_constant_properties(props)
Expand Down Expand Up @@ -2755,10 +2755,10 @@ def check(g):

def test_unique_temporal_properties():
g = Graph()
g.add_property(1, {"name": "tarzan"})
g.add_property(2, {"name": "tarzan2"})
g.add_property(3, {"name": "tarzan2"})
g.add_property(2, {"salary": "1000"})
g.add_properties(1, {"name": "tarzan"})
g.add_properties(2, {"name": "tarzan2"})
g.add_properties(3, {"name": "tarzan2"})
g.add_properties(2, {"salary": "1000"})
g.add_constant_properties({"type": "character"})
g.add_edge(1, 1, 2, properties={"status": "open"})
g.add_edge(2, 1, 2, properties={"status": "open"})
Expand Down Expand Up @@ -3057,6 +3057,162 @@ def test_edge_layer_properties():
assert g.edge("A", "B").properties == {"greeting": "namaste"}


def test_add_node_properties_ordered_by_secondary_index():
g = Graph()
g.add_node(1, "A", properties={"prop": 1}, secondary_index=3)
g.add_node(1, "A", properties={"prop": 2}, secondary_index=2)
g.add_node(1, "A", properties={"prop": 3}, secondary_index=1)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)]


def test_add_node_properties_overwritten_for_same_secondary_index():
g = Graph()
g.add_node(1, "A", properties={"prop": 1}, secondary_index=1)
g.add_node(1, "A", properties={"prop": 2}, secondary_index=1)
g.add_node(1, "A", properties={"prop": 3}, secondary_index=1)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 3)]

g = Graph()
g.add_node(1, "A", properties={"prop": 1}, secondary_index=1)
g.add_node(1, "A", properties={"prop": 2}, secondary_index=2)
g.add_node(1, "A", properties={"prop": 3}, secondary_index=2)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 1), (1, 3)]


def test_create_node_properties_ordered_by_secondary_index():
g = Graph()
g.create_node(1, "A", properties={"prop": 1}, secondary_index=3)
g.add_node(1, "A", properties={"prop": 2}, secondary_index=2)
g.add_node(1, "A", properties={"prop": 3}, secondary_index=1)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)]


def test_create_node_properties_overwritten_for_same_secondary_index():
g = Graph()
g.create_node(1, "A", properties={"prop": 1}, secondary_index=1)
g.add_node(1, "A", properties={"prop": 2}, secondary_index=1)
g.add_node(1, "A", properties={"prop": 3}, secondary_index=1)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 3)]

g = Graph()
g.create_node(1, "A", properties={"prop": 1}, secondary_index=1)
g.add_node(1, "A", properties={"prop": 2}, secondary_index=2)
g.add_node(1, "A", properties={"prop": 3}, secondary_index=2)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 1), (1, 3)]


def test_add_edge_properties_ordered_by_secondary_index():
g = Graph()
g.add_edge(1, "A", "B", properties={"prop": 1}, secondary_index=3)
g.add_edge(1, "A", "B", properties={"prop": 2}, secondary_index=2)
g.add_edge(1, "A", "B", properties={"prop": 3}, secondary_index=1)

assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)]


def test_add_edge_properties_overwritten_for_same_secondary_index():
g = Graph()
g.add_edge(1, "A", "B", properties={"prop": 1}, secondary_index=1)
g.add_edge(1, "A", "B", properties={"prop": 2}, secondary_index=1)
g.add_edge(1, "A", "B", properties={"prop": 3}, secondary_index=1)

assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3)]

g = Graph()
g.add_edge(1, "A", "B", properties={"prop": 1}, secondary_index=1)
g.add_edge(1, "A", "B", properties={"prop": 2}, secondary_index=2)
g.add_edge(1, "A", "B", properties={"prop": 3}, secondary_index=2)

assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 1), (1, 3)]


def test_add_properties_properties_ordered_by_secondary_index():
g = Graph()
g.add_properties(1, properties={"prop": 1}, secondary_index=3)
g.add_properties(1, properties={"prop": 2}, secondary_index=2)
g.add_properties(1, properties={"prop": 3}, secondary_index=1)

assert g.properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)]


def test_add_properties_properties_overwritten_for_same_secondary_index():
g = Graph()
g.add_properties(1, properties={"prop": 1}, secondary_index=1)
g.add_properties(1, properties={"prop": 2}, secondary_index=1)
g.add_properties(1, properties={"prop": 3}, secondary_index=1)

assert g.properties.temporal.get("prop").items() == [(1, 3)]

g = Graph()
g.add_properties(1, properties={"prop": 1}, secondary_index=1)
g.add_properties(1, properties={"prop": 2}, secondary_index=2)
g.add_properties(1, properties={"prop": 3}, secondary_index=2)

assert g.properties.temporal.get("prop").items() == [(1, 1), (1, 3)]


def test_node_add_updates_properties_ordered_by_secondary_index():
g = Graph()
g.add_node(1, "A")
g.node("A").add_updates(1, properties={"prop": 1}, secondary_index=3)
g.node("A").add_updates(1, properties={"prop": 2}, secondary_index=2)
g.node("A").add_updates(1, properties={"prop": 3}, secondary_index=1)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)]


def test_node_add_updates_properties_overwritten_for_same_secondary_index():
g = Graph()
g.add_node(1, "A")
g.node("A").add_updates(1, properties={"prop": 1}, secondary_index=1)
g.node("A").add_updates(1, properties={"prop": 2}, secondary_index=1)
g.node("A").add_updates(1, properties={"prop": 3}, secondary_index=1)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 3)]

g = Graph()
g.add_node(1, "A")
g.node("A").add_updates(1, properties={"prop": 1}, secondary_index=1)
g.node("A").add_updates(1, properties={"prop": 2}, secondary_index=2)
g.node("A").add_updates(1, properties={"prop": 3}, secondary_index=2)

assert g.node("A").properties.temporal.get("prop").items() == [(1, 1), (1, 3)]


def test_edge_add_updates_properties_ordered_by_secondary_index():
g = Graph()
g.add_edge(1, "A", "B")
g.edge("A", "B").add_updates(1, properties={"prop": 1}, secondary_index=3)
g.edge("A", "B").add_updates(1, properties={"prop": 2}, secondary_index=2)
g.edge("A", "B").add_updates(1, properties={"prop": 3}, secondary_index=1)

assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3), (1, 2), (1, 1)]


def test_edge_add_updates_properties_overwritten_for_same_secondary_index():
g = Graph()
g.add_edge(1, "A", "B")
g.edge("A", "B").add_updates(1, properties={"prop": 1}, secondary_index=1)
g.edge("A", "B").add_updates(1, properties={"prop": 2}, secondary_index=1)
g.edge("A", "B").add_updates(1, properties={"prop": 3}, secondary_index=1)

assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 3)]

g = Graph()
g.add_edge(1, "A", "B")
g.edge("A", "B").add_updates(1, properties={"prop": 1}, secondary_index=1)
g.edge("A", "B").add_updates(1, properties={"prop": 2}, secondary_index=2)
g.edge("A", "B").add_updates(1, properties={"prop": 3}, secondary_index=2)

assert g.edge("A", "B").properties.temporal.get("prop").items() == [(1, 1), (1, 3)]


@fixture
def datadir(tmpdir, request):
filename = request.module.__file__
Expand Down
5 changes: 4 additions & 1 deletion raphtory/src/core/entities/properties/tcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ mod tcell_tests {
let mut tcell = TCell::new(TimeIndexEntry::start(1), "Pometry");
tcell.set(TimeIndexEntry::start(1), "Pometry Inc.");

assert_eq!(tcell.iter_t().collect::<Vec<_>>(), vec![(1, &"Pometry")]);
assert_eq!(
tcell.iter_t().collect::<Vec<_>>(),
vec![(1, &"Pometry Inc.")]
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/core/entities/properties/tprop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ mod tprop_tests {

assert_eq!(
tprop.iter_t().collect::<Vec<_>>(),
vec![(1, "Pometry".into())]
vec![(1, "Pometry Inc.".into())]
);
}

Expand Down
14 changes: 0 additions & 14 deletions raphtory/src/db/api/view/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,6 @@ mod test_exploded_edges {
#[test]
fn test_add_properties_properties_ordered_by_secondary_index() {
let graph: Graph = Graph::new();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();

graph.add_properties((0, 3), [("prop", "1")]).unwrap();
graph.add_properties((0, 2), [("prop", "2")]).unwrap();
graph.add_properties((0, 1), [("prop", "3")]).unwrap();
Expand All @@ -843,10 +839,6 @@ mod test_exploded_edges {
#[test]
fn test_add_properties_properties_overwritten_for_same_secondary_index() {
let graph: Graph = Graph::new();
graph.add_edge((0, 1), 0, 1, NO_PROPS, None).unwrap();
graph.add_edge((0, 1), 0, 1, NO_PROPS, None).unwrap();
graph.add_edge((0, 1), 0, 1, NO_PROPS, None).unwrap();

graph.add_properties((0, 1), [("prop", "1")]).unwrap();
graph.add_properties((0, 1), [("prop", "2")]).unwrap();
graph.add_properties((0, 1), [("prop", "3")]).unwrap();
Expand Down Expand Up @@ -887,8 +879,6 @@ mod test_exploded_edges {
fn test_node_add_updates_properties_ordered_by_secondary_index() {
let graph: Graph = Graph::new();
graph.add_node(0, 0, NO_PROPS, None).unwrap();
graph.add_node(0, 0, NO_PROPS, None).unwrap();
graph.add_node(0, 0, NO_PROPS, None).unwrap();

graph
.node(0)
Expand Down Expand Up @@ -1008,8 +998,6 @@ mod test_exploded_edges {
fn test_edge_add_updates_properties_ordered_by_secondary_index() {
let graph: Graph = Graph::new();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();

graph
.edge(0, 1)
Expand Down Expand Up @@ -1050,8 +1038,6 @@ mod test_exploded_edges {
fn test_edge_add_updates_properties_overwritten_for_same_secondary_index() {
let graph: Graph = Graph::new();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();
graph.add_edge(0, 0, 1, NO_PROPS, None).unwrap();

graph
.edge(0, 1)
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/python/graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl PyGraph {
/// Raises:
/// GraphError: If the operation fails.
#[pyo3(signature = (timestamp, properties, secondary_index = None))]
pub fn add_property(
pub fn add_properties(
&self,
timestamp: PyTime,
properties: HashMap<String, Prop>,
Expand Down

0 comments on commit fa14f59

Please sign in to comment.