diff --git a/pint/constants_en.txt b/pint/constants_en.txt index 8427ff0..2b67545 100644 --- a/pint/constants_en.txt +++ b/pint/constants_en.txt @@ -15,7 +15,7 @@ planck_constant = 6.62606957e-34 J s = h hbar = planck_constant / (2 * pi) = ħ # 0.000 80 e-11 -newtonian_constant_of_gravitation = 6.67384e-11 m^3 kg^-1 s^-2 = G +newtonian_constant_of_gravitation = 6.67384e-11 m^3 kg^-1 s^-2 # 0.000 000 035 e-19 # elementary_charge = 1.602176565e-19 C = e diff --git a/pint/default_en.txt b/pint/default_en.txt index 1603062..98789fc 100644 --- a/pint/default_en.txt +++ b/pint/default_en.txt @@ -72,7 +72,7 @@ US_survey_acre = 160 * rod ** 2 esu = 1 * erg**0.5 * centimeter**0.5 = statcoulombs = statC = franklin = Fr esu_per_second = 1 * esu / second = statampere ampere_turn = 1 * A -gilbert = 10 / (4 * pi ) * ampere_turn = G +gilbert = 10 / (4 * pi ) * ampere_turn coulomb = ampere * second = C volt = joule / coulomb = V farad = coulomb / volt = F diff --git a/pint/testsuite/__init__.py b/pint/testsuite/__init__.py index 5c488dd..c29f7a7 100644 --- a/pint/testsuite/__init__.py +++ b/pint/testsuite/__init__.py @@ -9,6 +9,7 @@ from pint.compat import ndarray, unittest from pint import logger, UnitRegistry from pint.quantity import _Quantity +from logging.handlers import BufferingHandler h = logging.StreamHandler() f = logging.Formatter("%(levelname)s %(asctime)s %(funcName)s %(lineno)d %(message)s") @@ -18,6 +19,22 @@ logger.addHandler(h) logger.setLevel(logging.DEBUG) +class TestHandler(BufferingHandler): + def __init__(self): + # BufferingHandler takes a "capacity" argument + # so as to know when to flush. As we're overriding + # shouldFlush anyway, we can set a capacity of zero. + # You can call flush() manually to clear out the + # buffer. + BufferingHandler.__init__(self, 0) + + def shouldFlush(self): + return False + + def emit(self, record): + self.buffer.append(record.__dict__) + + class TestCase(unittest.TestCase): @classmethod diff --git a/pint/testsuite/test_contexts.py b/pint/testsuite/test_contexts.py index c3c3055..41fa740 100644 --- a/pint/testsuite/test_contexts.py +++ b/pint/testsuite/test_contexts.py @@ -8,28 +8,11 @@ from collections import defaultdict from pint import UnitRegistry from pint.context import Context, _freeze from pint.unit import UnitsContainer -from pint.testsuite import TestCase +from pint.testsuite import TestCase, TestHandler from pint.compat import unittest from pint import logger -from logging.handlers import BufferingHandler - -class TestHandler(BufferingHandler): - def __init__(self): - # BufferingHandler takes a "capacity" argument - # so as to know when to flush. As we're overriding - # shouldFlush anyway, we can set a capacity of zero. - # You can call flush() manually to clear out the - # buffer. - BufferingHandler.__init__(self, 0) - - def shouldFlush(self): - return False - - def emit(self, record): - self.buffer.append(record.__dict__) - def add_ctxs(ureg): a, b = UnitsContainer({'[length]': 1}), UnitsContainer({'[time]': -1}) d = Context('lc') diff --git a/pint/testsuite/test_unit.py b/pint/testsuite/test_unit.py index 64de85c..c8e0ed7 100644 --- a/pint/testsuite/test_unit.py +++ b/pint/testsuite/test_unit.py @@ -4,7 +4,6 @@ from __future__ import division, unicode_literals, print_function, absolute_impo import math import copy -import warnings import operator as op from pint.unit import (ScaleConverter, OffsetConverter, UnitsContainer, @@ -13,7 +12,7 @@ from pint.unit import (ScaleConverter, OffsetConverter, UnitsContainer, LazyRegistry, ParserHelper) from pint import DimensionalityError, UndefinedUnitError from pint.compat import u, unittest -from pint.testsuite import TestCase +from pint.testsuite import TestCase, logger, TestHandler class TestConverter(unittest.TestCase): @@ -434,6 +433,21 @@ class TestRegistry(TestCase): self.assertEqual(t.to('kelvin').magnitude, self.ureg._units['degF'].converter.to_reference(8.)) self.assertEqual(dt.to('delta_kelvin').magnitude, self.ureg._units['delta_degF'].converter.to_reference(8.)) + def test_redefinition(self): + d = UnitRegistry().define + + th = TestHandler() + logger.addHandler(th) + d('meter = [fruits]') + d('kilo- = 1000') + d('[speed] = [vegetables]') + + # aliases + d('bla = 3.2 meter = inch') + d('myk- = 1000 = kilo-') + + self.assertEqual(len(th.buffer), 5) + class TestEquivalents(TestCase): @@ -496,20 +510,6 @@ class TestEquivalents(TestCase): self.assertEqual(ureg.parse_units(''), UnitsContainer()) self.assertRaises(ValueError, ureg.parse_units, '2 * meter') - def test_redefinition(self): - d = UnitRegistry().define - - with warnings.catch_warnings(record=True) as w: - d('meter = [time]') - d('kilo- = 1000') - d('[speed] = [length]') - - # aliases - d('bla = 3.2 meter = inch') - d('myk- = 1000 = kilo-') - - self.assertEqual(len(w), 5) - class TestRegistryWithDefaultRegistry(TestRegistry):