Skip to content

Commit

Permalink
Test unexpected exceptions in update hooks aren't suppressed.
Browse files Browse the repository at this point in the history
Related to #218 / #96.
  • Loading branch information
lemon24 committed Sep 10, 2022
1 parent 229392f commit f81aaee
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions tests/test_reader_hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime

import pytest
from fakeparser import FailingParser
from fakeparser import NotModifiedParser
from fakeparser import Parser
Expand Down Expand Up @@ -45,8 +46,6 @@ def second_plugin(r, e, s):
]
assert set(e.id for e in reader.get_entries()) == {'1, 1', '1, 2'}

# TODO: What is the expected behavior if a plugin raises an exception?


def test_after_entry_update_hooks_add_entry(reader):
reader.add_feed('1')
Expand Down Expand Up @@ -157,8 +156,6 @@ def second_plugin(r, f):
(second_plugin, one.url),
]

# TODO: What is the expected behavior if a plugin raises an exception?


def test_feeds_update_hooks(reader):
reader._parser = parser = Parser()
Expand Down Expand Up @@ -235,3 +232,41 @@ def after_feeds_plugin(r):


# TODO: test relative order of different hooks


HOOK_NAMES = """
after_entry_update_hooks
before_feed_update_hooks
after_feed_update_hooks
before_feeds_update_hooks
after_feeds_update_hooks
""".split()


@pytest.mark.parametrize('hook_name', HOOK_NAMES)
def test_update_hook_unepected_exception(reader, call_update_method, hook_name):
if call_update_method.__name__ == 'call_update_feed' and '_feeds_' in hook_name:
pytest.skip("does not apply")

reader._parser = parser = Parser()
for feed_id in 1, 2, 3:
reader.add_feed(parser.feed(feed_id))
parser.entry(2, 1)

def hook(reader, obj=None, *_):
if '_entry_' in hook_name:
feed_url = obj.feed_url
elif '_feed_' in hook_name:
feed_url = obj
elif '_feeds_' in hook_name:
feed_url = None
else:
assert False, hook_name
if not feed_url or feed_url == '2':
raise Exception('error')

getattr(reader, hook_name).append(hook)

with pytest.raises(Exception) as excinfo:
call_update_method(reader, '2')
assert excinfo.value.args[0] == 'error'

0 comments on commit f81aaee

Please sign in to comment.