本文整理汇总了Python中modules.Convert.ConvertType.decimals方法的典型用法代码示例。如果您正苦于以下问题:Python ConvertType.decimals方法的具体用法?Python ConvertType.decimals怎么用?Python ConvertType.decimals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modules.Convert.ConvertType
的用法示例。
在下文中一共展示了ConvertType.decimals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_string_no_prefix
# 需要导入模块: from modules.Convert import ConvertType [as 别名]
# 或者: from modules.Convert.ConvertType import decimals [as 别名]
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"
示例2: test_to_string
# 需要导入模块: from modules.Convert import ConvertType [as 别名]
# 或者: from modules.Convert.ConvertType import decimals [as 别名]
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"
示例3: test_to_string_with_prefix
# 需要导入模块: from modules.Convert import ConvertType [as 别名]
# 或者: from modules.Convert.ConvertType import decimals [as 别名]
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"
示例4: test_json
# 需要导入模块: from modules.Convert import ConvertType [as 别名]
# 或者: from modules.Convert.ConvertType import decimals [as 别名]
def test_json(self):
# Set up test objects
test_repo = ConvertRepo()
test_type = ConvertType(test_repo, "test_type")
test_type.decimals = 4
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)
# Collapse to XML and rebuild
test_json = test_type.to_json()
rebuild_type = ConvertType.from_json(test_repo, test_json)
# Test the type
assert rebuild_type.repo == test_repo
assert len(rebuild_type.unit_list) == 2
assert rebuild_type.name == "test_type"
assert rebuild_type.decimals == 4
assert rebuild_type.base_unit.name_list[0] == "base_unit"