Exemplo n.º 1
0
def test_expandRecursive_noContainer():
    model = SettingDefinitionsModel()
    model.expand = MagicMock()
    model.expandRecursive("whatever")

    assert model.expanded == []
    assert model.expand.call_count == 0
def test_dataUnhappy():
    model = createModel("single_setting.def.json")
    # Out of bounds
    assert model.data(model.index(250, 0), model.KeyRole) == QVariant()

    # Invalid index
    assert model.data(QModelIndex(), model.KeyRole) == QVariant()

    # Unknown role
    assert model.data(model.index(0, 0), Qt.UserRole + 100) == QVariant()

    empty_model = SettingDefinitionsModel()
    assert empty_model.data(model.index(0, 0), model.KeyRole) == QVariant()
Exemplo n.º 3
0
def test_dataUnhappy():
    model = createModel("single_setting.def.json")
    # Out of bounds
    assert model.data(model.index(250, 0), model.KeyRole) == QVariant()

    # Invalid index
    assert model.data(QModelIndex(), model.KeyRole) == QVariant()

    # Unknown role
    assert model.data(model.index(0, 0), Qt.UserRole + 100) == QVariant()

    empty_model = SettingDefinitionsModel()
    assert empty_model.data(model.index(0, 0), model.KeyRole) == QVariant()
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"]
Exemplo n.º 5
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"]
Exemplo n.º 6
0
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"]
Exemplo n.º 7
0
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"}]
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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
Exemplo n.º 11
0
def test_disconnectVisibilityHandler():
    model = SettingDefinitionsModel()
    visibility_handler = MagicMock()
    visibility_handler_2 = MagicMock()
    model.setVisibilityHandler(visibility_handler)
    assert visibility_handler.visibilityChanged.disconnect.call_count == 0

    model.setVisibilityHandler(visibility_handler_2)

    assert visibility_handler.visibilityChanged.disconnect.call_count > 0
Exemplo n.º 12
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
Exemplo n.º 13
0
def test_getRequires_noContainer():
    model = SettingDefinitionsModel()
    assert model.getRequires("blorp", "whatever") == []
Exemplo n.º 14
0
def test_getCountNoContainer():
    model = SettingDefinitionsModel()
    assert model.count == 0
Exemplo n.º 15
0
def test_getRequires_noDefinition():
    model = SettingDefinitionsModel()
    model._container = MagicMock()
    model._container.findDefinitions = MagicMock(return_value=[])

    assert model.getRequires("blorp", "whatever") == []
Exemplo n.º 16
0
def test_collapse_no_container():
    model = SettingDefinitionsModel()
    model.collapseRecursive("whatever")

    assert model.expanded == []
Exemplo n.º 17
0
def test_getIndexNoContainer():
    model = SettingDefinitionsModel()
    assert model.getIndex("blarg") == -1