Skip to content

Commit

Permalink
Move entry filtering tests to test_reader_filter.py. #328
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Dec 8, 2023
1 parent ae38154 commit 87bbf24
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 146 deletions.
146 changes: 0 additions & 146 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,152 +1594,6 @@ def test_direct_instantiation():
Reader('storage', 'search', 'parser', DEFAULT_RESERVED_NAME_SCHEME)


# BEGIN entry filtering tests

# We're testing both get_entries() and search_entries() here,
# since filtering works the same for them.


# TODO: there should probably be a way to get this from the fakeparser
ALL_IDS = {
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(2, 1),
}


@pytest.mark.parametrize(
'kwargs, expected',
[
(dict(), ALL_IDS),
(dict(read=None), ALL_IDS),
(dict(read=True), {(1, 2)}),
(dict(read=False), ALL_IDS - {(1, 2)}),
(dict(important=None), ALL_IDS),
(dict(important=True), {(1, 3)}),
(dict(important=False), ALL_IDS - {(1, 3)}),
(dict(has_enclosures=None), ALL_IDS),
(dict(has_enclosures=True), {(1, 4)}),
(dict(has_enclosures=False), ALL_IDS - {(1, 4)}),
(dict(feed=None), ALL_IDS),
(dict(feed='1'), {(1, 1), (1, 2), (1, 3), (1, 4)}),
(dict(feed='2'), {(2, 1)}),
(dict(feed=Feed('2')), {(2, 1)}),
(dict(feed='inexistent'), set()),
(dict(entry=None), ALL_IDS),
(dict(entry=('1', '1, 1')), {(1, 1)}),
(dict(entry=('1', '1, 2')), {(1, 2)}),
(
dict(
entry=Entry(
'1, 2',
datetime(2010, 2, 1),
feed=Feed('1'),
)
),
{(1, 2)},
),
(dict(entry=('inexistent', 'also-inexistent')), set()),
],
)
def test_entries_filtering(reader, get_entries, kwargs, expected):
parser = Parser()
reader._parser = parser

one = parser.feed(1, datetime(2010, 1, 1))
one_one = parser.entry(1, 1, datetime(2010, 1, 1))
one_two = parser.entry(1, 2, datetime(2010, 2, 1)) # read
one_three = parser.entry(1, 3, datetime(2010, 2, 1)) # important
one_four = parser.entry(
1, 4, datetime(2010, 2, 1), enclosures=[Enclosure('http://e2')]
)
two = parser.feed(2, datetime(2010, 1, 1))
two_one = parser.entry(2, 1, datetime(2010, 2, 1))

reader.add_feed(one.url)
reader.add_feed(two.url)
reader.update_feeds()
get_entries.after_update(reader)

reader.mark_entry_as_read((one.url, one_two.id))
reader.mark_entry_as_important((one.url, one_three.id))

assert {eval(e.id) for e in get_entries(reader, **kwargs)} == expected

# TODO: how do we test the combinations between arguments?


@pytest.mark.parametrize(
'kwargs',
[
dict(read=object()),
dict(important=object()),
dict(has_enclosures=object()),
dict(feed=object()),
dict(entry=object()),
],
)
def test_entries_filtering_error(reader, get_entries, kwargs):
parser = Parser()
reader._parser = parser

one = parser.feed(1, datetime(2010, 1, 1))
one_one = parser.entry(1, 1, datetime(2010, 1, 1))

reader.add_feed(one.url)
reader.update_feeds()
get_entries.after_update(reader)

with pytest.raises(ValueError):
list(get_entries(reader, **kwargs))


@pytest.mark.parametrize('modified', [None, datetime(2010, 1, 1)])
def test_entries_filtering_important(reader, subtests, get_entries, modified):
reader._parser = parser = Parser()

reader.add_feed(parser.feed(1))
one = parser.entry(1, 1)
two = parser.entry(1, 2)
reader.add_feed(parser.feed(2))
three = parser.entry(2, 3)

reader.update_feeds()
reader.update_search()

reader.set_entry_important(one, None, modified)
reader.set_entry_important(two, True, modified)
reader.set_entry_important(three, False, modified)

data = {
'istrue': {'1, 2'},
True: {'1, 2'},
'isfalse': {'2, 3'},
'notset': {'1, 1'},
'nottrue': {'1, 1', '2, 3'},
False: {'1, 1', '2, 3'},
'notfalse': {'1, 1', '1, 2'},
'isset': {'1, 2', '2, 3'},
'any': {'1, 1', '1, 2', '2, 3'},
None: {'1, 1', '1, 2', '2, 3'},
} # fmt: skip

for important, expected in data.items():
with subtests.test(important=important):
actual = {e.id for e in get_entries(reader, important=important)}
assert actual == expected
assert get_entries.counts(reader, important=important).total == len(
expected
)


# TODO: ideally, systematize all filtering tests?

# END entry filtering tests


@pytest.mark.parametrize(
'kwargs, feed_root',
[
Expand Down
144 changes: 144 additions & 0 deletions tests/test_reader_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from utils import rename_argument
from utils import utc_datetime as datetime

from reader import Enclosure
from reader import Entry
from reader import Feed
from reader import make_reader


Expand Down Expand Up @@ -125,3 +128,144 @@ def test_entries_by_entry_tags(reader, get_entries, tags, expected):


# END tag filtering tests


# BEGIN entry filtering tests

ALL_IDS = {
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(2, 1),
}


@pytest.mark.parametrize(
'kwargs, expected',
[
(dict(), ALL_IDS),
(dict(read=None), ALL_IDS),
(dict(read=True), {(1, 2)}),
(dict(read=False), ALL_IDS - {(1, 2)}),
(dict(important=None), ALL_IDS),
(dict(important=True), {(1, 3)}),
(dict(important=False), ALL_IDS - {(1, 3)}),
(dict(has_enclosures=None), ALL_IDS),
(dict(has_enclosures=True), {(1, 4)}),
(dict(has_enclosures=False), ALL_IDS - {(1, 4)}),
(dict(feed=None), ALL_IDS),
(dict(feed='1'), {(1, 1), (1, 2), (1, 3), (1, 4)}),
(dict(feed='2'), {(2, 1)}),
(dict(feed=Feed('2')), {(2, 1)}),
(dict(feed='inexistent'), set()),
(dict(entry=None), ALL_IDS),
(dict(entry=('1', '1, 1')), {(1, 1)}),
(dict(entry=('1', '1, 2')), {(1, 2)}),
(
dict(
entry=Entry(
'1, 2',
datetime(2010, 2, 1),
feed=Feed('1'),
)
),
{(1, 2)},
),
(dict(entry=('inexistent', 'also-inexistent')), set()),
],
)
def test_entries(reader, get_entries, kwargs, expected):
parser = Parser()
reader._parser = parser

one = parser.feed(1, datetime(2010, 1, 1))
one_one = parser.entry(1, 1, datetime(2010, 1, 1))
one_two = parser.entry(1, 2, datetime(2010, 2, 1)) # read
one_three = parser.entry(1, 3, datetime(2010, 2, 1)) # important
one_four = parser.entry(
1, 4, datetime(2010, 2, 1), enclosures=[Enclosure('http://e2')]
)
two = parser.feed(2, datetime(2010, 1, 1))
two_one = parser.entry(2, 1, datetime(2010, 2, 1))

reader.add_feed(one.url)
reader.add_feed(two.url)
reader.update_feeds()
get_entries.after_update(reader)

reader.mark_entry_as_read((one.url, one_two.id))
reader.mark_entry_as_important((one.url, one_three.id))

assert {eval(e.id) for e in get_entries(reader, **kwargs)} == expected

# TODO: how do we test the combinations between arguments?


@pytest.mark.parametrize(
'kwargs',
[
dict(read=object()),
dict(important=object()),
dict(has_enclosures=object()),
dict(feed=object()),
dict(entry=object()),
],
)
def test_entries_error(reader, get_entries, kwargs):
parser = Parser()
reader._parser = parser

one = parser.feed(1, datetime(2010, 1, 1))
one_one = parser.entry(1, 1, datetime(2010, 1, 1))

reader.add_feed(one.url)
reader.update_feeds()
get_entries.after_update(reader)

with pytest.raises(ValueError):
list(get_entries(reader, **kwargs))


@pytest.mark.parametrize('modified', [None, datetime(2010, 1, 1)])
def test_entries_important(reader, subtests, get_entries, modified):
reader._parser = parser = Parser()

reader.add_feed(parser.feed(1))
one = parser.entry(1, 1)
two = parser.entry(1, 2)
reader.add_feed(parser.feed(2))
three = parser.entry(2, 3)

reader.update_feeds()
reader.update_search()

reader.set_entry_important(one, None, modified)
reader.set_entry_important(two, True, modified)
reader.set_entry_important(three, False, modified)

data = {
'istrue': {'1, 2'},
True: {'1, 2'},
'isfalse': {'2, 3'},
'notset': {'1, 1'},
'nottrue': {'1, 1', '2, 3'},
False: {'1, 1', '2, 3'},
'notfalse': {'1, 1', '1, 2'},
'isset': {'1, 2', '2, 3'},
'any': {'1, 1', '1, 2', '2, 3'},
None: {'1, 1', '1, 2', '2, 3'},
} # fmt: skip

for important, expected in data.items():
with subtests.test(important=important):
actual = {e.id for e in get_entries(reader, important=important)}
assert actual == expected
assert get_entries.counts(reader, important=important).total == len(
expected
)


# TODO: ideally, systematize all filtering tests?

# END entry filtering tests

0 comments on commit 87bbf24

Please sign in to comment.