diff --git a/CHANGES.rst b/CHANGES.rst index 68705031..40fac02e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,13 @@ Version 3.14 Unreleased +* Add :attr:`~EntryCounts.unimportant` attribute to + :class:`EntryCounts` and :class:`EntrySearchCounts`. + Thanks to `chenthur`_ for the pull request. + (:issue:`283`) + +.. _chenthur: https://github.com/chenthur + Version 3.13 ------------ diff --git a/src/reader/_app/__init__.py b/src/reader/_app/__init__.py index 6b20f401..9e72cf11 100644 --- a/src/reader/_app/__init__.py +++ b/src/reader/_app/__init__.py @@ -418,7 +418,7 @@ def add_entry(): FEED_SORT_NATIVE = {'title', 'added'} FEED_SORT_FANCY = { 'important': lambda counts: counts.important, - 'unimportant':lambda counts: counts.unimportant, + 'unimportant': lambda counts: counts.unimportant, 'unread': lambda counts: counts.total - counts.read, # TODO: if we keep these average intervals, properties for them might be nice too 'avg1m': lambda counts: counts.averages[0], diff --git a/src/reader/types.py b/src/reader/types.py index 361bfe5d..b7a9d121 100644 --- a/src/reader/types.py +++ b/src/reader/types.py @@ -899,6 +899,9 @@ class EntryCounts(_namedtuple_compat): important: int | None = None #: Number of unimportant entries. + #: + #: .. versionadded:: 3.14 + #: unimportant: int | None = None #: Number of entries that have enclosures. @@ -939,6 +942,9 @@ class EntrySearchCounts(_namedtuple_compat): important: int | None = None #: Number of unimportant entries. + #: + #: .. versionadded:: 3.14 + #: unimportant: int | None = None #: Number of entries that have enclosures. diff --git a/tests/test_reader_counts.py b/tests/test_reader_counts.py index 8fb05144..e0a14665 100644 --- a/tests/test_reader_counts.py +++ b/tests/test_reader_counts.py @@ -12,6 +12,11 @@ from utils import utc_datetime as datetime +def kwargs_ids(val): + if isinstance(val, dict): + return ','.join(f'{k}={v!r}' for k, v in val.items()) + + KWARGS_AND_EXPECTED_FEED_COUNTS = [ (dict(), FeedCounts(3, broken=1, updates_enabled=2)), (dict(feed='1'), FeedCounts(1, 0, 1)), @@ -46,7 +51,9 @@ def reader_feed_counts(): yield reader -@pytest.mark.parametrize('kwargs, expected', KWARGS_AND_EXPECTED_FEED_COUNTS) +@pytest.mark.parametrize( + 'kwargs, expected', KWARGS_AND_EXPECTED_FEED_COUNTS, ids=kwargs_ids +) @rename_argument('reader', 'reader_feed_counts') def test_feed(reader, kwargs, expected): assert reader.get_feed_counts(**kwargs) == expected @@ -66,7 +73,7 @@ def entries_per_day(month, quarter, year): 9, read=2, important=4, - unimportant=0, + unimportant=1, has_enclosures=8, averages=entries_per_day(2, 3, 7), ), @@ -88,7 +95,7 @@ def entries_per_day(month, quarter, year): 8, read=2, important=4, - unimportant=0, + unimportant=1, has_enclosures=8, averages=entries_per_day(2, 3, 6), ), @@ -154,7 +161,7 @@ def entries_per_day(month, quarter, year): 7, read=0, important=2, - unimportant=0, + unimportant=1, has_enclosures=6, averages=entries_per_day(1, 2, 6), ), @@ -176,18 +183,29 @@ def entries_per_day(month, quarter, year): 5, read=0, important=0, - unimportant=0, + unimportant=1, has_enclosures=4, averages=entries_per_day(1, 2, 5), ), ), + ( + dict(important='isfalse'), + EntryCounts( + 1, + read=0, + important=0, + unimportant=1, + has_enclosures=1, + averages=entries_per_day(1, 1, 1), + ), + ), ( dict(has_enclosures=True), EntryCounts( 8, read=2, important=4, - unimportant=0, + unimportant=1, has_enclosures=8, averages=entries_per_day(2, 3, 6), ), @@ -219,6 +237,9 @@ def entries_per_day(month, quarter, year): @pytest.fixture(scope='module') def reader_entry_counts(): + # TODO: testing everything all at once like this is kinda brittle + # https://github.com/lemon24/reader/pull/342#discussion_r1649614984 + with make_reader(':memory:') as reader: reader._parser = parser = Parser() @@ -253,7 +274,7 @@ def reader_entry_counts(): published=datetime(2011, 8, 15), ), parser.entry(2, 6, datetime(2011, 11, 15), enclosures=[]), - # gets updated / added 2011-12-16 (_now() during update_feeds()) + # unimportant, gets updated / added 2011-12-16 (_now() during update_feeds()) parser.entry(2, 7, None, enclosures=[]), # important, read parser.entry(2, 8, datetime(2011, 12, 15), enclosures=[]), @@ -283,13 +304,16 @@ def reader_entry_counts(): for entry in two_entries[:3]: reader.mark_entry_as_important(entry) reader.mark_entry_as_important(two_entries[-1]) + reader.mark_entry_as_unimportant(two_entries[-2]) reader._now = lambda: datetime(2011, 12, 31) yield reader -@pytest.mark.parametrize('kwargs, expected', KWARGS_AND_EXPECTED_ENTRY_COUNTS) +@pytest.mark.parametrize( + 'kwargs, expected', KWARGS_AND_EXPECTED_ENTRY_COUNTS, ids=kwargs_ids +) @rename_argument('reader', 'reader_entry_counts') def test_entry(reader, get_entry_counts, kwargs, expected): actual = get_entry_counts(reader, **kwargs) diff --git a/tests/test_reader_search.py b/tests/test_reader_search.py index c1544478..102e2e60 100644 --- a/tests/test_reader_search.py +++ b/tests/test_reader_search.py @@ -611,7 +611,7 @@ def test_search_entries_basic(reader, sort): }, ) ] - assert search_counts('one') == EntrySearchCounts(1, 0, 0, 0,0,(0, 0, 0)) + assert search_counts('one') == EntrySearchCounts(1, 0, 0, 0, 0, (0, 0, 0)) assert list(search('two')) == [ EntrySearchResult( feed.url, @@ -684,7 +684,7 @@ def test_search_entries_basic(reader, sort): ), ] } - assert search_counts('summary') == EntrySearchCounts(3, 0, 0, 0, 0,(0, 0, 0)) + assert search_counts('summary') == EntrySearchCounts(3, 0, 0, 0, 0, (0, 0, 0)) # search_entries() filtering is tested in test_reader.py::test_entries_filtering{,_error}