def test_fillByDict(self, data): setting = Setting(self._machine_manager, "test", self._catalog) setting.fillByDict(data) assert setting.getType() == data["type"] assert setting.getDefaultValue() == data["default"] assert setting.getLabel() == data["label"] assert setting.getDescription() == data["description"] assert setting.isVisible()
def test_fillByDict(self): setting = Setting(self._machine_manager, "test", self._catalog) data = { "type": "int", "default": 4, "label": "Test Setting", "description": "A Test Setting", "unit": "furlongs per fortnight", "visible": True } setting.fillByDict(data) self.assertEqual("int", setting.getType()) self.assertEqual(4, setting.getDefaultValue()) self.assertEqual("Test Setting", setting.getLabel()) self.assertEqual("A Test Setting", setting.getDescription()) self.assertEqual("furlongs per fortnight", setting.getUnit()) self.assertTrue(setting.isVisible())
def test_fillByDictWithChildren(self): setting = Setting(self._machine_manager, "test", self._catalog) data = { "type": "int", "default": 4, "label": "Test Setting", "description": "A Test Setting", "unit": "furlongs per fortnight", "visible": True, # Since python's dict is unordered but we want an ordered dict we # have to go through a bit of magic to make sure we define it as an # ordered dict. "children": collections.OrderedDict( sorted({ "test_child1": { "type": "int", "default": 9, "label": "Test Child 1", "description": "Test Setting Child 1", }, "test_child2": { "type": "int", "default": 5, "label": "Test Child 2", "description": "Test Setting Child 2", "inherit": False }, "test_child3": { "type": "int", "default": 99, "label": "Test Child 3", "description": "Test Setting Child 3", "inherit_function": "parent_value * 10" } }.items(), key=lambda k: k[0])) } setting.fillByDict(data) profile = Profile(setting) assert len(setting.getChildren()) == 3 child1 = setting.getChildren()[0] child2 = setting.getChildren()[1] child3 = setting.getChildren()[2] # Children should keep the order in which they were defined assert child1.getKey() == "test_child1" assert child2.getKey() == "test_child2" assert child3.getKey() == "test_child3" # All children should have "setting" as their parent. assert child1.getParent() == setting assert child2.getParent() == setting assert child3.getParent() == setting # Child visibility should not affect parent visibility. assert setting.isVisible() # Child 1 uses default inheritance so should inherit its parent value assert child1.getDefaultValue(profile) == 4 # Child 2 does not inherit so should return its default value assert child2.getDefaultValue(profile) == 5 # Child 3 uses an inherit function and should return parent's value * 10. assert child3.getDefaultValue(profile) == 40
def test_fillByDictWithChildren(self): setting = Setting(self._machine_manager, "test", self._catalog) data = { "type": "int", "default": 4, "label": "Test Setting", "description": "A Test Setting", "unit": "furlongs per fortnight", "visible": True, # Since python's dict is unordered but we want an ordered dict we # have to go through a bit of magic to make sure we define it as an # ordered dict. "children": collections.OrderedDict(sorted({ "test_child1": { "type": "int", "default": 9, "label": "Test Child 1", "description": "Test Setting Child 1", }, "test_child2": { "type": "int", "default": 5, "label": "Test Child 2", "description": "Test Setting Child 2", "inherit": False }, "test_child3": { "type": "int", "default": 99, "label": "Test Child 3", "description": "Test Setting Child 3", "inherit_function": "parent_value * 10" } }.items(), key = lambda k: k[0])) } setting.fillByDict(data) profile = Profile(setting) assert len(setting.getChildren()) == 3 child1 = setting.getChildren()[0] child2 = setting.getChildren()[1] child3 = setting.getChildren()[2] # Children should keep the order in which they were defined assert child1.getKey() == "test_child1" assert child2.getKey() == "test_child2" assert child3.getKey() == "test_child3" # All children should have "setting" as their parent. assert child1.getParent() == setting assert child2.getParent() == setting assert child3.getParent() == setting # Child visibility should not affect parent visibility. assert setting.isVisible() # Child 1 uses default inheritance so should inherit its parent value assert child1.getDefaultValue(profile) == 4 # Child 2 does not inherit so should return its default value assert child2.getDefaultValue(profile) == 5 # Child 3 uses an inherit function and should return parent's value * 10. assert child3.getDefaultValue(profile) == 40