-
Notifications
You must be signed in to change notification settings - Fork 982
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
Refactor json_test's TEST_OBJECTS value into test data files #2527
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of missing newlines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor concern that it's now slightly more difficult to add a new type (these things compound, you know!); but appreciate the backwards compatibility testing this provides
…the name - Include keys from json.py in "expect test data to be present" check
@@ -667,6 +518,88 @@ def test_to_from_strings(): | |||
cirq.read_json(io.StringIO(), json_text=x_json_text) | |||
|
|||
|
|||
def _eval_repr_data_file(path: pathlib.Path): | |||
return eval(path.read_text(), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems mildly dangerous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in principle... but to be pragmatic we're already parsing files and running them as python when we invoke pytest. I don't see any additional risk from this... if there was, it would be of the style "a tool was setup to detect people replacing code with delete everything commands, but the tool ignored things that didn't end with .py".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, logically this isn't much different than the gaping security hole of python / pytest / everything already :)
Automerge cancelled: A status check is failing. |
This spreads out the gigantic list a bit, but mainly it allows us a format for adding backwards compatibility tests (where the repr file contains the intended result, instead of the object that initially produced the JSON).
The test files were generated by iterating over the test object and using cirq.to_json and repr.
Fixes #2425
This is maybe the third time I find myself refactoring this code. I wonder what the next one will be?