Skip to content

Commit

Permalink
test: validate that schemas are up to date in unit testing
Browse files Browse the repository at this point in the history
Also:
 - fix the schemas output so it's stable under our pre-commit hooks
 - docs: help the dev do the right thing when schemas are out of date
  • Loading branch information
joanise committed Apr 16, 2024
1 parent 5e9b682 commit f5a8186
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion everyvoice/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ def update_schemas(
for filename, schema in SCHEMAS_TO_OUTPUT.items():
if (schema_dir_path / filename).exists():
raise FileExistsError(
f"Sorry a schema already exists for version {filename}. Please bump the minor version number and generate the schema again."
f"Sorry a schema already exists for version {filename}.\n"
"If it's already been published to the schema store, please bump the EveryVoice minor version number and generate the schemas again.\n"
"If the current minor version is still in development, just delete the schema files and try again."
)
with open(schema_dir_path / filename, "w") as f:
json.dump(schema.model_json_schema(), f, indent=2)
f.write("\n")


CLICK_APP = typer.main.get_group(app)
Expand Down
11 changes: 11 additions & 0 deletions everyvoice/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ def test_update_schema(self):
)
)

for filename in SCHEMAS_TO_OUTPUT:
with open(Path(tmpdir) / filename, encoding="utf8") as f:
new_schema = f.read()
with open(EV_DIR / ".schema" / filename, encoding="utf8") as f:
saved_schema = f.read()
self.assertEqual(
saved_schema,
new_schema,
'Schemas are out of date, please run "everyvoice update-schemas".',
)

def test_inspect_checkpoint_help(self):
result = self.runner.invoke(app, ["inspect-checkpoint", "--help"])
self.assertIn("inspect-checkpoint [OPTIONS] MODEL_PATH", result.stdout)
Expand Down

0 comments on commit f5a8186

Please sign in to comment.