-
Notifications
You must be signed in to change notification settings - Fork 415
Replace assert in reverse_jordan_wigner.py #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
f9ba85a
04cbcb8
3853e35
3b4d799
af8bc8a
b8e44d3
64c2d5c
6e098d2
885a094
49a856f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| """Tests reverse_jordan_wigner.py.""" | ||
|
|
||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from openfermion.ops.operators import FermionOperator, QubitOperator | ||
| from openfermion.transforms.opconversions import jordan_wigner, normal_ordered | ||
|
|
@@ -160,6 +161,14 @@ def test_bad_type(self): | |
| with self.assertRaises(TypeError): | ||
| reverse_jordan_wigner(3) | ||
|
|
||
| def test_reverse_jw_multi_term_error(self): | ||
| with patch( | ||
| 'openfermion.transforms.opconversions.reverse_jordan_wigner.' 'QubitOperator.__mul__' | ||
| ) as mock_mul: | ||
| mock_mul.return_value = QubitOperator('X0') + QubitOperator('Y0') | ||
| with self.assertRaisesRegex(ValueError, 'QubitOperator must contain exactly one term'): | ||
| reverse_jordan_wigner(QubitOperator('X1')) | ||
|
Comment on lines
+164
to
+172
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need to mock stuff?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's to simulate an internal failure condition. The code uses unittest.mock.patch to replace the Maybe I'm missing another, easier way? (Entirely possible …)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naively, I would think that if you can't trigger the failure condition without mucking up the library code itself (i.e. it can't be triggered by bad user input), then I would think an assertion would be the more idiomatic way to guard this |
||
|
|
||
| def test_jw_convention(self): | ||
| """Test that the Jordan-Wigner convention places the Z-string on | ||
| lower indices.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.