Skip to content

Commit

Permalink
fixed qcstyle bug that modified style dict, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Durd3nT committed Feb 23, 2024
1 parent 8509d94 commit 0bfc697
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions qiskit/visualization/circuit/qcstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def update(self, other):
nested_attrs = {"displaycolor", "displaytext"}
for attr in nested_attrs.intersection(other.keys()):
if attr in self.keys():
self[attr].update(other.pop(attr))
self[attr].update(other[attr])
else:
self[attr] = other.pop(attr)
self[attr] = other[attr]

super().update(other)

Expand Down
24 changes: 18 additions & 6 deletions test/visual/mpl/circuit/test_circuit_matplotlib_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,15 +1010,16 @@ def test_user_style(self):
circuit.barrier(5, 6)
circuit.reset(5)

style = {
"name": "user_style",
"displaytext": {"H2": "H_2"},
"displaycolor": {"H2": ("#EEDD00", "#FF0000")},
}
fname = "user_style.png"
self.circuit_drawer(
circuit,
output="mpl",
style={
"name": "user_style",
"displaytext": {"H2": "H_2"},
"displaycolor": {"H2": ("#EEDD00", "#FF0000")},
},
style=style,
filename=fname,
)

Expand All @@ -1029,7 +1030,18 @@ def test_user_style(self):
FAILURE_DIFF_DIR,
FAILURE_PREFIX,
)
self.assertGreaterEqual(ratio, self.threshold)

with self.subTest(msg="check image"):
self.assertGreaterEqual(ratio, self.threshold)

with self.subTest(msg="check style dict unchanged"):
self.assertEqual(
style, {
"name": "user_style",
"displaytext": {"H2": "H_2"},
"displaycolor": {"H2": ("#EEDD00", "#FF0000")},
}
)

def test_subfont_change(self):
"""Tests changing the subfont size"""
Expand Down

0 comments on commit 0bfc697

Please sign in to comment.