Skip to content

Commit

Permalink
Added file save checks for renderers (#260)
Browse files Browse the repository at this point in the history
Added a test to verify that the Matplotlib and Text renderers save circuit files in PNG and TXT formats. The test checks file creation using the tmpdir fixture for multiple QC fixtures.
  • Loading branch information
gadhvirushiraj authored Jan 12, 2025
1 parent 1a94cf5 commit c769bfd
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,27 @@ def test_matrenderer(request, qc_fixture):
"""
qc = request.getfixturevalue(qc_fixture)

with patch("matplotlib.pyplot.show"):
with patch("matplotlib.pyplot.show"): # to avoid showing the plot
qc.draw("matplotlib")


@pytest.mark.parametrize("qc_fixture", ["qc1", "qc2", "qc3"])
def test_circuit_saving(request, qc_fixture, tmpdir):
"""
Test if the different renderers can save the circuit in different formats.
"""

qc = request.getfixturevalue(qc_fixture)

# test MatRenderer
with patch("matplotlib.pyplot.show"): # to avoid showing the plot
qc.draw("matplotlib", save=True, file_path=str(tmpdir.join("test")))
assert tmpdir.join(
"test.png"
).check(), "MatRenderer saved PNG file not found."

# test TextRenderer
qc.draw("text", save=True, file_path=str(tmpdir.join("test")))
assert tmpdir.join(
"test.txt"
).check(), "TextRenderer saved TXT file not found."

0 comments on commit c769bfd

Please sign in to comment.