From 7e942c915e63d04a090d73258ce60a75874f89d7 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Mon, 17 Oct 2016 18:07:18 -0700 Subject: [PATCH] Adding tests. --- rtv/content.py | 12 ++++++------ tests/test_content.py | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/rtv/content.py b/rtv/content.py index 8fb199c..5609716 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -475,12 +475,12 @@ class SubredditContent(Content): elif len(parts) == 2: resource, resource_order = parts else: - raise InvalidSubreddit() + raise InvalidSubreddit('`{}` is an invalid format'.format(name)) if not resource: # Praw does not correctly handle empty strings # https://github.com/praw-dev/praw/issues/615 - raise InvalidSubreddit() + raise InvalidSubreddit('Subreddit cannot be empty') # If the order was explicitly passed in, it will take priority over # the order that was extracted from the name @@ -496,12 +496,12 @@ class SubredditContent(Content): period = None if order not in ['hot', 'top', 'rising', 'new', 'controversial', None]: - raise InvalidSubreddit('Invalid order "%s"' % order) + raise InvalidSubreddit('Invalid order `%s`' % order) if period not in ['all', 'day', 'hour', 'month', 'week', 'year', None]: - raise InvalidSubreddit('Invalid period "%s"' % period) + raise InvalidSubreddit('Invalid period `%s`' % period) if period and order not in ['top', 'controversial']: - raise InvalidSubreddit('"%s" order does not allow sorting by' - 'period' % order) + raise InvalidSubreddit('`%s` order does not allow sorting by' + ' period' % order) # On some objects, praw doesn't allow you to pass arguments for the # order and period. Instead you need to call special helper functions diff --git a/tests/test_content.py b/tests/test_content.py index 69d9627..523c826 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -344,7 +344,8 @@ def test_content_subreddit_from_name_invalid(prompt, reddit, terminal): with terminal.loader(): SubredditContent.from_name(reddit, prompt, terminal.loader) assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit) - + # Must always have an argument because it gets displayed + assert terminal.loader.exception.args[0] args, ids = SUBREDDIT_SEARCH_QUERIES.values(), list(SUBREDDIT_SEARCH_QUERIES) @pytest.mark.parametrize('prompt,query', args, ids=ids)