Skip to content
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

Merged
merged 9 commits into from
Nov 14, 2019
Merged

Conversation

Strilanc
Copy link
Contributor

@Strilanc Strilanc commented Nov 12, 2019

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?

@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Nov 12, 2019
Copy link
Collaborator

@vtomole vtomole left a 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.

Copy link
Collaborator

@mpharrigan mpharrigan left a 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

@@ -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(), {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems mildly dangerous

Copy link
Contributor Author

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".

Copy link
Collaborator

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 :)

@Strilanc Strilanc added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 13, 2019
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 13, 2019
@CirqBot
Copy link
Collaborator

CirqBot commented Nov 13, 2019

Automerge cancelled: A status check is failing.

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Nov 13, 2019
@Strilanc Strilanc added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 14, 2019
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 14, 2019
@CirqBot CirqBot merged commit 4ff38cf into master Nov 14, 2019
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 14, 2019
@CirqBot CirqBot deleted the identify1 branch November 14, 2019 00:20
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add backward-compatibility tests for json serialization
5 participants