def test_quantity_abs_round(self):
x = self.Q_(-4.2, 'meter')
y = self.Q_(4.2, 'meter')
# In Python 3+ round of x is delegated to x.__round__, instead of round(x.__float__)
# and therefore it can be properly implemented by Pint
for fun in (abs, op.pos, op.neg) + (round, ) if PYTHON3 else ():
zx = self.Q_(fun(x.magnitude), 'meter')
zy = self.Q_(fun(y.magnitude), 'meter')
rx = fun(x)
ry = fun(y)
self.assertEqual(rx, zx, 'while testing {0}'.format(fun))
self.assertEqual(ry, zy, 'while testing {0}'.format(fun))
self.assertIsNot(rx, zx, 'while testing {0}'.format(fun))
self.assertIsNot(ry, zy, 'while testing {0}'.format(fun))
评论列表
文章目录