Skip to content

Commit

Permalink
Separate the png and svg tests for circuit plots (#140)
Browse files Browse the repository at this point in the history
Separate the tests so that it skips if svg/png converters are not installed.
  • Loading branch information
BoxiLi committed May 1, 2022
1 parent 2f2879e commit d9b5ccb
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,27 +709,20 @@ def test_latex_code_non_reversed(self):
shutil.which("pdflatex") is None,
reason="requires pdflatex"
)
def test_export_image(self):

def cleanup(*img_files):
for img_file in img_files:
if img_file in os.listdir('.'):
os.remove(img_file)

file_png_200 = "exported_pic_200.png"
file_png_400 = "exported_pic_400.png"
file_svg = "exported_pic.svg"
cleanup(file_png_200, file_png_400, file_svg)

def test_export_image(self, in_temporary_directory):
from qutip_qip import circuit_latex
qc = QubitCircuit(2, reverse_states=False)
qc.add_gate("CSIGN", controls=[0], targets=[1])
qc.draw("png", 200, file_png_200.split('.')[0], "")
qc.draw("png", 400.5, file_png_400.split('.')[0], "")
qc.draw("svg", 450, file_svg.split('.')[0], "")

assert file_png_200 in os.listdir('.')
assert file_png_400 in os.listdir('.')
assert os.stat(file_png_200).st_size < os.stat(file_png_400).st_size
assert file_svg in os.listdir('.')

cleanup(file_png_200, file_png_400, file_svg)
if "png" in circuit_latex.CONVERTERS:
file_png200 = "exported_pic_200.png"
file_png400 = "exported_pic_400.png"
qc.draw("png", 200, file_png200.split('.')[0], "")
qc.draw("png", 400.5, file_png400.split('.')[0], "")
assert file_png200 in os.listdir('.')
assert file_png400 in os.listdir('.')
assert os.stat(file_png200).st_size < os.stat(file_png400).st_size
if "svg" in circuit_latex.CONVERTERS:
file_svg = "exported_pic.svg"
qc.draw("svg", file_svg.split('.')[0], "")
assert file_svg in os.listdir('.')

0 comments on commit d9b5ccb

Please sign in to comment.