def test_onProperty_convertTo():
    """Test that a property value is property converted before it is
    tested against the prop sheet model cache.
    """
    
    item1 = MyItem(someBool=True)
    item2 = MyItem(someBool=False)
    item3 = MyItem(someBool=False)
    model = Model()
    model.items = [item1, item2, item3]
    assert model.someBool == Qt.PartiallyChecked

    someBoolChanged = util.Condition()
    model.someBoolChanged.connect(someBoolChanged)
    assert someBoolChanged.callCount == 0

    # should convert the value before testing, still resulting in
    # someBool == Qt.PartiallyChecked and not emit the someBoolChanged signal
    item2.setSomeBool(True)
    assert model.someBool == Qt.PartiallyChecked
    assert someBoolChanged.callCount == 0

    # should convert the value before testing, but now resulting in
    # someBool == Qt.Checked and should emit the someBoolChanged signal
    item3.setSomeBool(True)
    assert model.someBool == Qt.Checked
    assert someBoolChanged.callCount == 1
Exemple #2
0
 def qWaitForMessageBox(self, action, contains=None, handleClick=None):
     from PyQt5.QtWidgets import QAbstractButton
     msgBoxAccepted = util.Condition()
     def acceptMessageBox():
         # def isWindowUp():
         #     return bool(QApplication.activeModalWidget())
         # self.waitUntil(isWindowUp, 2000)
         widget = QApplication.activeModalWidget()
         if widget:
             if contains:
                 assert contains in widget.text()
             if handleClick and handleClick():
                 msgBoxAccepted()
                 msgBoxAccepted.timer.stop()
             elif isinstance(widget, QMessageBox):
                 okButton = widget.button(QMessageBox.Ok)
                 widget.buttonClicked[QAbstractButton].connect(msgBoxAccepted)
                 msgBoxAccepted()
                 self.mouseClick(okButton, Qt.LeftButton)
                 msgBoxAccepted.timer.stop()
     msgBoxAccepted.timer = QTimer(QApplication.instance())
     msgBoxAccepted.timer.timeout.connect(acceptMessageBox)
     msgBoxAccepted.timer.start(100)
     action()
     assert msgBoxAccepted.wait() == True
Exemple #3
0
def test_remove_layer(qApp, qtbot):
    model = LayerModel()
    document = Document()
    model.document = document
    model.addRow()
    model.addRow()
    rowsRemoved = util.Condition()
    model.rowsRemoved.connect(rowsRemoved)
    qtbot.clickYesAfter(lambda: model.removeRow(0))

    assert rowsRemoved.callCount == 1
    assert model.rowCount() == 1
    assert model.data(model.index(0, 0)) == (model.NEW_NAME_TMPL % 2)
    assert model.data(model.index(0, 0), model.ActiveRole) == Qt.Unchecked
Exemple #4
0
def test_add_layer(qApp):
    document = Document()
    model = LayerModel()
    model.document = document
    rowsInserted = util.Condition()
    model.rowsInserted.connect(rowsInserted)
    model.addRow()
    assert rowsInserted.callCount == 1
    assert model.rowCount() == 1
    assert model.data(model.index(0, 0)) == (model.NEW_NAME_TMPL % 1)

    model.addRow()
    assert rowsInserted.callCount == 2
    assert model.rowCount() == 2
    assert model.data(model.index(1, 0)) == (model.NEW_NAME_TMPL % 2)
def test_rename_tag_retains_tag_on_items(qApp):

    s = Document()
    s.setTags(['aaa', 'ccc', 'ddd'])
    item = Item()
    s.addItem(item)
    item.setTags(['ddd'])

    model = TagsModel()
    model.items = [item]
    model.document = s
    assert model.data(model.index(2, 0), model.NameRole) == 'ddd'

    dataChanged = util.Condition()
    model.dataChanged.connect(dataChanged)
    modelReset = util.Condition()
    model.modelReset.connect(modelReset)

    model.setData(model.index(2, 0), 'bbb', model.NameRole)

    assert s.tags() == ['aaa', 'bbb', 'ccc']
    assert item.tags() == ['bbb']
    assert modelReset.callCount == 1
    assert dataChanged.callCount == 0
def test_add_tag(qApp):
    document = Document()
    model = TagsModel()
    model.document = document
    item1 = Item()
    item2 = Item()
    model.items = [item1, item2]
    assert model.rowCount() == 0

    modelReset = util.Condition()
    model.modelReset.connect(modelReset)

    model.addTag()
    assert modelReset.callCount == 1
    assert model.rowCount() == 1
    assert model.data(model.index(0, 0)) == model.NEW_NAME_TMPL % 1
def test_signals():

    item1 = MyItem(myint=10)
    item2 = MyItem()

    model = Model()
    changed = util.Condition()
    model.myintChanged.connect(changed)
    model.items = [item1, item2]

    assert changed.callCount == 0

    model.myint = 123
    assert changed.callCount == 1

    model.resetMyint()
    assert changed.callCount == 2
def test_remove_tag(qApp, qtbot):
    model = TagsModel()
    document = Document(tags=['here', 'we', 'are'])
    model.document = document
    item1 = Item(tags=['here', 'we'])
    item2 = Item(tags=['here'])
    model.items = [item1, item2]

    modelReset = util.Condition()
    model.modelReset.connect(modelReset)

    qtbot.clickYesAfter(lambda: model.removeTag(1))
    assert modelReset.callCount == 1
    assert model.rowCount() == 2
    assert model.data(model.index(0, 0)) == 'are'
    assert model.data(model.index(0, 0), model.ActiveRole) == Qt.Unchecked
    assert model.data(model.index(1, 0)) == 'we'
    assert model.data(model.index(1, 0),
                      model.ActiveRole) == Qt.PartiallyChecked
def test_reset():

    item1 = MyItem(myint=123)
    item2 = MyItem(myint=321)

    model = Model()
    model.items = [item1, item2]
    myintChanged = util.Condition(model.myintChanged)

    model.myint = 222
    assert myintChanged.callCount == 1
    assert item1.prop('myint').isset() == True
    assert item2.prop('myint').isset() == True
    assert item1.prop('myint').get() != model.defaultFor('myint')
    assert item2.prop('myint').get() != model.defaultFor('myint')

    model.resetMyint()
    assert myintChanged.callCount == 2
    assert item1.prop('myint').isset() == False
    assert item2.prop('myint').isset() == False
    assert item1.prop('myint').get() == model.defaultFor('myint')
    assert item2.prop('myint').get() == model.defaultFor('myint')