Skip to content

Extract the schema for tests into a JSON file. #120

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

Merged
merged 1 commit into from
Jul 7, 2016
Merged

Extract the schema for tests into a JSON file. #120

merged 1 commit into from
Jul 7, 2016

Conversation

seagreen
Copy link

@seagreen seagreen commented Jul 6, 2016

No description provided.

@seagreen
Copy link
Author

seagreen commented Jul 6, 2016

Will fix this issue: #94

Is the way I read the file to JSON idiomatic?

}
}

TESTSUITE_SCHEMA = json.load(open("test-schema.json"))
Copy link
Member

Choose a reason for hiding this comment

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

Needs a with statement to not leave the file descriptor hanging around.

Copy link
Member

Choose a reason for hiding this comment

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

Also would be good to use a path relative to __file__ rather than relative to cwd.

@Julian
Copy link
Member

Julian commented Jul 6, 2016

Awesome! Thanks so much. Left 2 comments, lemme know if they're clear.

@seagreen
Copy link
Author

seagreen commented Jul 6, 2016

How does that look? (force pushed)

@Julian
Copy link
Member

Julian commented Jul 7, 2016

Why did you choose to add a function just to call it once right after :)?

Sorry, I'm annoying :)

@seagreen
Copy link
Author

seagreen commented Jul 7, 2016

Sorry, I'm annoying :)

Not at all, I'm enjoying the chance to re-learn some python.

Using with gave me this error SyntaxError: invalid syntax.

It happens whether I put everything on one line

TESTSUITE_SCHEMA = with open(os.path.join(ROOT_DIR, "test-schema.json")) as schema: return json.load(schema)

Or two (the indentation of this is showing off -- I have the return indented 4 spaces after the with):

TESTSUITE_SCHEMA = with open(os.path.join(ROOT_DIR, "test-schema.json")) as schema:
                                              return json.load(schema)

Doesn't the value of an assignment have to be an expression, not a statement? That would explain the problem.

@Julian
Copy link
Member

Julian commented Jul 7, 2016

Ah! Yes, it's a statement, which means you need to move the assignment within its body, e.g.:

with open(...) as test_schema:
    TESTSUITE_SCHEMA = json.load(test_schema)

@seagreen
Copy link
Author

seagreen commented Jul 7, 2016

Ohhhhhhhhhh!

(Force pushed again)

@Julian
Copy link
Member

Julian commented Jul 7, 2016

Looks great! Thanks!

@Julian Julian merged commit 9355965 into json-schema-org:develop Jul 7, 2016
@seagreen seagreen deleted the extract-test-schema branch July 7, 2016 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants