refactor: add Entry type that owns the tag syntax and drop the configurable schema
This commit is contained in:
parent
6fbd54c754
commit
921f06b4fa
4 changed files with 187 additions and 174 deletions
35
tests/test_entry.py
Normal file
35
tests/test_entry.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from orvanitag.entry import Entry
|
||||
|
||||
|
||||
def test_parse_and_format():
|
||||
entry = Entry.parse(['#lofi,', '+album', 'first', '#lofi', '@home-office', 'C', '+', 'take'])
|
||||
assert entry == Entry(['album'], ['home-office'], ['lofi'], 'first C + take')
|
||||
assert str(entry) == '+album @home-office #lofi first C + take'
|
||||
assert Entry.parse(str(entry).split()) == entry
|
||||
|
||||
|
||||
def test_empty_entry_is_false():
|
||||
assert not Entry.parse([])
|
||||
assert not Entry.parse(['', ' '])
|
||||
assert Entry.parse(['note'])
|
||||
|
||||
|
||||
def test_dict_round_trip_and_tolerance():
|
||||
entry = Entry(['album'], [], ['lofi'], 'a note')
|
||||
assert entry.to_dict() == {'projects': ['album'], 'contexts': [], 'tags': ['lofi'], 'note': 'a note'}
|
||||
assert Entry.from_dict(entry.to_dict()) == entry
|
||||
assert Entry.from_dict({'tags': 'single', 'projects': [2023]}) == Entry(['2023'], [], ['single'])
|
||||
|
||||
|
||||
def test_merge_remove_without():
|
||||
entry = Entry(tags=['lofi'], note='old')
|
||||
entry.merge(Entry(tags=['lofi', 'snare'], note='new'))
|
||||
assert entry == Entry(tags=['lofi', 'snare'], note='new')
|
||||
entry.merge(Entry(tags=['x']))
|
||||
assert entry.note == 'new'
|
||||
|
||||
assert entry.remove(Entry(tags=['snare', 'missing']))
|
||||
assert not entry.remove(Entry(tags=['missing']))
|
||||
assert entry.tags == ['lofi', 'x']
|
||||
|
||||
assert entry.without(Entry(tags=['lofi'], note='new')) == Entry(tags=['x'])
|
||||
Loading…
Add table
Add a link
Reference in a new issue