def test_remove_tag_undo_redo(filled_database): foo = Tag('foo') foo.id = 1 fourth_entry = filled_database.get_entry_by_id(4) assert foo in fourth_entry.tags filled_database.remove_tag(fourth_entry, 'foo') assert foo not in fourth_entry.tags assert foo in filled_database.tags filled_database.undo() assert foo in fourth_entry.tags assert foo in filled_database.tags filled_database.redo() assert foo not in fourth_entry.tags assert foo in filled_database.tags eighth_entry = filled_database.get_entry_by_id(8) filled_database.remove_tag(eighth_entry, 'foo') assert foo not in eighth_entry.tags assert foo not in filled_database.tags filled_database.undo() assert foo not in fourth_entry.tags assert foo in eighth_entry.tags assert foo in filled_database.tags filled_database.redo() assert foo not in eighth_entry.tags assert foo not in filled_database.tags
def test_getitem_exceeding_range(filled_database): entries = filled_database[7:1000] foo = Tag("foo") foo.id = 1 bar = Tag("bar") bar.id = 2 assert entries == [DatabaseEntry(id=8, tags=[foo]), DatabaseEntry(id=9), DatabaseEntry(id=10, tags=[bar])]
def test_get_existing_tag(database): entry = DatabaseEntry() database.tag(entry, 'tag') database.add(entry) expected_tag = Tag('tag') expected_tag.id = 1 assert database.get_tag('tag') == expected_tag
def test_getitem_negative_indices_slice(filled_database): entries = filled_database[-2:-8:-2] bar = Tag('bar') bar.id = 2 assert entries == [ DatabaseEntry(id=9), DatabaseEntry(id=7), DatabaseEntry(id=5, tags=[bar])]
def test_remove_many_entries(filled_database): bar = Tag("bar") bar.id = 2 # required to check if `remove_many` adds any entries to undo-history filled_database.clear_histories() filled_database.remove_many(filled_database[:8]) assert len(filled_database) == 2 assert list(filled_database) == [DatabaseEntry(id=9), DatabaseEntry(id=10, tags=[bar])] filled_database.undo() assert len(filled_database) == 10 with pytest.raises(EmptyCommandStackError): filled_database.undo()
def test_query(filled_database): foo = Tag('foo') foo.id = 1 bar = Tag('bar') bar.id = 2 entries = filled_database.query( attrs.Tag('foo') | attrs.Tag('bar'), sortby='id') assert len(entries) == 4 assert entries == [ DatabaseEntry(id=4, tags=[foo]), DatabaseEntry(id=5, tags=[bar]), DatabaseEntry(id=8, tags=[foo]), DatabaseEntry(id=10, tags=[bar])]
def test_query(filled_database): foo = Tag("foo") foo.id = 1 bar = Tag("bar") bar.id = 2 entries = filled_database.query(attrs.Tag("foo") | attrs.Tag("bar"), sortby="id") assert len(entries) == 4 assert entries == [ DatabaseEntry(id=4, tags=[foo]), DatabaseEntry(id=5, tags=[bar]), DatabaseEntry(id=8, tags=[foo]), DatabaseEntry(id=10, tags=[bar]), ]
def test_remove_tag(filled_database): foo = Tag("foo") foo.id = 1 fourth_entry = filled_database.get_entry_by_id(4) assert foo in fourth_entry.tags eighth_entry = filled_database.get_entry_by_id(8) assert foo in eighth_entry.tags filled_database.remove_tag(fourth_entry, "foo") assert foo not in fourth_entry.tags assert foo in filled_database.tags filled_database.remove_tag(eighth_entry, "foo") assert foo not in eighth_entry.tags assert foo not in filled_database.tags
def test_getitem_custom(filled_database): entries = filled_database[1:5:2] foo = Tag('foo') foo.id = 1 assert entries == [ DatabaseEntry(id=2), DatabaseEntry(id=4, tags=[foo])]
def test_tag_hashability(): assert isinstance(Tag(''), Hashable)
def test_tag_inequality(): assert Tag('abc') != Tag('xyz') assert not (Tag('abc') != Tag('abc'))
def test_getitem_custom(filled_database): entries = filled_database[1:5:2] foo = Tag('foo') foo.id = 1 assert entries == [DatabaseEntry(id=2), DatabaseEntry(id=4, tags=[foo])]
def test_remove_nonexisting_tag(session): cmd = RemoveTag(session, DatabaseEntry(), Tag('tag')) with pytest.raises(NonRemovableTagError): cmd()