Files
deb-python-pint/pint/testsuite/test_pitheorem.py
Hernan Grecco 88f7bb3f28 Implemented checks in testsuite to assert that warnings are only emmited when expected.
Each test class captures the logging output for warnings and check at tear down that
there was not a warning. If any warning is expected you must explicitly capture within
the test using `with self.capture_log() as buffer:`
2014-04-01 01:16:22 -03:00

45 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import division, unicode_literals, print_function, absolute_import
import itertools
from pint import pi_theorem
from pint.testsuite import QuantityTestCase
class TestPiTheorem(QuantityTestCase):
FORCE_NDARRAY = False
def test_simple(self):
# simple movement
with self.capture_log() as buffer:
self.assertEqual(pi_theorem({'V': 'm/s', 'T': 's', 'L': 'm'}),
[{'V': 1, 'T': 1, 'L': -1}])
# pendulum
self.assertEqual(pi_theorem({'T': 's', 'M': 'grams', 'L': 'm', 'g': 'm/s**2'}),
[{'g': 1, 'T': 2, 'L': -1}])
self.assertEqual(len(buffer), 7)
def test_inputs(self):
V = 'km/hour'
T = 'ms'
L = 'cm'
f1 = lambda x: x
f2 = lambda x: self.Q_(1, x)
f3 = lambda x: self.Q_(1, x).units
f4 = lambda x: self.Q_(1, x).dimensionality
fs = f1, f2, f3, f4
for fv, ft, fl in itertools.product(fs, fs, fs):
qv = fv(V)
qt = ft(T)
ql = ft(L)
self.assertEqual(self.ureg.pi_theorem({'V': qv, 'T': qt, 'L': ql}),
[{'V': 1.0, 'T': 1.0, 'L': -1.0}])