Skip to content

added UTs for visualizer#48

Open
anusghos wants to merge 4 commits intoKeysight:mainfrom
anusghos:visualizer-UTs
Open

added UTs for visualizer#48
anusghos wants to merge 4 commits intoKeysight:mainfrom
anusghos:visualizer-UTs

Conversation

@anusghos
Copy link
Copy Markdown
Contributor

@anusghos anusghos commented Apr 2, 2026

This PR contains Unit Tests for the visualizer and some mock data for testing.
The UTs asserts:

  • if the number of nodes in the graph generated for devices, fabrics and composed devices are correct.
  • if edges between nodes exist.
  • if html, css and js files are generated.
  • if all input types (infra object, yaml and json) are working

@anusghos anusghos requested a review from harsh-sikhwal as a code owner April 2, 2026 05:57
assert len(cx5_edges) > 0, "cx5_100gbe should have edges"

@pytest.mark.asyncio
async def test_json_file():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a fabric, dump it as json and test that json. Do the same for yaml. This way we can get rid of the mock_data

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in commit 5b584be

current_dir = os.path.dirname(os.path.abspath(__file__))
mock_data_path = os.path.join(current_dir, "mock_data")
json_path = os.path.join(mock_data_path, "SYS-221H-TNR.json")
output_dir="./viz3"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pytest native tmp_path or some fixture that returns a tmp directory - also add them to gitignore if not already present

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added pytest fixture in commit 5b584be

switch = Switch(port_count=4)
clos_fat_tree = ClosFatTreeFabric(switch, server, 3, [])
output_dir="./viz1"
run_visualizer(infrastructure=clos_fat_tree,hosts="server", switches="switch",output=output_dir)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide better spacing - I see no space here:
"switch",output=output_dir

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in commit 5b584be



@pytest.mark.asyncio
async def test_closfabric_3tier_4radix():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improper naming convention - provide full names like three tier radix four
or just provide test_visualizer_closfabric

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in commit 5b584be

@@ -0,0 +1,85 @@
import pytest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to have a folder - you can have the file under src/tests/test_visualizer.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in commit 362ee3f

@@ -0,0 +1,305 @@
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this file - we do not want to keep resources

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, removed the old files

@@ -0,0 +1,193 @@
devices:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this file - we do not want to keep resources

Copy link
Copy Markdown
Contributor Author

@anusghos anusghos Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in commit 362ee3f

from infragraph.visualizer.visualize import run_visualizer


def _load_graph_data(output_dir):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required as we are already using infra objects

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping _load_graph_data() as it's a shared helper used by multiple tests to parse and validate the generated graph_data.js file. It extracts the JSON from the JS output so tests can assert on node/edge counts.

data = _load_graph_data(output_dir)
assert len(data) > 1, "Should have infrastructure and at least one device view"


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test for dgx device - maybe a higher variant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added tests for a compossibility graph in commit 5b584be


@pytest.mark.asyncio
async def test_composed_devices():
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use infragraph object rather than yaml

assert os.path.exists(os.path.join(output_dir, "js", "graph_data.js")), "graph_data.js not generated"
assert os.path.exists(os.path.join(output_dir, "css", "style.css")), "CSS file not copied"

data = _load_graph_data(output_dir)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why Api().set_graph() is not being used, for loading and validation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • set_graph() is already called internally in visualize.py (in run_visualizer()).
  • _load_graph_data is a test helper that parses the generated graph_data.js output file against which all assertions are running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants