Skip to content

Commit

Permalink
Additional tests + changelog for PR #342. #283
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Jun 22, 2024
1 parent c867823 commit 6e921d5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
2 changes: 1 addition & 1 deletion src/reader/_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 6 additions & 0 deletions src/reader/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
40 changes: 32 additions & 8 deletions tests/test_reader_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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
Expand All @@ -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),
),
Expand All @@ -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),
),
Expand Down Expand Up @@ -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),
),
Expand All @@ -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),
),
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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=[]),
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_reader_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 6e921d5

Please sign in to comment.