本文整理汇总了Python中treemap.models.Plot.convert_to_database_units方法的典型用法代码示例。如果您正苦于以下问题:Python Plot.convert_to_database_units方法的具体用法?Python Plot.convert_to_database_units怎么用?Python Plot.convert_to_database_units使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Plot
的用法示例。
在下文中一共展示了Plot.convert_to_database_units方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConvertibleTest
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import convert_to_database_units [as 别名]
class ConvertibleTest(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.user = make_commander_user(self.instance)
self.plot = Plot(instance=self.instance, geom=self.instance.center)
self.plot.save_with_user(self.user)
self.tree = Tree(instance=self.instance, plot=self.plot)
self.tree.save_with_user(self.user)
def test_save_converts_width_when_units_differ(self):
set_attr_on_json_field(
self.instance, 'config.value_display.plot.width.units', 'in')
self.plot.convert_to_display_units()
self.plot.width = 12
self.plot.convert_to_database_units()
self.plot.save_with_user(self.user)
updated_plot = Plot.objects.get(pk=self.plot.pk)
self.assertAlmostEqual(1, updated_plot.width)
def test_save_converts_diameter_when_units_differ(self):
set_attr_on_json_field(
self.instance, 'config.value_display.tree.diameter.units', 'ft')
self.tree.convert_to_display_units()
self.tree.diameter = 1
self.tree.convert_to_database_units()
self.tree.save_with_user(self.user)
updated_tree = Tree.objects.get(pk=self.tree.pk)
self.assertAlmostEqual(12, updated_tree.diameter)
def test_save_does_not_convert_width_when_units_same(self):
set_attr_on_json_field(
self.instance, 'config.value_display.plot.width.units', 'ft')
self.plot.width = 12
self.plot.save_with_user(self.user)
updated_plot = Plot.objects.get(pk=self.plot.pk)
self.assertEqual(12, updated_plot.width)
def test_save_does_not_convert_diameter_when_units_same(self):
set_attr_on_json_field(
self.instance, 'config.value_display.tree.diameter.units', 'in')
self.tree.diameter = 1
self.tree.save_with_user(self.user)
updated_tree = Tree.objects.get(pk=self.tree.pk)
self.assertEqual(1, updated_tree.diameter)