def test_setRootKeyUnknownDefinition(): model = SettingDefinitionsModel() model._container = MagicMock() model._container.findDefinitions = MagicMock(return_value = []) model.rootKeyChanged = MagicMock() model.setRootKey("Blorp") assert model.rootKeyChanged.emit.call_count == 0
def test_expandRecursive_noDefinition(): model = SettingDefinitionsModel() model._container = MagicMock() model._container.findDefinitions = MagicMock(return_value = False) model.expand = MagicMock() model.expandRecursive("whatever") assert model.expanded == [] assert model.expand.call_count == 0
def test_getAndSet(data): model = SettingDefinitionsModel() model._container = MagicMock() # Convert the first letter into a capital attribute = list(data["attribute"]) attribute[0] = attribute[0].capitalize() attribute = "".join(attribute) # Attempt to set the value getattr(model, "set" + attribute)(data["value"]) # Ensure that the value got set assert getattr(model, data["attribute"]) == data["value"]
def test_getAndSet(data): model = SettingDefinitionsModel() model._scheduleUpdateVisibleRows = MagicMock() model._container = MagicMock() # Convert the first letter into a capital attribute = list(data["attribute"]) attribute[0] = attribute[0].capitalize() attribute = "".join(attribute) # Attempt to set the value with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance"): getattr(model, "set" + attribute)(data["value"]) # Ensure that the value got set assert getattr(model, data["attribute"]) == data["value"]
def createModel(definition = "multiple_settings.def.json"): model = SettingDefinitionsModel() # Get a basic definition container uid = str(uuid.uuid4()) definition_container = DefinitionContainer(uid) with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "definitions", definition), encoding="utf-8") as data: json = data.read() definition_container.deserialize(json) model._container = definition_container model.setShowAll(True) model.forceUpdate() model._updateVisibleRows() return model
def createModel(definition="multiple_settings.def.json"): model = SettingDefinitionsModel() # Get a basic definition container uid = str(uuid.uuid4()) definition_container = DefinitionContainer(uid) with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "definitions", definition), encoding="utf-8") as data: json = data.read() definition_container.deserialize(json) model._container = definition_container model.setShowAll(True) model.forceUpdate() model._updateVisibleRows() return model
def test_getRequiredBy_withRelationsSet(): model = SettingDefinitionsModel() model._container = MagicMock() relation_1 = MagicMock() relation_1.type = RelationType.RequiredByTarget relation_2 = MagicMock() relation_2.type = RelationType.RequiresTarget relation_2.role = "HERPDERP" relation_3 = MagicMock() relation_3.type = RelationType.RequiredByTarget relation_3.role = "yay" relation_3.target.key = "key_3" relation_3.target.label = "label_3" mocked_definition_1 = MagicMock() mocked_definition_1.relations = [relation_1, relation_2, relation_3] model._container.findDefinitions = MagicMock(return_value=[mocked_definition_1]) assert model.getRequiredBy("blorp", "yay") == [{"key": "key_3", "label": "label_3"}]
def test_getRequires_noDefinition(): model = SettingDefinitionsModel() model._container = MagicMock() model._container.findDefinitions = MagicMock(return_value=[]) assert model.getRequires("blorp", "whatever") == []