Exemplo n.º 1
0
 def test_get_prefix_from_user_input_abbr_internal(self):
     # Set up prefix group
     test_repo = ConvertRepo()
     prefix_group = ConvertPrefixGroup(test_repo, "test_group")
     prefix_name1 = "test_name1"
     prefix_abbr1 = "test_abbr1"
     prefix_mult1 = 1001
     test_prefix1 = ConvertPrefix(prefix_group, prefix_name1, prefix_abbr1, prefix_mult1)
     prefix_name2 = "test_name2"
     prefix_abbr2 = "test_abbr2"
     prefix_mult2 = 1002
     test_prefix2 = ConvertPrefix(prefix_group, prefix_name2, prefix_abbr2, prefix_mult2)
     prefix_group.add_prefix(test_prefix1)
     prefix_group.add_prefix(test_prefix2)
     # Set up test object
     test_type = ConvertType(test_repo, "test_type")
     test_type.base_unit = ConvertUnit(test_type, ["base_unit"], 1)
     test_unit_names = ["name1", "name2", "NaMe3"]
     test_value = 1337
     test_unit = ConvertUnit(test_type, test_unit_names, test_value)
     test_unit.add_abbr("ABbr1")
     test_unit.add_abbr("cubic {X}abbr2")
     test_unit.valid_prefix_group = prefix_group
     # Get prefix from input
     assert test_unit.get_prefix_from_user_input("cubic test_abbr1abbr2") == test_prefix1
     assert test_unit.get_prefix_from_user_input("cubic test_abbr1not_a_unit") is False
     assert test_unit.get_prefix_from_user_input("cubic not_a_prefixabbr2") is False
     assert test_unit.get_prefix_from_user_input("cubic abbr2") is None
     # Remove prefix group and see what happens
     test_unit.valid_prefix_group = None
     assert test_unit.get_prefix_from_user_input("cubic test_abbr1abbr2") is False
Exemplo n.º 2
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
Exemplo n.º 3
0
 def test_to_string(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_type.decimals = 3
     test_unit = ConvertUnit(test_type, ["name1", "name2"], 1337)
     prefix_group = ConvertPrefixGroup(test_repo, "test_group")
     test_prefix = ConvertPrefix(prefix_group, "ten", "10", 10)
     prefix_group.add_prefix(test_prefix)
     test_unit.valid_prefix_group = prefix_group
     measure1 = ConvertMeasure(17.5, test_unit)
     # Get string
     measure_str = measure1.to_string()
     # Check
     assert str(measure1) == measure_str
     assert measure_str == "1.750 tenname1"
Exemplo n.º 4
0
 def test_build_list_from_user_input_prefix(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_repo.add_type(test_type)
     test_unit = ConvertUnit(test_type, ["name1", "name2"], 1337)
     test_type.add_unit(test_unit)
     prefix_group = ConvertPrefixGroup(test_repo, "test_group")
     test_prefix = ConvertPrefix(prefix_group, "ten", "10", 10)
     prefix_group.add_prefix(test_prefix)
     test_unit.valid_prefix_group = prefix_group
     # Run method
     data = ConvertMeasure.build_list_from_user_input(test_repo, "tenname2 27")
     # Check results
     assert len(data) == 1
     assert data[0].amount == 270
     assert data[0].unit == test_unit
Exemplo n.º 5
0
 def test_to_string_with_prefix(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_type.decimals = 3
     test_unit = ConvertUnit(test_type, ["name1", "name2"], 1337)
     prefix_group = ConvertPrefixGroup(test_repo, "test_group")
     test_prefix1 = ConvertPrefix(prefix_group, "ten", "10", 10)
     test_prefix2 = ConvertPrefix(prefix_group, "hundred", "100", 100)
     prefix_group.add_prefix(test_prefix1)
     prefix_group.add_prefix(test_prefix2)
     test_unit.valid_prefix_group = prefix_group
     measure1 = ConvertMeasure(17.5, test_unit)
     # Get string
     measure_str = measure1.to_string_with_prefix(test_prefix2)
     # Check
     assert measure_str == "0.175 hundredname1"