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

Always print summary as last thing in validation #700

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion optimade/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def validate_implementation(self):
)
self._test_as_type()
self.valid = not bool(self.results.failure_count)
self.print_summary()
return

# Test entire implementation
Expand All @@ -268,9 +269,9 @@ def validate_implementation(self):
f"Unable to deserialize response from introspective {info_endp!r} endpoint. "
"This is required for all further validation, so the validator will now exit."
)
self.print_summary()
# Set valid to False to ensure error code 1 is raised at CLI
self.valid = False
self.print_summary()
return

# Grab the provider prefix from base info and use it when looking for provider fields
Expand Down
21 changes: 14 additions & 7 deletions tests/server/test_server_validation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import json
import dataclasses
from traceback import print_exc

import pytest

Expand Down Expand Up @@ -64,7 +63,7 @@ def test_mongo_backend_package_used():
)


def test_as_type_with_validator(client):
def test_as_type_with_validator(client, capsys):
import unittest

test_urls = {
Expand All @@ -80,14 +79,22 @@ def test_as_type_with_validator(client):
):
for url, as_type in test_urls.items():
validator = ImplementationValidator(
base_url=url, as_type=as_type, verbosity=5
base_url=url, as_type=as_type, respond_json=True
)
try:
validator.validate_implementation()
except Exception:
print_exc()
validator.validate_implementation()
assert validator.valid

captured = capsys.readouterr()
json_response = json.loads(captured.out)

assert json_response["failure_count"] == 0
assert json_response["internal_failure_count"] == 0
assert json_response["optional_failure_count"] == 0
assert validator.results.failure_count == 0
assert validator.results.internal_failure_count == 0
assert validator.results.optional_failure_count == 0
assert dataclasses.asdict(validator.results) == json_response


def test_query_value_formatting(client):
from optimade.models.optimade_json import DataType
Expand Down