def test_quantity_in_sys(self): unitty.setup('test', units_raw=TEST_DICT_5, sys_raw=TEST_SYSTEMS_1) u = unitty.get_units('test') q = 7 << u.ft / u.lbs val, spec = q.in_sys() self.assertAlmostEqual(val, 4.703782825976547) self.assertEqual(spec, 'm/kg')
def test_quantity_in_sys_switch(self): unitty.setup('test', units_raw=TEST_DICT_5, sys_raw=TEST_SYSTEMS_1) u = unitty.get_units('test') q = 7 << u.ft / u.lbs unitty.set_system('US') val, spec = q.in_sys() self.assertEqual(val, 7) self.assertEqual(spec, 'ft/lbs')
def test_set_refs_csv(self): unitty.setup('test', units_raw=TEST_DICT_10, sys_raw=TEST_SYSTEMS_1) s = unitty.get_systems('test') source = os.path.join(root, 'ref_set_1.csv') s.set_refs(source) self.assertEqual(s._refs['widget_length']['metric'], 'mm') self.assertEqual(s._refs['widget_length']['US'], 'in') self.assertEqual(s._refs['complex.value']['metric'], 'kg.s2/m') self.assertEqual(s._refs['complex.value']['US'], 'lbs.s2/ft')
def test_quantity_by_ref(self): unitty.setup('test', units_raw=TEST_DICT_10, sys_raw=TEST_SYSTEMS_1) s = unitty.get_systems('test') source = os.path.join(root, 'ref_set_1.csv') s.set_refs(source) u = unitty.get_units('test') q = 7 << u['kg.s2/m'] q.set_ref('complex.value') val, spec = q.by_ref() self.assertEqual(val, 7) self.assertEqual(spec, 'kg.s2/m')
def setUp(self): unitty.setup('test', units_raw=TEST_DICT_30, sys_raw=TEST_SYSTEMS_20)
def test_quantity_unitise_round_trip(self): unitty.setup('test', units_raw=TEST_DICT_5, sys_raw=TEST_SYSTEMS_1) self._round_trip('test')
def test_quantity_val(self): unitty.setup('test', units_raw=TEST_DICT_5, sys_raw=TEST_SYSTEMS_1) u = unitty.get_units('test') q = 7 << u.ft / u.lbs self.assertAlmostEqual(q.value, 7 * (12*0.0254) / 0.45359237) # 4.703782825976547
def test_val(self): unitty.setup('test', units_raw=TEST_DICT_5, sys_raw=TEST_SYSTEMS_1) u = unitty.get_units('test') q = 7 * u.ft / u.lbs self.assertAlmostEqual(q, 7 * (12*0.0254) / 0.45359237)
def test_set_refs(self): unitty.setup('test', units_raw=TEST_DICT_10, sys_raw=TEST_SYSTEMS_1) s = unitty.get_systems('test') s.set_refs(TEST_REF_SET_A) self.assertDictEqual(TEST_REF_SET_A, s._refs)
def test_quantity_unitise_round_trip_2(self): ''' Check for alternative specification ''' unitty.setup('test', units_raw=TEST_DICT_5, sys_raw=TEST_SYSTEMS_2) self._round_trip('test')