MCPcopy
hub / github.com/cartography-cncf/cartography / check_nodes

Function check_nodes

tests/integration/util.py:11–31  ·  view source on GitHub ↗

Helper function for checking nodes in cartography integration tests. Returns the result of a neo4j match query on the given node label and the given list of attributes as a set of tuples.

(
    neo4j_session: neo4j.Session,
    node_label: str,
    attrs: List[str],
)

Source from the content-addressed store, hash-verified

9
10
11def check_nodes(
12 neo4j_session: neo4j.Session,
13 node_label: str,
14 attrs: List[str],
15) -> Optional[Set[Tuple[Any, ...]]]:
16 """
17 Helper function for checking nodes in cartography integration tests.
18 Returns the result of a neo4j match query on the given node label and the given list of attributes as a set of
19 tuples.
20 """
21 if not attrs:
22 raise ValueError(
23 "`attrs` passed to check_nodes() must have at least one element.",
24 )
25
26 attrs = ", ".join(f"n.{attr}" for attr in attrs)
27 query_template = Template("MATCH (n:$NodeLabel) RETURN $Attrs")
28 result = neo4j_session.run(
29 query_template.safe_substitute(NodeLabel=node_label, Attrs=attrs),
30 )
31 return {tuple(row.values()) for row in result}
32
33
34def check_rels(

Calls 1

runMethod · 0.45