Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Add test_et_visualizer.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TaekyungHeo committed Nov 27, 2023
1 parent cca1148 commit 122ff78
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/et_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main() -> None:

nx.write_graphml(G, args.output_filename)
else:
print("Unknown output file extension. Must be one of pdf, dot, graphml.")
raise ValueError("Unsupported file extension. Must be one of: pdf, dot, graphml.")

et.close()

Expand Down
3 changes: 1 addition & 2 deletions src/third_party/utils/protolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def openFileRd(in_file):
except IOError:
proto_in = open(in_file, 'rb')
except IOError:
print("Failed to open ", in_file, " for reading")
exit(-1)
raise FileNotFoundError("Failed to open ", in_file, " for reading")
return proto_in

def _DecodeVarint32(in_file):
Expand Down
33 changes: 33 additions & 0 deletions tests/test_et_visualizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest
from chakra.et_visualizer import main
from unittest.mock import patch

# Assuming 'example_input.et' is the example input file you provided
example_input_file = 'example_input.et'

def test_run_with_pdf_output():
test_args = ["et_visualizer.py", "--input_filename", example_input_file, "--output_filename", "output.pdf"]
with patch('sys.argv', test_args):
main() # No assertion needed; we're checking if it runs without error

def test_run_with_dot_output():
test_args = ["et_visualizer.py", "--input_filename", example_input_file, "--output_filename", "output.dot"]
with patch('sys.argv', test_args):
main() # No assertion needed; we're checking if it runs without error

def test_run_with_graphml_output():
test_args = ["et_visualizer.py", "--input_filename", example_input_file, "--output_filename", "output.graphml"]
with patch('sys.argv', test_args):
main() # No assertion needed; we're checking if it runs without error

def test_incorrect_file_path():
test_args = ["et_visualizer.py", "--input_filename", "nonexistent_input.et", "--output_filename", "output.pdf"]
with patch('sys.argv', test_args):
with pytest.raises(FileNotFoundError):
main()

def test_unsupported_file_extension():
test_args = ["et_visualizer.py", "--input_filename", example_input_file, "--output_filename", "output.xyz"]
with patch('sys.argv', test_args):
with pytest.raises(ValueError):
main()

0 comments on commit 122ff78

Please sign in to comment.