Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
test(kg): assert which algorithm ran in the label propagation tests (#1939)
Raashish Aggarwal8b3fffd88c05
diff --git a/tests/kg/test_enhanced_algorithms_e2e.py b/tests/kg/test_enhanced_algorithms_e2e.pyindex d1e34cfd..7a78bf72 100644--- a/tests/kg/test_enhanced_algorithms_e2e.py+++ b/tests/kg/test_enhanced_algorithms_e2e.py@@ -389,48 +389,41 @@ class TestEnhancedAlgorithmsE2E:results = {}for method in methods:- try:- result = community_detector.detect_communities(graph_dict, method=method)- results[method] = result-- # Verify result structure- assert 'communities' in result- assert 'node_assignments' in result- assert 'algorithm' in result-- # Verify communities- assert isinstance(result['communities'], list)- assert isinstance(result['node_assignments'], dict)-- # Verify node assignments- for node, community_id in result['node_assignments'].items():- assert isinstance(node, str)- assert isinstance(community_id, int)-- # Verify communities contain all nodes- all_nodes_in_communities = set()- for community in result['communities']:- all_nodes_in_communities.update(community)-- assert all_nodes_in_communities == set(result['node_assignments'].keys())-- except Exception as e:- print(f"Warning: {method} community detection failed: {e}")-- # Test with parameters- try:- result_with_params = community_detector.detect_communities(- graph_dict,- method='label_propagation',- max_iterations=50,- random_seed=42- )+ result = community_detector.detect_communities(graph_dict, method=method)+ results[method] = result- assert 'communities' in result_with_params- results['with_params'] = result_with_params+ # Verify result structure+ assert 'communities' in result+ assert 'node_assignments' in result+ assert result['algorithm'] == method- except Exception as e:- print(f"Warning: Community detection with params failed: {e}")+ # Verify communities+ assert isinstance(result['communities'], list)+ assert isinstance(result['node_assignments'], dict)++ # Verify node assignments+ for node, community_id in result['node_assignments'].items():+ assert isinstance(node, str)+ assert isinstance(community_id, int)++ # Verify communities contain all nodes+ all_nodes_in_communities = set()+ for community in result['communities']:+ all_nodes_in_communities.update(community)++ assert all_nodes_in_communities == set(result['node_assignments'].keys())++ # Test with parameters+ result_with_params = community_detector.detect_communities(+ graph_dict,+ method='label_propagation',+ max_iterations=50,+ random_seed=42+ )++ assert result_with_params['algorithm'] == 'label_propagation'+ assert 'communities' in result_with_params+ results['with_params'] = result_with_params# Verify we got some resultsassert len(results) > 0@@ -505,6 +498,7 @@ class TestEnhancedAlgorithmsE2E:# Step 3: Detect communitiescommunities = community_detector.detect_communities(social_dict, method='label_propagation')+ assert communities['algorithm'] == 'label_propagation'assert 'communities' in communities# Step 4: Find shortest pathsdiff --git a/tests/kg/test_integration_comprehensive.py b/tests/kg/test_integration_comprehensive.pyindex 0c96b82a..61909b12 100644--- a/tests/kg/test_integration_comprehensive.py+++ b/tests/kg/test_integration_comprehensive.py@@ -256,6 +256,7 @@ class TestComprehensiveIntegration:# Community detectioncommunities = community_detector.detect_communities(graph_dict, method='label_propagation')+ assert communities['algorithm'] == 'label_propagation'comm_id = tracker.track_community_detection(graph=network_graph,communities=communities['communities'],@@ -453,6 +454,7 @@ class TestComprehensiveIntegration:# Community detectionif graph.number_of_edges() > 0:communities = community_detector.detect_communities(graph_dict, method='label_propagation')+ assert communities['algorithm'] == 'label_propagation'layer_results[f"{layer_name}_communities"] = communitiescomm_id = tracker.track_community_detection(graph=graph,diff --git a/tests/kg/test_provenance_integration.py b/tests/kg/test_provenance_integration.pyindex 011a98d0..ad4970d1 100644--- a/tests/kg/test_provenance_integration.py+++ b/tests/kg/test_provenance_integration.py@@ -338,15 +338,12 @@ class TestProvenanceIntegration:# Test different community detection methodsfor method in ['label_propagation', 'louvain']:- try:- result = community_detector.detect_communities(graph_dict, method=method)- assert 'communities' in result- assert 'node_assignments' in result- assert isinstance(result['communities'], list)- assert isinstance(result['node_assignments'], dict)- except Exception as e:- # Some methods may fail on certain graphs- print(f"Warning: {method} community detection failed: {e}")+ result = community_detector.detect_communities(graph_dict, method=method)+ assert result['algorithm'] == method+ assert 'communities' in result+ assert 'node_assignments' in result+ assert isinstance(result['communities'], list)+ assert isinstance(result['node_assignments'], dict)def test_connectivity_analyzer_with_provenance(self, networkx_graph):"""Test connectivity analyzer with provenance tracking."""diff --git a/tests/kg/test_provenance_workflows.py b/tests/kg/test_provenance_workflows.pyindex 1cfe9fcf..8480be06 100644--- a/tests/kg/test_provenance_workflows.py+++ b/tests/kg/test_provenance_workflows.py@@ -501,6 +501,7 @@ class TestProvenanceWorkflows:if method == 'label_propagation':raisecontinue+ assert result['algorithm'] == methodcomm_id = tracker.track_community_detection(graph=workflow_graph,@@ -621,6 +622,7 @@ class TestProvenanceWorkflows:# Phase 6: Community Detectionprint("Phase 6: Community Detection")communities = community_detector.detect_communities(graph_dict, method='label_propagation')+ assert communities['algorithm'] == 'label_propagation'comm_id = tracker.track_community_detection(graph=workflow_graph,communities=communities['communities'],diff --git a/tests/kg/test_provenance_workflows_simple.py b/tests/kg/test_provenance_workflows_simple.pyindex 74ec1159..9238f3c1 100644--- a/tests/kg/test_provenance_workflows_simple.py+++ b/tests/kg/test_provenance_workflows_simple.py@@ -259,6 +259,7 @@ class TestProvenanceWorkflowsSimple:# Detect communitiescommunities = community_detector.detect_communities(graph_dict, method='label_propagation')+ assert communities['algorithm'] == 'label_propagation'# Track community detectioncomm_id = tracker.track_community_detection(@@ -405,6 +406,7 @@ class TestProvenanceWorkflowsSimple:# Phase 6: Community Detectioncommunities = community_detector.detect_communities(graph_dict, method='label_propagation')+ assert communities['algorithm'] == 'label_propagation'comm_id = tracker.track_community_detection(graph=workflow_graph,communities=communities['communities'],diff --git a/tests/kg/test_real_world_scenarios.py b/tests/kg/test_real_world_scenarios.pyindex 6d4d9149..2b0ef8e4 100644--- a/tests/kg/test_real_world_scenarios.py+++ b/tests/kg/test_real_world_scenarios.py@@ -554,6 +554,7 @@ class TestRealWorldScenarios:# 2. Detect communities (social circles)communities = community_detector.detect_communities(graph_dict, method='label_propagation')+ assert communities['algorithm'] == 'label_propagation'# Track community detectioncomm_id = tracker.track_community_detection(