def test_read_fd(qApp): """ Just test reading in an actual fd. """ with open(os.path.join(conftest.TIMELINE_TEST_FD, 'diagram.pickle'), 'rb') as f: bdata = f.read() document = Document() data = pickle.loads(bdata) assert document.read(data) == None
def test_update_set_tag_on_inspected_items_out_of_layer(qApp): """ Show layer with people that have emotional process symbols that don’t have the layer’s tags, inspect those symbols from personal timeline, add tag for the layer -> symbols don’t appear. """ tags = ['here'] s = Document() s.setTags(tags) layer1 = Layer(tags=tags) s.addItem(layer1) p1 = Person(name='p1', tags=tags) p2 = Person(name='p2', tags=tags) s.addItems(p1, p2) cutoff = Emotion(kind=util.ITEM_CUTOFF, personA=p1, personB=p2) s.addItems(cutoff) layer1.setActive(True) date = QDate.currentDate() assert p1.shouldShowFor(date, tags) == True assert p2.shouldShowFor(date, tags) == True assert cutoff.shouldShowFor(date, tags) == False assert cutoff.isVisible() == False # Simulate inspecting a hidden emotion from person props cutoff.setTags(tags) assert cutoff.shouldShowFor(date, tags) == True assert cutoff.isVisible() == True
def test_set_active(qApp): document = Document() model = TagsModel() model.document = document item1 = Item() item2 = Item() model.items = [item1, item2] document.setTags(['here', 'we', 'are']) assert item1.tags() == [] assert item2.tags() == [] def set(row, value): assert model.setData(model.index(row, 0), value, model.ActiveRole) is True set(0, True) assert item1.tags() == ['are'] assert item2.tags() == ['are'] set(2, True) assert item1.tags() == ['are', 'we'] assert item2.tags() == ['are', 'we'] set(0, False) assert item1.tags() == ['we'] assert item2.tags() == ['we'] set(2, False) assert item1.tags() == [] assert item2.tags() == []
def test_init_deinit(qApp): model = LayerModel() assert model.rowCount() == 0 document = Document() layer1 = Layer(name='Layer 1') layer2 = Layer(name='Layer 2', active=True) layer3 = Layer(name='Layer 3', active=True) document.addItems(layer1, layer2, layer3) model.document = document assert model.rowCount() == 3 assert model.data(model.index(0, 0), model.IdRole) == layer1.id assert model.data(model.index(1, 0), model.IdRole) == layer2.id assert model.data(model.index(2, 0), model.IdRole) == layer3.id assert model.data(model.index(0, 0)) == 'Layer 1' assert model.data(model.index(1, 0)) == 'Layer 2' assert model.data(model.index(2, 0)) == 'Layer 3' assert model.data(model.index(0, 0), model.ActiveRole) == Qt.Unchecked assert model.data(model.index(1, 0), model.ActiveRole) == Qt.Checked assert model.data(model.index(2, 0), model.ActiveRole) == Qt.Checked model.resetDocument() assert model.rowCount() == 0 with pytest.raises(IndexError): model.data(model.index(0, 0))
def test_hasActiveLayers(qApp): document = Document() assert document.hasActiveLayers == False layer = Layer(active=True) document.addItem(layer) assert document.hasActiveLayers == True layer.setActive(False) assert document.hasActiveLayers == False
def test_hasActiveLayers(qApp): document = Document() model = DocumentModel() model.document = document assert model.hasActiveLayers == document.hasActiveLayers layer = Layer(active=True) document.addItem(layer) assert model.hasActiveLayers == document.hasActiveLayers layer.setActive(False) assert model.hasActiveLayers == document.hasActiveLayers
def test_exclusiveLayerSelection(qApp): document = Document() layerModel = LayerModel() layerModel.document = document layer1 = Layer(name='Layer 1', active=True) layer2 = Layer(name='Layer 2') document.addItems(layer1, layer2) assert layer1.active() == True layerModel.setActiveExclusively(1) assert layer2.active() == True assert layer1.active() == False
def test_rename_tag_retains_tag_on_items(qApp): s = Document() s.setTags(['aaa', 'ccc', 'ddd']) item = Item() s.addItem(item) item.setTags(['ddd']) s.renameTag('ddd', 'bbb') assert s.tags() == ['aaa', 'bbb', 'ccc'] assert item.tags() == ['bbb']
def test_documentChanged(qApp): document = Document() model = DocumentModel() documentChanged = misc.Condition(model.documentChanged) model.document = document assert documentChanged.callCount == 1 assert documentChanged.callArgs[0][0] == document
def test_init_deinit(qApp): model = TagsModel() assert model.rowCount() == 0 document = Document(tags=['here', 'we', 'are']) model.document = document assert model.rowCount() == 3 item1 = Item(tags=['here', 'we']) item2 = Item(tags=['here']) model.items = [item1, item2] assert model.data(model.index(0, 0)) == 'are' assert model.data(model.index(1, 0)) == 'here' assert model.data(model.index(2, 0)) == 'we' assert model.data(model.index(0, 0), model.ActiveRole) == Qt.Unchecked # are assert model.data(model.index(1, 0), model.ActiveRole) == Qt.Checked # here assert model.data(model.index(2, 0), model.ActiveRole) == Qt.PartiallyChecked # we model.resetItems() assert model.rowCount() == 3 # should not change item tags assert item1.tags() == ['here', 'we'] assert item2.tags() == ['here'] model.resetDocument() assert model.rowCount() == 0 with pytest.raises(KeyError): model.data(model.index(0, 0))
def __test_valid_props(qApp): document = Document() model = DocumentModel() model.document = document attrs = model.classProperties(DocumentModel) for kwargs in attrs: attr = kwargs['attr'] Debug(attr, model.get(attr))
def __test_getPrintRect(qApp): # was always changing by a few pixels... s = Document() s.setTags(['NW', 'NE', 'SW', 'SE']) northWest = Person(name='NW', pos=QPointF(-1000, -1000), tags=['NW']) northEast = Person(name='NE', pos=QPointF(1000, -1000), tags=['NE']) southWest = Person(name='SW', pos=QPointF(-1000, 1000), tags=['SW']) southEast = Person(name='SE', pos=QPointF(1000, 1000), tags=['SE']) s.addItems(northWest, northEast, southWest, southEast) fullRect = s.getPrintRect() assert fullRect == QRectF(-1162.5, -1181.25, 2407.5, 2343.75) nwRect = s.getPrintRect(forTags=['NW']) assert nwRect == QRectF(-1162.5, -1181.25, 417.5, 343.75)
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
def test_read(qApp): """ Just try to break the most basic object constructors. """ stuff = [] def byId(id): return None data = { 'items': [ { 'kind': 'Person', 'id': 1, 'events': [ { 'id': 2 } ], 'parents': None, 'marriages': [] } ] } document = Document() document.read(data, byId)
def test_layered_property_undo_redo(qApp): """ commands.SetItemProperty wasn't working for non-layered properties. """ document = Document() item = LayeredItem() layer = Layer(name='Layer 1') document.addItems(layer, item) # 0 assert item.num() == -1 assert item.count == 0 assert item.layeredCount == 0 item.setNum(1, undo=True) # 1 assert item.num() == 1 assert item.count == 1 assert item.layeredCount == 0 commands.stack().undo() # 0 assert item.num() == -1 assert item.count == 2 assert item.layeredCount == 0 commands.stack().redo() # 1 assert item.num() == 1 assert item.count == 3 assert item.layeredCount == 0
def test_set_active(qApp): model = LayerModel() document = Document() layer1 = Layer(name='Layer 1') layer2 = Layer(name='Layer 2') layer3 = Layer(name='Layer 3') document.addItems(layer1, layer2, layer3) model.document = document assert layer1.active() == False assert layer2.active() == False assert layer3.active() == False def set(row, value): assert model.setData(model.index(row, 0), value, model.ActiveRole) is True set(0, True) assert layer1.active() == True assert layer2.active() == False assert layer2.active() == False set(2, True) assert layer1.active() == True assert layer2.active() == False assert layer3.active() == True set(0, False) assert layer1.active() == False assert layer2.active() == False assert layer3.active() == True set(2, False) assert layer1.active() == False assert layer2.active() == False assert layer3.active() == False
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_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_reset_layered_props(qApp): """ Item.write was not explicitly requesting non-layered prop values. """ document = Document() person = Person() layer = Layer(name='Layer 1', active=True, storeGeometry=True) document.addItems(person, layer) person.setItemPos(QPointF(10, 10)) assert layer.active() == True assert person.pos() == QPointF(10, 10) document.resetAll() # was throwing exception in commands.py assert person.itemPos() == QPointF() assert person.pos() == QPointF()
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_layered_property(qApp): document = Document() item = LayeredItem() layer = Layer(name='Layer 1') document.addItem(item) document.addItem(layer) assert item.num() == -1 assert item.count == 0 assert item.layeredCount == 0 item.setNum(1) assert item.num() == 1 assert item.count == 1 assert item.layeredCount == 0 layer.setActive(True) assert item.num() == 1 assert item.count == 1 assert item.layeredCount == 0 item.prop('num').set(2) # item.setNum(2) assert item.num() == 2 assert item.count == 2 assert item.layeredCount == 1 layer.setActive(False) assert item.num() == 1 assert item.count == 3 assert item.layeredCount == 1 layer.setActive(True) assert item.num() == 2 assert item.count == 4 assert item.layeredCount == 2 item.prop('num').reset() assert item.num() == 1 assert item.count == 5 assert item.layeredCount == 2 layer.setActive(False) assert item.num() == 1 assert item.count == 5 assert item.layeredCount == 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_new_items_have_current_tags(qApp): s = Document() s.setTags(['are', 'here', 'you']) layer1 = Layer(tags=['here']) s.addItem(layer1) p1 = Person(name='p1') assert p1.tags() == [] layer1.setActive(True) assert p1.tags() == [] p2 = Person(name='p2') s.addItem(p2) assert p1.tags() == [] assert p2.tags() == ['here'] layer2 = Layer(tags=['you'], active=True) s.addItem(layer2) assert p1.tags() == [] assert p2.tags() == ['here'] p3 = Person(name='p3') s.addItem(p3) assert p1.tags() == [] assert p2.tags() == ['here'] assert p3.tags() == ['here', 'you'] layer1.setActive(False) p4 = Person(name='p4') s.addItem(p4) assert p1.tags() == [] assert p2.tags() == ['here'] assert p3.tags() == ['here', 'you'] assert p4.tags() == ['you']
def test_save_load_delete_items(qtbot, qApp): """ ItemDetails and SeparationIndicator that were saved to disk were not retaining ids stored in the fd, causing addItem() to asign new ids. Then item properties in layers would be out of sync, etc. Fixed by not adding items until after read(). """ document = Document() person = Person() person.setDiagramNotes('here are some notes') document.addItem(person) data = {} document.write(data) bdata = pickle.dumps(data) # document = Document() document.read(data) ## added to ensure that ItemDetails|SeparationIndicator id's match the id's in the file for id, item in document.itemRegistry.items(): assert id == item.id document.selectAll() qtbot.clickYesAfter(lambda: document.removeSelection()) # would throw exception
def test_moveLayer(qApp): document = Document() model = LayerModel() layer0 = Layer(name='Layer 0') layer1 = Layer(name='Layer 1') layer2 = Layer(name='Layer 2') document.addItems(layer0, layer1, layer2) model.document = document assert layer0.order() == 0 assert layer1.order() == 1 assert layer2.order() == 2 model.moveLayer(2, 1) assert layer0.order() == 0 assert layer1.order() == 2 assert layer2.order() == 1 model.moveLayer(0, 2) assert layer0.order() == 2 assert layer1.order() == 1 assert layer2.order() == 0 assert document.layers() == [layer2, layer1, layer0] # test reload file after reordering layers data = {} document.write(data) document2 = Document() document2.read(data) _layer0 = document2.query1(name='Layer 0') _layer1 = document2.query1(name='Layer 1') _layer2 = document2.query1(name='Layer 2') assert _layer0.order() == 2 assert _layer1.order() == 1 assert _layer2.order() == 0 assert document2.layers() == [_layer2, _layer1, _layer0]
def test_clean_stale_refs(qApp): with open(os.path.join(conftest.DATA_ROOT, 'patrick-stinson-stale-refs.fd/diagram.pickle'), 'rb') as f: bdata = f.read() document = Document() data = pickle.loads(bdata) assert len(document.prune(data)) == 9
def test_read_write_layered_props(qApp): """ Item.write was not explicitly requesting non-layered prop values. """ document = Document() person = Person() layer = Layer(name='Layer 1', active=True) document.addItems(person, layer) person.setItemPos(QPointF(10, 10)) person.setColor('#ff0000') # data = {} document.write(data) document = Document() document.read(data) assert document.people()[0].pos() == QPointF(10, 10) assert document.people()[0].color() == '#ff0000' assert document.people()[0].pen().color().name() == '#ff0000' document.layers()[0].setActive(False) assert document.people()[0].color() == None assert document.people()[0].pen().color().name() == util.PEN.color().name() document.layers()[0].setActive(True) assert document.people()[0].color() == '#ff0000' assert document.people()[0].pen().color().name() == '#ff0000'
def test_undo_add_remove_layered_item_props(qtbot, qApp): document = Document() male = Person(name='Male', kind='male') female = Person(name='Female', kind='female') marriage = Marriage(personA=male, personB=female) divorcedEvent = Event(parent=marriage, uniqueId='divorced', date=QDate(1900, 1, 1)) layer = Layer(name='Layer 1') document.addItems(male, female, marriage, layer) # unlayered = { 'male': QPointF(-100, -50), 'maleDetails': QPointF(100, 100), 'female': QPointF(100, -50), 'femaleDetails': QPointF(-100,-200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(-25, 0), } layered = { 'male': QPointF(-200, -150), 'maleDetails': QPointF(-100, -100), 'female': QPointF(100, 50), 'femaleDetails': QPointF(100, 200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(25, -100), } # layered layer.setItemProperty(male.id, 'itemPos', layered['male']) layer.setItemProperty(male.detailsText.id, 'itemPos', layered['maleDetails']) layer.setItemProperty(female.id, 'itemPos', layered['female']) layer.setItemProperty(female.detailsText.id, 'itemPos', layered['femaleDetails']) layer.setItemProperty(marriage.detailsText.id, 'itemPos', layered['marriageDetails']) layer.setItemProperty(marriage.separationIndicator.id, 'itemPos', layered['marriageSep']) # unlayered male.setItemPos(unlayered['male'], undo=False) male.detailsText.setItemPos(unlayered['maleDetails'], undo=False) female.setItemPos(unlayered['female'], undo=False) female.detailsText.setItemPos(unlayered['femaleDetails'], undo=False) # marriage.setDivorced(True, undo=False) marriage.separationIndicator.setItemPos(unlayered['marriageSep'], undo=False) marriage.detailsText.setItemPos(unlayered['marriageDetails'], undo=False) assert len(document.items()) == 22 document.selectAll() qtbot.clickYesAfter(lambda: document.removeSelection()) assert len(document.items()) == 0 commands.stack().undo() assert len(document.items()) == 22 commands.stack().redo() assert len(document.items()) == 0
def test_layered_properties(qApp): """ Ensure correct layered prop updates for marriage+marriage-indicators. """ document = Document() male = Person(name='Male', kind='male') female = Person(name='Female', kind='female') marriage = Marriage(personA=male, personB=female) divorcedEvent = Event(parent=marriage, uniqueId='divorced', date=QDate(1900, 1, 1)) layer = Layer(name='Layer 1') document.addItems(male, female, marriage, layer) # unlayered = { 'male': QPointF(-100, -50), 'maleDetails': QPointF(100, 100), 'female': QPointF(100, -50), 'femaleDetails': QPointF(-100,-200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(-25, 0), } layered = { 'male': QPointF(-200, -150), 'maleDetails': QPointF(-100, -100), 'female': QPointF(100, 50), 'femaleDetails': QPointF(100, 200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(25, -100), } # layered layer.setItemProperty(male.id, 'itemPos', layered['male']) layer.setItemProperty(male.detailsText.id, 'itemPos', layered['maleDetails']) layer.setItemProperty(female.id, 'itemPos', layered['female']) layer.setItemProperty(female.detailsText.id, 'itemPos', layered['femaleDetails']) layer.setItemProperty(marriage.detailsText.id, 'itemPos', layered['marriageDetails']) layer.setItemProperty(marriage.separationIndicator.id, 'itemPos', layered['marriageSep']) # unlayered male.setItemPos(unlayered['male'], undo=False) male.detailsText.setItemPos(unlayered['maleDetails'], undo=False) female.setItemPos(unlayered['female'], undo=False) female.detailsText.setItemPos(unlayered['femaleDetails'], undo=False) # marriage.setDivorced(True, undo=False) marriage.separationIndicator.setItemPos(unlayered['marriageSep'], undo=False) marriage.detailsText.setItemPos(unlayered['marriageDetails'], undo=False) assert male.pos() == unlayered['male'] assert male.detailsText.pos() == unlayered['maleDetails'] assert female.pos() == unlayered['female'] assert female.detailsText.pos() == unlayered['femaleDetails'] assert marriage.detailsText.pos() == unlayered['marriageDetails'] assert marriage.separationIndicator.pos() == unlayered['marriageSep'] layer.setActive(True) assert male.pos() == layered['male'] assert male.detailsText.pos() == layered['maleDetails'] assert female.pos() == layered['female'] assert female.detailsText.pos() == layered['femaleDetails'] assert marriage.detailsText.pos() == layered['marriageDetails'] assert marriage.separationIndicator.pos() == layered['marriageSep'] layer.setActive(False) assert male.pos() == unlayered['male'] assert male.detailsText.pos() == unlayered['maleDetails'] assert female.pos() == unlayered['female'] assert female.detailsText.pos() == unlayered['femaleDetails'] assert marriage.detailsText.pos() == unlayered['marriageDetails'] assert marriage.separationIndicator.pos() == unlayered['marriageSep'] layer.resetItemProperty(male.prop('itemPos')) layer.resetItemProperty(male.detailsText.prop('itemPos')) layer.resetItemProperty(female.prop('itemPos')) layer.resetItemProperty(female.detailsText.prop('itemPos')) layer.resetItemProperty(marriage.detailsText.prop('itemPos')) layer.resetItemProperty(marriage.separationIndicator.prop('itemPos')) layer.setActive(True) assert male.pos() == unlayered['male'] assert male.detailsText.pos() == unlayered['maleDetails'] assert female.pos() == unlayered['female'] assert female.detailsText.pos() == unlayered['femaleDetails'] assert marriage.detailsText.pos() == unlayered['marriageDetails'] assert marriage.separationIndicator.pos() == unlayered['marriageSep']