-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade unittest equality method (#1132)
### Summary Current implementation of equality check, i.e. `QiskitExperimentsTestCase.json_equiv`, is not readable and scalable because it implements equality check logic for different types in a single method. This PR adds new test module `test/extended_equality.py` which implements new equality check dispatcher `is_equivalent`. Developers no longer need to specify `check_func` in the `assertRoundTripSerializable` and `assertRoundTripPickle` methods unless they define custom class for a specific unittest. This simplifies unittests and improves readability of equality check logic (and test becomes more trustable). This PR adds new software dependency in develop; [multimethod](https://pypi.org/project/multimethod/) Among several similar packages, this is chosen in favor of - its license type (Apache License, Version 2.0) - syntax compatibility with `functools.singledispatch` - support for subscripted generics in `typings`, e.g. `Union` --------- Co-authored-by: Helena Zhang <[email protected]>
- Loading branch information
1 parent
4038556
commit 2278679
Showing
32 changed files
with
564 additions
and
257 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
releasenotes/notes/add-test-equality-checker-dbe5762d2b6a967f.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
developer: | ||
- | | ||
Added the :meth:`QiskitExperimentsTestCase.assertEqualExtended` method for generic equality checks | ||
of Qiskit Experiments class instances in unittests. This is a drop-in replacement of | ||
calling the assertTrue with :meth:`QiskitExperimentsTestCase.json_equiv`. | ||
Note that some Qiskit Experiments classes may not officially implement equality check logic, | ||
although objects may be compared during unittests. Extended equality check is used | ||
for such situations. | ||
- | | ||
The following unittest test case methods will be deprecated: | ||
* :meth:`QiskitExperimentsTestCase.json_equiv` | ||
* :meth:`QiskitExperimentsTestCase.ufloat_equiv` | ||
* :meth:`QiskitExperimentsTestCase.analysis_result_equiv` | ||
* :meth:`QiskitExperimentsTestCase.curve_fit_data_equiv` | ||
* :meth:`QiskitExperimentsTestCase.experiment_data_equiv` | ||
One can now use the :func:`~test.extended_equality.is_equivalent` function instead. | ||
This function internally dispatches the logic for equality check. | ||
- | | ||
The default behavior of :meth:`QiskitExperimentsTestCase.assertRoundTripSerializable` and | ||
:meth:`QiskitExperimentsTestCase.assertRoundTripPickle` when `check_func` is not | ||
provided was upgraded. These methods now compare the decoded instance with | ||
:func:`~test.extended_equality.is_equivalent`, rather than | ||
delegating to the native `assertEqual` unittest method. | ||
One writing a unittest for serialization no longer need to explicitly set checker function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.