Пример #1
0
 def test_convert_to(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_unit2 = ConvertUnit(test_type, ["name3"], 505)
     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/505
Пример #2
0
 def test_convert_to_different_types(self):
     # Setup test objects
     test_repo = ConvertRepo()
     test_type1 = ConvertType(test_repo, "test_type1")
     test_type1.base_unit = ConvertUnit(test_type1, ["base_unit"], 1)
     test_unit1 = ConvertUnit(test_type1, ["name1", "name2"], 1337)
     test_type2 = ConvertType(test_repo, "test_type2")
     test_type2.base_unit = ConvertUnit(test_type2, ["another_base"], 1)
     test_unit2 = ConvertUnit(test_type2, ["name3"], 505)
     measure1 = ConvertMeasure(17.5, test_unit1)
     # Convert to base
     try:
         test_result = measure1.convert_to(test_unit2)
         assert False
     except Exception as e:
         assert "not the same unit type" in str(e)