Skip to content

Commit

Permalink
Always print summary as last thing in validation (#700)
Browse files Browse the repository at this point in the history
Update test to use respond_json.
  • Loading branch information
CasperWA committed Feb 10, 2021
1 parent f9d3b8a commit fcb385a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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

0 comments on commit fcb385a

Please sign in to comment.