Skip to content

Commit

Permalink
Fixed unit validation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerkin committed May 21, 2021
1 parent d54ad9a commit 056b20c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sciunit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(

params_validator = ParametersValidator

units = pq.Dimensionless
units = pq.dimensionless

state_hide = ["last_model"]

Expand Down
7 changes: 5 additions & 2 deletions sciunit/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ def _validate_units(self, has_units: bool, key: str, value: Any) -> None:
else:
required_units = self.test.units
if not isinstance(value, pq.quantity.Quantity):
self._error(key, "Must be a python quantity")
#self._error(key, "Must be a python quantity")
value *= pq.dimensionless
provided_units = value.simplified.units
if not isinstance(required_units, pq.Dimensionless):
provided_units = value.simplified.units
required_units = required_units.simplified.units
else:
required_units = required_units.units
if not required_units == provided_units:
self._error(key, "Must have units of '%s'" % self.test.units.name)

Expand Down

0 comments on commit 056b20c

Please sign in to comment.