Skip to content

Commit

Permalink
Change gate library test to avoid pytest identification
Browse files Browse the repository at this point in the history
  • Loading branch information
wshanks committed Dec 20, 2023
1 parent db4e43b commit fa1354c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions test/calibration/test_setup_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qiskit_experiments.framework.json import ExperimentEncoder, ExperimentDecoder


class TestLibrary(FixedFrequencyTransmon):
class MutableTestLibrary(FixedFrequencyTransmon):
"""A subclass designed for test_hash_warn.
This class ensures that FixedFrequencyTransmon is preserved if anything goes wrong
Expand Down Expand Up @@ -197,26 +197,27 @@ def test_hash_warn(self):
4. A warning is raised since the class definition has changed.
"""

lib1 = TestLibrary()
lib1 = MutableTestLibrary()
lib_data = json.dumps(lib1, cls=ExperimentEncoder)
lib2 = json.loads(lib_data, cls=ExperimentDecoder)

self.assertTrue(self._test_library_equivalence(lib1, lib2))

# stash method build schedules to avoid other tests from failing
build_schedules = TestLibrary._build_schedules
build_schedules = MutableTestLibrary._build_schedules

def _my_build_schedules():
"""A dummy function to change the class behaviour."""
pass

# Change the schedule behaviour
TestLibrary._build_schedules = _my_build_schedules
MutableTestLibrary._build_schedules = _my_build_schedules

with self.assertWarns(UserWarning):
json.loads(lib_data, cls=ExperimentDecoder)

TestLibrary._build_schedules = build_schedules
try:
json.loads(lib_data, cls=ExperimentDecoder)
finally:
MutableTestLibrary._build_schedules = build_schedules

def _test_library_equivalence(self, lib1, lib2) -> bool:
"""Test if libraries are equivalent.
Expand Down

0 comments on commit fa1354c

Please sign in to comment.