Skip to content

Commit

Permalink
Disable all floating-point comparisons during validation (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Mar 8, 2021
1 parent f77235d commit 9306cb8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
10 changes: 3 additions & 7 deletions optimade/validator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"ENDS",
),
DataType.TIMESTAMP: (
# "=" and "<=" are disabled due to issue with microseconds stored in database vs API response (see Materials-Consortia/optimade-python-tools/#606)
# N.B. "=" and "<=" are disabled due to issue with microseconds stored in database vs API response (see Materials-Consortia/optimade-python-tools/#606)
# ">=" is fine as all microsecond trimming will round times down
# "=",
# "<=",
Expand All @@ -82,11 +82,7 @@
"<=",
">=",
),
DataType.FLOAT: (
"=",
"<=",
">=",
),
DataType.FLOAT: (),
DataType.LIST: ("HAS", "HAS ALL", "HAS ANY"),
}

Expand All @@ -95,7 +91,7 @@
_EXCLUSIVE_OPERATORS = {
DataType.STRING: exclusive_ops,
DataType.TIMESTAMP: (),
DataType.FLOAT: exclusive_ops,
DataType.FLOAT: (),
DataType.INTEGER: exclusive_ops,
DataType.LIST: (),
}
Expand Down
10 changes: 10 additions & 0 deletions optimade/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,16 @@ def _construct_single_property_filters(
self._log.warning(msg)
return None, msg

# Try to infer if the test value is a float from its string representation
# and decide whether to do inclusive/exclusive query tests
try:
float(test_value[0])
msg = f"Not testing filters on field {prop} of type {prop_type} containing float values."
self._log.warning(msg)
return None, msg
except ValueError:
pass

if prop_type in (DataType.DICTIONARY,):
msg = f"Not testing queries on field {prop} of type {prop_type}."
self._log.warning(msg)
Expand Down
16 changes: 7 additions & 9 deletions tests/server/test_server_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_with_validator(both_fake_remote_clients):
validator = ImplementationValidator(
client=both_fake_remote_clients,
index=both_fake_remote_clients.app == app,
verbosity=5,
)

validator.validate_implementation()
Expand All @@ -33,14 +32,13 @@ def test_with_validator_json_response(both_fake_remote_clients, capsys):

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

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


Expand Down

0 comments on commit 9306cb8

Please sign in to comment.