def test_json(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.update_offset(10) test_unit.add_abbr("abbr1") test_unit.valid_prefix_group = prefix_group # Convert to json and back test_json = test_unit.to_json() json_unit = ConvertUnit.from_json(test_type, test_json) assert len(test_unit.abbr_list) == 1 assert "abbr1" in json_unit.abbr_list assert json_unit.type == test_type assert len(test_unit.name_list) == 2 assert "name1" in json_unit.name_list assert "name2" in json_unit.name_list assert json_unit.value == test_value assert json_unit.offset == 10 assert json_unit.last_updated_date == test_unit.last_updated_date assert json_unit.valid_prefix_group == prefix_group
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.update_offset(54) test_unit2 = ConvertUnit(test_type, ["name3"], 505) test_unit2.update_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
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_date is None # Change value test_unit.update_offset(10) # Check value assert test_unit.offset == 10 assert test_unit.last_updated_date is not None