Ejemplo n.º 1
0
 def test_xml(self):
     # Set up test objects
     test_repo = ConvertRepo()
     test_type = ConvertType(test_repo, "test_type")
     test_repo.add_type(test_type)
     prefix_group = ConvertPrefixGroup(test_repo, "test_group")
     test_repo.add_prefix_group(prefix_group)
     test_type.base_unit = ConvertUnit(test_type, ["base_unit"], 1)
     test_unit_names = ["name1", "name2"]
     test_value = 1337
     # Create test unit
     test_unit = ConvertUnit(test_type, test_unit_names, test_value)
     test_unit.set_offset(10)
     test_unit.add_abbr("abbr1")
     test_unit.valid_prefix_group = prefix_group
     # Convert to XML and back
     test_xml = test_unit.to_xml()
     xml_unit = ConvertUnit.from_xml(test_type, test_xml)
     assert len(test_unit.abbr_list) == 1
     assert "abbr1" in xml_unit.abbr_list
     assert xml_unit.type == test_type
     assert len(test_unit.name_list) == 2
     assert "name1" in xml_unit.name_list
     assert "name2" in xml_unit.name_list
     assert xml_unit.value == test_value
     assert xml_unit.offset == 10
     assert xml_unit.last_updated == test_unit.last_updated
     assert xml_unit.valid_prefix_group == prefix_group
Ejemplo n.º 2
0
 def test_convert_to_offset(self):
     # Setup test objects
     test_repo = ConvertRepo()
     test_type = ConvertType(test_repo, "test_type")
     test_type.base_unit = ConvertUnit(test_type, ["base_unit"], 1)
     test_unit1 = ConvertUnit(test_type, ["name1", "name2"], 1337)
     test_unit1.set_offset(54)
     test_unit2 = ConvertUnit(test_type, ["name3"], 505)
     test_unit2.set_offset(10)
     measure1 = ConvertMeasure(17.5, test_unit1)
     # Convert to base
     test_result = measure1.convert_to(test_unit2)
     # Check
     assert test_result.unit.name_list[0] == "name3"
     assert test_result.amount == ((17.5*1337)+54-10)/505
Ejemplo n.º 3
0
 def test_set_offset(self):
     # Set up test object
     test_repo = ConvertRepo()
     test_type = ConvertType(test_repo, "test_type")
     test_type.base_unit = ConvertUnit(test_type, ["base_unit"], 1)
     test_unit_names = ["name1", "name2"]
     test_value = 1337
     test_unit = ConvertUnit(test_type, test_unit_names, test_value)
     # Check value and time updated
     assert test_unit.offset == 0
     assert test_unit.last_updated is None
     # Change value
     test_unit.set_offset(10)
     # Check value
     assert test_unit.offset == 10
     assert test_unit.last_updated is not None