• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python Convert.ConvertType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中modules.Convert.ConvertType的典型用法代码示例。如果您正苦于以下问题:Python ConvertType类的具体用法?Python ConvertType怎么用?Python ConvertType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ConvertType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_add_unit

 def test_add_unit(self):
     # Set up test objects
     test_repo = ConvertRepo()
     test_type = ConvertType(test_repo, "test_type")
     test_type.base_unit = ConvertUnit(test_type, ["base_unit"], 1)
     test_unit = ConvertUnit(test_type, ["name1", "name2"], 1337)
     # Add unit to type
     test_type.add_unit(test_unit)
     # Check
     assert len(test_type.unit_list) == 1
     assert test_type.unit_list[0] == test_unit
开发者ID:joshcoales,项目名称:Hallo,代码行数:11,代码来源:testConvertType.py


示例2: test_init

 def test_init(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_unit = ConvertUnit(test_type, ["name1", "name2"], 1337)
     # Init
     test_measure = ConvertMeasure(12.34, test_unit)
     # Check
     assert test_measure.amount == 12.34
     assert test_measure.unit == test_unit
开发者ID:joshcoales,项目名称:Hallo,代码行数:11,代码来源:testConvertMeasure.py


示例3: test_convert_to_base

 def test_convert_to_base(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_unit = ConvertUnit(test_type, ["name1", "name2"], 1337)
     measure1 = ConvertMeasure(17.5, test_unit)
     # Convert to base
     test_result = measure1.convert_to_base()
     # Check
     assert test_result.unit.name_list[0] == "base_unit"
     assert test_result.amount == 17.5*1337
开发者ID:joshcoales,项目名称:Hallo,代码行数:12,代码来源:testConvertMeasure.py


示例4: test_is_equal

 def test_is_equal(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_unit = ConvertUnit(test_type, ["name1", "name2"], 1337)
     measure1 = ConvertMeasure(17.5, test_unit)
     measure2 = ConvertMeasure(17.5, test_unit)
     # Check not the same object
     assert not measure1 == measure2
     # Check is equal
     assert measure1.is_equal(measure2)
     assert measure2.is_equal(measure1)
开发者ID:joshcoales,项目名称:Hallo,代码行数:13,代码来源:testConvertMeasure.py


示例5: test_to_string_no_prefix

 def test_to_string_no_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)
     measure1 = ConvertMeasure(17.5, test_unit)
     # Get string
     measure_str = measure1.to_string()
     # Check
     assert str(measure1) == measure_str
     assert measure_str == "17.500 name1"
开发者ID:joshcoales,项目名称:Hallo,代码行数:13,代码来源:testConvertMeasure.py


示例6: test_build_list_from_user_input_no_match

 def test_build_list_from_user_input_no_match(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, ["name_a", "name_b"], 1337)
     test_type.add_unit(test_unit)
     # Run method
     try:
         ConvertMeasure.build_list_from_user_input(test_repo, "32 name_c")
         assert False, "Should have failed to find a valid unit."
     except Exception as e:
         assert "unrecognised unit" in str(e).lower()
开发者ID:joshcoales,项目名称:Hallo,代码行数:14,代码来源:testConvertMeasure.py


示例7: test_build_list_from_user_input_end

 def test_build_list_from_user_input_end(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)
     # Run method
     data = ConvertMeasure.build_list_from_user_input(test_repo, "name2 27")
     # Check results
     assert len(data) == 1
     assert data[0].amount == 27
     assert data[0].unit == test_unit
开发者ID:joshcoales,项目名称:Hallo,代码行数:14,代码来源:testConvertMeasure.py


示例8: test_build_list_from_user_input_middle

 def test_build_list_from_user_input_middle(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, ["name_a", "name_b"], 1337)
     test_type.add_unit(test_unit)
     # Run method
     try:
         ConvertMeasure.build_list_from_user_input(test_repo, "name_b 15 name_a")
         assert False, "Should have failed to find amount."
     except Exception as e:
         assert "cannot find amount" in str(e).lower()
开发者ID:joshcoales,项目名称:Hallo,代码行数:14,代码来源:testConvertMeasure.py


示例9: test_convert_to_offset

 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
开发者ID:joshcoales,项目名称:Hallo,代码行数:15,代码来源:testConvertMeasure.py


示例10: test_convert_to_different_types

 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)
开发者ID:joshcoales,项目名称:Hallo,代码行数:16,代码来源:testConvertMeasure.py


示例11: test_to_string

 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"
开发者ID:joshcoales,项目名称:Hallo,代码行数:17,代码来源:testConvertMeasure.py


示例12: test_to_string_with_prefix

 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"
开发者ID:joshcoales,项目名称:Hallo,代码行数:18,代码来源:testConvertMeasure.py


示例13: test_build_list_from_user_input_prefix

 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
开发者ID:joshcoales,项目名称:Hallo,代码行数:18,代码来源:testConvertMeasure.py


示例14: setUp

 def setUp(self):
     super().setUp()
     # Create test repo
     self.test_repo = ConvertRepo()
     self.test_type1 = ConvertType(self.test_repo, "test_type1")
     self.test_repo.add_type(self.test_type1)
     self.test_unit1a = ConvertUnit(self.test_type1, ["unit1a"], 1)
     self.test_type1.base_unit = self.test_unit1a
     self.test_unit1b = ConvertUnit(self.test_type1, ["unit1b", "same_name"], 2)
     self.test_unit1b.abbr_list = ["abbr1b", "abbr1bz"]
     self.test_type1.add_unit(self.test_unit1b)
     self.test_unit1c = ConvertUnit(self.test_type1, ["unit1c"], 4)
     self.test_unit1b.abbr_list = ["abbr1c"]
     self.test_type1.add_unit(self.test_unit1c)
     # Add a second type
     self.test_type2 = ConvertType(self.test_repo, "test_type2")
     self.test_repo.add_type(self.test_type2)
     self.test_unit2a = ConvertUnit(self.test_type2, ["unit2a"], 1)
     self.test_type2.base_unit = self.test_unit2a
     self.test_unit2b = ConvertUnit(self.test_type2, ["unit2b", "same_name"], 5)
     self.test_type2.add_unit(self.test_unit2b)
     # Add a prefix group
     self.test_group1 = ConvertPrefixGroup(self.test_repo, "test_group1")
     self.test_repo.add_prefix_group(self.test_group1)
     self.test_prefix1a = ConvertPrefix(self.test_group1, "prefix1a", "pref1a", 5)
     self.test_group1.add_prefix(self.test_prefix1a)
     self.test_prefix1b = ConvertPrefix(self.test_group1, "prefixb", "pref1b", 15)
     self.test_group1.add_prefix(self.test_prefix1b)
     # Add a second prefix group
     self.test_group2 = ConvertPrefixGroup(self.test_repo, "test_group2")
     self.test_repo.add_prefix_group(self.test_group2)
     self.test_prefix2a = ConvertPrefix(self.test_group2, "prefix2a", "pref2a", 7)
     self.test_group2.add_prefix(self.test_prefix2a)
     self.test_prefix2b = ConvertPrefix(self.test_group2, "prefixb", "pref2b", 42)
     self.test_group2.add_prefix(self.test_prefix2b)
     # Move current convert.json
     try:
         os.rename("store/convert.json", "store/convert.json.tmp")
     except OSError:
         pass
     # Put this test repo into the Convert object
     convert_function = self.function_dispatcher.get_function_by_name("convert")
     convert_function_obj = self.function_dispatcher.get_function_object(convert_function)  # type: Convert
     convert_function_obj.convert_repo = self.test_repo
开发者ID:joshcoales,项目名称:Hallo,代码行数:44,代码来源:ConvertFunctionTestBase.py


示例15: test_json

 def test_json(self):
     test_repo = ConvertRepo()
     test_type1 = ConvertType(test_repo, "test_type1")
     test_type2 = ConvertType(test_repo, "test_type2")
     test_repo.add_type(test_type1)
     test_repo.add_type(test_type2)
     test_unit1 = ConvertUnit(test_type1, ["unit1"], 1)
     test_unit2 = ConvertUnit(test_type2, ["unit2"], 1)
     test_type1.base_unit = test_unit1
     test_type2.base_unit = test_unit2
     test_group1 = ConvertPrefixGroup(test_repo, "group1")
     test_group2 = ConvertPrefixGroup(test_repo, "group2")
     test_repo.add_prefix_group(test_group1)
     test_repo.add_prefix_group(test_group2)
     # Save to JSON and load
     try:
         try:
             os.rename("store/convert.json", "store/convert.json.tmp")
         except OSError:
             pass
         test_repo.save_json()
         new_repo = ConvertRepo.load_json()
         assert len(new_repo.type_list) == 2
         assert len(new_repo.prefix_group_list) == 2
         assert "test_type1" in [x.name for x in new_repo.type_list]
         assert "test_type2" in [x.name for x in new_repo.type_list]
         assert "group1" in [x.name for x in new_repo.prefix_group_list]
         assert "group2" in [x.name for x in new_repo.prefix_group_list]
     finally:
         try:
             os.remove("store/convert.json")
         except OSError:
             pass
         try:
             os.rename("store/convert.json.tmp", "store/convert.json")
         except OSError:
             pass
开发者ID:joshcoales,项目名称:Hallo,代码行数:37,代码来源:testConvertRepo.py


示例16: test_get_full_unit_list

 def test_get_full_unit_list(self):
     # Set up test objects
     test_repo = ConvertRepo()
     test_type = ConvertType(test_repo, "test_type")
     test_unitb = ConvertUnit(test_type, ["base_unit"], 1)
     test_type.base_unit = test_unitb
     test_unit1 = ConvertUnit(test_type, ["name1", "name2"], 1337)
     test_unit2 = ConvertUnit(test_type, ["name3", "name4"], 505)
     test_type.add_unit(test_unit1)
     test_type.add_unit(test_unit2)
     # Check full unit list
     assert len(test_type.get_full_unit_list()) == 3
     assert test_unitb in test_type.get_full_unit_list()
     assert test_unit1 in test_type.get_full_unit_list()
     assert test_unit2 in test_type.get_full_unit_list()
开发者ID:joshcoales,项目名称:Hallo,代码行数:15,代码来源:testConvertType.py


示例17: test_get_unit_by_name

 def test_get_unit_by_name(self):
     # Set up test objects
     test_repo = ConvertRepo()
     test_type = ConvertType(test_repo, "test_type")
     test_unitb = ConvertUnit(test_type, ["base_unit"], 1)
     test_type.base_unit = test_unitb
     test_unit1 = ConvertUnit(test_type, ["name1", "name2"], 1337)
     test_unit2 = ConvertUnit(test_type, ["name3", "name4"], 505)
     test_unit2.add_abbr("u2")
     test_type.add_unit(test_unit1)
     test_type.add_unit(test_unit2)
     # test some stuff
     assert test_type.get_unit_by_name("base_unit") == test_unitb
     assert test_type.get_unit_by_name("NAME1") == test_unit1
     assert test_type.get_unit_by_name("NaMe4") == test_unit2
     assert test_type.get_unit_by_name("u2") == test_unit2
开发者ID:joshcoales,项目名称:Hallo,代码行数:16,代码来源:testConvertType.py


示例18: test_build_list_from_user_input_multi_match

 def test_build_list_from_user_input_multi_match(self):
     # Setup test objects
     test_repo = ConvertRepo()
     test_type1 = ConvertType(test_repo, "test_type1")
     test_type1.base_unit = ConvertUnit(test_type1, ["base_unit1"], 1)
     test_type2 = ConvertType(test_repo, "test_type2")
     test_type2.base_unit = ConvertUnit(test_type2, ["base_unit2"], 1)
     test_repo.add_type(test_type1)
     test_repo.add_type(test_type2)
     test_unit1 = ConvertUnit(test_type1, ["name1", "name2"], 1337)
     test_unit2 = ConvertUnit(test_type2, ["name2", "name3"], 567)
     test_type1.add_unit(test_unit1)
     test_type2.add_unit(test_unit2)
     # Run method
     data = ConvertMeasure.build_list_from_user_input(test_repo, "7 name2")
     # Check results
     assert len(data) == 2
     assert data[0].amount == 7
     assert data[1].amount == 7
     assert test_unit1 in [data[x].unit for x in [0, 1]]
     assert test_unit2 in [data[x].unit for x in [0, 1]]
开发者ID:joshcoales,项目名称:Hallo,代码行数:21,代码来源:testConvertMeasure.py


示例19: test_remove_unit

 def test_remove_unit(self):
     # Set up 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", "name4"], 505)
     test_type.add_unit(test_unit1)
     test_type.add_unit(test_unit2)
     # Check it's all set up correctly
     assert len(test_type.unit_list) == 2
     # Remove unit from type
     test_type.remove_unit(test_unit1)
     # Check
     assert len(test_type.unit_list) == 1
     assert test_type.unit_list[0] == test_unit2
开发者ID:joshcoales,项目名称:Hallo,代码行数:16,代码来源:testConvertType.py


示例20: test_get_full_unit_list

 def test_get_full_unit_list(self):
     # Set up test objects
     test_repo = ConvertRepo()
     test_type1 = ConvertType(test_repo, "test_type1")
     test_repo.add_type(test_type1)
     test_unit1 = ConvertUnit(test_type1, ["unit1"], 1)
     test_unit2 = ConvertUnit(test_type1, ["unit2"], 10)
     test_unit3 = ConvertUnit(test_type1, ["unit3"], 100)
     test_type1.base_unit = test_unit1
     test_type1.add_unit(test_unit2)
     test_type1.add_unit(test_unit3)
     test_type2 = ConvertType(test_repo, "test_type2")
     test_unit4 = ConvertUnit(test_type2, ["unit4"], 1)
     test_unit5 = ConvertUnit(test_type2, ["unit5"], 1000)
     test_type2.base_unit = test_unit4
     test_type2.add_unit(test_unit5)
     test_repo.add_type(test_type2)
     # Test
     assert test_unit1 in test_repo.get_full_unit_list()
     assert test_unit2 in test_repo.get_full_unit_list()
     assert test_unit3 in test_repo.get_full_unit_list()
     assert test_unit4 in test_repo.get_full_unit_list()
     assert test_unit5 in test_repo.get_full_unit_list()
     assert len(test_repo.get_full_unit_list()) == 5
开发者ID:joshcoales,项目名称:Hallo,代码行数:24,代码来源:testConvertRepo.py



注:本文中的modules.Convert.ConvertType类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python error.traceback函数代码示例发布时间:2022-05-27
下一篇:
Python modules.Mixin类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap