Skip to content

Commit

Permalink
Add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arthursoprana committed Oct 10, 2019
1 parent f4255c4 commit 28c6e14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/barril/units/_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
UnitDatabase,
UnitsError,
FixUnitIfIsLegacy,
ComposedUnitError,
)
from oop_ext.interface._interface import ImplementsInterface

Expand Down Expand Up @@ -677,9 +678,17 @@ def Convert(self, value, to_unit):
:returns:
An object with values to the passed unit.
"""
return self._unit_database.Convert(
self._category, self._CreateUnitsWithJoinedExponentsString(), to_unit, value
)
try:
return self._unit_database.Convert(
self._composing_categories, self._composing_units, to_unit, value
)
except ComposedUnitError:
return self._unit_database.Convert(
self._category,
self._CreateUnitsWithJoinedExponentsString(),
to_unit,
value,
)

@classmethod
def _GetComparison(cls, operator, use_literals=False):
Expand Down
7 changes: 7 additions & 0 deletions src/barril/units/_tests/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ class MyScalar(units.Scalar):
scalar = Scalar("length", 1.18, "m")
assert scalar.GetFormatted() == "1.18 [m]"

# Check that squared works
scalar2 = scalar * scalar
assert scalar2.GetFormatted("m2") == "1.3924 [m2]"
assert scalar2.GetFormattedValue("m2") == "1.3924"
assert scalar2.GetFormatted((("m", 2),)) == "1.3924 [('m', 2)]"
assert scalar2.GetFormattedValue((("m", 2),)) == "1.3924"


def testCopyProperties(unit_database_well_length):
"""
Expand Down

0 comments on commit 28c6e14

Please sign in to comment.