def test_commensurable_with_same_dimension(self): dimension = 'T' physical_quantity1 = metadata.PhysicalQuantity() physical_quantity1.dimension = dimension physical_quantity2 = metadata.PhysicalQuantity() physical_quantity2.dimension = dimension self.assertTrue(physical_quantity1.commensurable(physical_quantity2))
def test_set_properties_from_dict_with_physical_quantities(self): dict_ = { "purpose": "Kill time", "operator": "John Doe", "labbook": "loi:42.1001/foo/bar", "length": "1.0 mm" } for key in dict_: setattr(self.metadata, key, '') self.metadata.length = metadata.PhysicalQuantity() self.metadata.from_dict(dict_) for key in dict_: if isinstance(getattr(self.metadata, key), metadata.PhysicalQuantity): self.assertEqual(str(getattr(self.metadata, key)), dict_[key]) else: self.assertEqual(getattr(self.metadata, key), dict_[key])
def test_to_dict_with_physical_quantities(self): dict_ = { "purpose": "Kill time", "operator": "John Doe", "labbook": "loi:42.1001/foo/bar", "length": "1.0 mm" } for key in dict_: setattr(self.metadata, key, '') self.metadata.length = metadata.PhysicalQuantity() self.metadata.from_dict(dict_) test_dict = { "purpose": "Kill time", "operator": "John Doe", "labbook": "loi:42.1001/foo/bar", "length": { "value": 1.0, "unit": "mm", "dimension": "", "name": "" } } to_dict = self.metadata.to_dict() self.assertDictEqual(test_dict, to_dict)
def test_incommensurable_if_has_no_dimension(self): physical_quantity = metadata.PhysicalQuantity() physical_quantity.dimension = 'T' self.assertFalse(physical_quantity.commensurable([]))
def test_incommensurable_if_has_no_unit(self): physical_quantity = metadata.PhysicalQuantity('5.0 m') self.assertFalse(physical_quantity.commensurable([]))
def test_incommensurable_with_different_dimensions(self): physical_quantity1 = metadata.PhysicalQuantity() physical_quantity1.dimension = 'T' physical_quantity2 = metadata.PhysicalQuantity() physical_quantity2.dimension = 'L' self.assertFalse(physical_quantity1.commensurable(physical_quantity2))
def test_incommensurable_with_different_units(self): physical_quantity1 = metadata.PhysicalQuantity('5.0 m') physical_quantity2 = metadata.PhysicalQuantity('3 s') self.assertFalse(physical_quantity1.commensurable(physical_quantity2))
def test_commensurable_with_same_unit(self): string = '5.0 m' physical_quantity1 = metadata.PhysicalQuantity(string) physical_quantity2 = metadata.PhysicalQuantity(string) self.assertTrue(physical_quantity1.commensurable(physical_quantity2))
def test_string_representation_when_value_is_zero(self): string = '0.0 m' physical_quantity = metadata.PhysicalQuantity(string) self.assertEqual(str(physical_quantity), string)
def test_string_representation(self): string = '5.0 m' physical_quantity = metadata.PhysicalQuantity(string) self.assertEqual(str(physical_quantity), string)
def test_instantiate_with_value_unit(self): physical_quantity = metadata.PhysicalQuantity(value=5., unit='m') self.assertEqual(physical_quantity.value, 5.) self.assertEqual(physical_quantity.unit, 'm')
def test_instantiate_with_string_without_unit(self): physical_quantity = metadata.PhysicalQuantity('5') self.assertEqual(physical_quantity.value, 5.) self.assertFalse(physical_quantity.unit)
def test_instantiate_with_string(self): physical_quantity = metadata.PhysicalQuantity('5 m') self.assertEqual(physical_quantity.value, 5.) self.assertEqual(physical_quantity.unit, 'm')
def setUp(self): self.physical_quantity = metadata.PhysicalQuantity()