class NomListItem(BaseModel):
- label: Optional[int] = -1
+ label: Optional[int] = None
@abstractmethod
def __hash__(self):
else:
nlitems = [self.nlitem().from_dict(item.to_dict()) for item in items]
super().__init__(nlitems)
-
- # Number items and persist via label attribute
- for i, nlitem in enumerate(self, start=1):
- if not nlitem.label:
- nlitem.__setattr__('label',i)
+ self.update_labels()
@abstractclassmethod
def nlitem(cls):
msg = "You must specify what type of NomListItem the list contains."
raise NotImplementedError(msg)
+ def update_labels(self, force=False):
+ for i, nlitem in enumerate(self, start=1):
+ if not nlitem.label or force:
+ nlitem.__setattr__('label',i)
+
def __add__(self, other):
- return self.__class__(self.union(other))
+ sum_ = self.__class__(self.union(other))
+ sum_.update_labels(force=True)
+ return sum_
def select(self, predicate: Predicate):
items = {item for item in self if predicate(item)}
elist = EntryList.from_csv(ENTRY_LIST)
elist.to_stdout()
elif args.command == "feed" and args.feed_command == "update":
+ feedlist.update_labels()
feedlist.fetch_feeds(FEED_CACHE)
elif args.command == "feed" and args.feed_command == "show":
feedlist.to_stdout()
+++ /dev/null
-# Note: The base module isn't meant to be used directly, but instead is meant
-# to be subclassed from. In general, it makes more sense to test the subclasses
-# than it does to test the base class.
-
-import pytest
-from pathlib import Path
-from nom.base import NomList, NomListItem
-
-
-
-def test_from_csv_error():
- class DummyList(NomList):
- pass
- path = Path(__file__).parent / "data" / "entry_single.csv"
- with pytest.raises(NotImplementedError):
- nlist=DummyList.from_csv(path, NomListItem)
assert len(sum_) == len(elist_multi) + len(elist_single)
assert isinstance(sum_,EntryList)
+def test_elist_addition_unique_labels(elist_multi,elist_single):
+ sum_ = elist_multi + elist_single
+ labels = {item.label for item in sum_}
+ assert len(labels) == len(sum_)
+
def test_elist_select(elist_multi):
viewed = elist_multi.select(lambda e: e.viewed)
assert len(viewed) < len(elist_multi)