Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed May 27, 2024
1 parent 11a9c6d commit c3a345e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
UnitLike,
)
from ...compat import Self, TypeAlias, deprecated
from ...errors import DimensionalityError, RedefinitionError, UndefinedUnitError, OffsetUnitCalculusError
from ...errors import (
DimensionalityError,
OffsetUnitCalculusError,
RedefinitionError,
UndefinedUnitError,
)
from ...pint_eval import build_eval_tree
from ...util import (
ParserHelper,
Expand Down Expand Up @@ -665,8 +670,10 @@ def get_name(self, name_or_alias: str, case_sensitive: bool | None = None) -> st

if prefix:
if not self._units[unit_name].is_multiplicative:
raise OffsetUnitCalculusError("Prefixing a unit requires multiplying the unit.")

raise OffsetUnitCalculusError(
"Prefixing a unit requires multiplying the unit."
)

name = prefix + unit_name
symbol = self.get_symbol(name, case_sensitive)
prefix_def = self._prefixes[prefix]
Expand Down
5 changes: 5 additions & 0 deletions pint/testsuite/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,3 +1043,8 @@ def test_alias(self):
# Define against unknown name
with pytest.raises(KeyError):
ureg.define("@alias notexist = something")

def test_prefix_offset_units(self):
ureg = UnitRegistry()
with pytest.raises(errors.OffsetUnitCalculusError):
ureg.parse_units("kilodegree_Celsius")

0 comments on commit c3a345e

Please sign in to comment.