Commit 1f0e141b authored by peastman's avatar peastman
Browse files

Merge pull request #985 from swails/bool_unit

Fix Python 3 support in unit package.
parents 96f0c0f2 24f6585e
...@@ -603,7 +603,7 @@ class Quantity(object): ...@@ -603,7 +603,7 @@ class Quantity(object):
return bool(self._value) return bool(self._value)
def __bool__(self): def __bool__(self):
return self.__nonzero__() return bool(self._value)
def __complex__(self): def __complex__(self):
return Quantity(complex(self._value), self.unit) return Quantity(complex(self._value), self.unit)
...@@ -818,7 +818,6 @@ def _is_string(x): ...@@ -818,7 +818,6 @@ def _is_string(x):
except StopIteration: except StopIteration:
return False return False
# run module directly for testing # run module directly for testing
if __name__=='__main__': if __name__=='__main__':
# Test the examples in the docstrings # Test the examples in the docstrings
......
...@@ -448,7 +448,7 @@ class TestUnits(QuantityTestCase): ...@@ -448,7 +448,7 @@ class TestUnits(QuantityTestCase):
self.assertAlmostEqualQuantities(n, 2.05834818672e-17 * u.mole) self.assertAlmostEqualQuantities(n, 2.05834818672e-17 * u.mole)
self.assertAlmostEqualQuantities(V, 5.2359833333333e-19 * u.meters**3) self.assertAlmostEqualQuantities(V, 5.2359833333333e-19 * u.meters**3)
self.assertEqual(str(T), '310.0 K') self.assertEqual(str(T), '310.0 K')
self.assertEqual(str(u.MOLAR_GAS_CONSTANT_R), '8.31447247122 J/(K mol)') self.assertEqual(str(1*u.joules/u.kelvin/u.mole), '1 J/(K mol)')
self.assertTrue(u.is_quantity(V)) self.assertTrue(u.is_quantity(V))
# Checks trouble with complicated unit conversion factors # Checks trouble with complicated unit conversion factors
p1 = 1.0 * u.atmospheres p1 = 1.0 * u.atmospheres
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment