|
| 1 | +import json |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from graphdatascience import Graph |
| 6 | +from graphdatascience.arrow_client.authenticated_flight_client import AuthenticatedArrowClient |
| 7 | +from graphdatascience.arrow_client.v2.data_mapper_utils import deserialize_single |
| 8 | +from graphdatascience.procedure_surface.arrow.arrow_wcc_endpoints import WccArrowEndpoints |
| 9 | + |
| 10 | + |
| 11 | +class MockGraph(Graph): |
| 12 | + def __init__(self, name: str): |
| 13 | + self._name = name |
| 14 | + |
| 15 | + def name(self) -> str: |
| 16 | + return self._name |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture |
| 20 | +def sample_graph(arrow_client: AuthenticatedArrowClient): |
| 21 | + gdl = """ |
| 22 | + (a: Node) |
| 23 | + (b: Node) |
| 24 | + (c: Node) |
| 25 | + (a)-[:REL]->(c) |
| 26 | + """ |
| 27 | + |
| 28 | + res = arrow_client.do_action( "v2/graph.fromGDL", json.dumps({"graphName": "g", "gdlGraph": gdl}).encode("utf-8")) |
| 29 | + print(deserialize_single(res)) |
| 30 | + yield MockGraph("g") |
| 31 | + arrow_client.do_action( "v2/graph.drop", json.dumps({"graphName": "g"}).encode("utf-8")) |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +def wcc_endpoints(arrow_client: AuthenticatedArrowClient): |
| 35 | + yield WccArrowEndpoints(arrow_client) |
| 36 | + |
| 37 | + |
| 38 | +def test_wcc_stats(wcc_endpoints: WccArrowEndpoints, sample_graph: Graph): |
| 39 | + """Test WCC stats operation.""" |
| 40 | + result = wcc_endpoints.stats( |
| 41 | + G=sample_graph |
| 42 | + ) |
| 43 | + |
| 44 | + assert result.component_count == 2 |
| 45 | + assert result.compute_millis > 0 |
| 46 | + assert result.pre_processing_millis > 0 |
| 47 | + assert result.post_processing_millis > 0 |
| 48 | + assert "p10" in result.component_distribution |
| 49 | + |
| 50 | +def test_wcc_stream(wcc_endpoints: WccArrowEndpoints, sample_graph: Graph): |
| 51 | + """Test WCC stream operation.""" |
| 52 | + result_df = wcc_endpoints.stream( |
| 53 | + G=sample_graph, |
| 54 | + ) |
| 55 | + |
| 56 | + assert "nodeId" in result_df.columns |
| 57 | + assert "componentId" in result_df.columns |
| 58 | + assert len(result_df.columns) == 2 |
| 59 | + |
| 60 | +def test_wcc_mutate(wcc_endpoints: WccArrowEndpoints, sample_graph: Graph): |
| 61 | + """Test WCC mutate operation.""" |
| 62 | + result = wcc_endpoints.mutate( |
| 63 | + G=sample_graph, |
| 64 | + mutate_property="componentId", |
| 65 | + ) |
| 66 | + |
| 67 | + assert result.component_count == 2 |
| 68 | + assert "p10" in result.component_distribution |
| 69 | + assert result.pre_processing_millis >= 0 |
| 70 | + assert result.compute_millis >= 0 |
| 71 | + assert result.post_processing_millis >= 0 |
| 72 | + assert result.mutate_millis >= 0 |
| 73 | + assert result.node_properties_written == 3 |
0 commit comments