def test_measurement_3args(self, protocol): m = Measurement(123, 15, "kg") assert m.value.magnitude == 123 assert m.error.magnitude == 15 assert str(m.units) == "kilogram" m = pickle.loads(pickle.dumps(m, protocol)) assert m.value.magnitude == 123 assert m.error.magnitude == 15 assert str(m.units) == "kilogram"
def test_measurement_2args(self, protocol): m = Measurement(Quantity(123, "foo"), Quantity(10, "bar")) assert m.value.magnitude == 123 assert m.error.magnitude == 5 assert str(m.units) == "foo" m = pickle.loads(pickle.dumps(m, protocol)) assert m.value.magnitude == 123 assert m.error.magnitude == 5 assert str(m.units) == "foo"
def test_measurement_2args(self, protocol): m = Measurement(Quantity(123, "foo"), Quantity(10, "bar")) self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 5) self.assertEqual(str(m.units), "foo") m = pickle.loads(pickle.dumps(m, protocol)) self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 5) self.assertEqual(str(m.units), "foo")
def test_measurement_3args(self, protocol): m = Measurement(123, 15, "kg") self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 15) self.assertEqual(str(m.units), "kilogram") m = pickle.loads(pickle.dumps(m, protocol)) self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 15) self.assertEqual(str(m.units), "kilogram")
def test_measurement_2args(self): m = Measurement(Quantity(123, "kg"), Quantity(15, "kg")) self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 15) self.assertEqual(str(m.units), "kilogram") m = pickle.loads(pickle.dumps(m)) self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 15) self.assertEqual(str(m.units), "kilogram")
def test_measurement_3args(self): m = Measurement(123, 5, "foo") self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 5) self.assertEqual(str(m.units), "foo") m = pickle.loads(pickle.dumps(m)) self.assertEqual(m.value.magnitude, 123) self.assertEqual(m.error.magnitude, 5) self.assertEqual(str(m.units), "foo")
def _test_format(self): v, u = self.Q_(4.0, 's'), self.Q_(.1, 's') m = Measurement(v, u) print(str(m)) print(repr(m)) print('{:!s}'.format(m)) print('{:!r}'.format(m)) print('{:!l}'.format(m)) print('{:!p}'.format(m)) print('{:.02f!l}'.format(m)) print('{:.02f!p}'.format(m))
def test_build(self): v, u = self.Q_(4.0, 's'), self.Q_(.1, 's') ms = (Measurement(v, u), v.plus_minus(.1), v.plus_minus(0.025, True), v.plus_minus(u)) for m in ms: self.assertEqual(m.value, v) self.assertEqual(m.error, u) self.assertEqual(m.rel, m.error / abs(m.value))
def test_measurement_3args(self, protocol): set_application_registry(self.ureg1) m1 = Measurement(10, 1, "foo") set_application_registry(self.ureg2) m2 = Measurement(10, 1, "foo") m3 = pickle.loads(pickle.dumps(m1, protocol)) assert m1.dimensionality == {"[dim1]": 1} assert m2.dimensionality == {"[dim2]": 1} assert m1.to("bar").value.magnitude == 20 assert m2.to("bar").value.magnitude == 30 assert m3.to("bar").value.magnitude == 30 assert m1.to("bar").error.magnitude == 2 assert m2.to("bar").error.magnitude == 3 assert m3.to("bar").error.magnitude == 3
def test_measurement_3args(self): set_application_registry(self.ureg1) m1 = Measurement(10, 1, "foo") set_application_registry(self.ureg2) m2 = Measurement(10, 1, "foo") m3 = pickle.loads(pickle.dumps(m1)) assert m1.dimensionality == {"[dim1]": 1} assert m2.dimensionality == {"[dim2]": 1} self.assertEqual(m1.to("bar").value.magnitude, 20) self.assertEqual(m2.to("bar").value.magnitude, 30) self.assertEqual(m3.to("bar").value.magnitude, 30) self.assertEqual(m1.to("bar").error.magnitude, 2) self.assertEqual(m2.to("bar").error.magnitude, 3) self.assertEqual(m3.to("bar").error.magnitude, 3)