Skip to content

Commit

Permalink
Fix spurious errors when running validator with --skip-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Mar 14, 2023
1 parent 0060f44 commit 10c317c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 9 additions & 6 deletions optimade/validator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,16 @@ def wrapper(
# If the result was None, return it here and ignore statuses
if result is None:
return result, msg
else:
display_request = requests.utils.requote_uri(request.replace("\n", "")) # type: ignore[union-attr]

if not isinstance(result, Exception):
if not multistage:
success_type = "optional" if optional else None
validator.results.add_success(f"{request} - {msg}", success_type)
validator.results.add_success(
f"{display_request} - {msg}", success_type
)
else:
request = request.replace("\n", "") # type: ignore[union-attr]
message = msg.split("\n")
if validator.verbosity > 1:
# ValidationErrors from pydantic already include very detailed errors
Expand All @@ -371,12 +374,12 @@ def wrapper(

failure_type = None
if isinstance(result, InternalError):
summary = (
f"{request} - {test_fn.__name__} - failed with internal error"
)
summary = f"{display_request} - {test_fn.__name__} - failed with internal error"
failure_type = "internal"
else:
summary = f"{request} - {test_fn.__name__} - failed with error"
summary = (
f"{display_request} - {test_fn.__name__} - failed with error"
)
failure_type = "optional" if optional else None

validator.results.add_failure(
Expand Down
4 changes: 3 additions & 1 deletion optimade/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,9 @@ def _construct_single_property_filters(
expected_status_code=(200, 501),
)

if response.status_code != 200:
if response is None or response.status_code != 200:
if response is None:
breakpoint()
if query_optional:
return (
None,
Expand Down
13 changes: 13 additions & 0 deletions tests/server/test_server_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ def test_with_validator(both_fake_remote_clients):
assert validator.valid


def test_with_validator_skip_optional(both_fake_remote_clients):
from optimade.server.main_index import app

validator = ImplementationValidator(
client=both_fake_remote_clients,
index=both_fake_remote_clients.app == app,
run_optional_tests=True,
)

validator.validate_implementation()
assert validator.valid


def test_with_validator_json_response(both_fake_remote_clients, capsys):
"""Test that the validator writes compliant JSON when requested."""
from optimade.server.main_index import app
Expand Down

0 comments on commit 10c317c

Please sign in to comment.