Added logging, fixed tests
This commit is contained in:
@@ -2,9 +2,7 @@ beautifulsoup4==4.5.1
|
||||
decorator==4.0.10
|
||||
kitchen==1.2.4
|
||||
mailcap-fix==0.1.3
|
||||
praw==3.6.0
|
||||
requests==2.11.0
|
||||
six==1.10.0
|
||||
update-checker==0.11
|
||||
pytest
|
||||
vcrpy
|
||||
pytest==3.0.7
|
||||
vcrpy==1.10.5
|
||||
@@ -12,6 +12,7 @@ import six
|
||||
import requests
|
||||
|
||||
from . import docs
|
||||
from . import packages
|
||||
from .packages import praw
|
||||
from .config import Config, copy_default_config, copy_default_mailcap
|
||||
from .oauth import OAuthHelper
|
||||
@@ -111,6 +112,14 @@ def main():
|
||||
warnings.warn(text)
|
||||
config['ascii'] = True
|
||||
|
||||
# Check the praw version
|
||||
if packages.__praw_bundled__:
|
||||
_logger.info('Using packaged PRAW distribution')
|
||||
_logger.info('PRAW commit hash %s' % packages.__praw_hash__)
|
||||
else:
|
||||
_logger.info('Packaged PRAW not found, falling back to system distribution')
|
||||
_logger.info('PRAW version %s' % praw.__version__)
|
||||
|
||||
# Construct the reddit user agent
|
||||
user_agent = docs.AGENT.format(version=__version__)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
This stub allows the end-user to fallback to their system installation of praw
|
||||
if the bundled package missing. This technique was inspired by the requests
|
||||
library and how it handles dependencies.
|
||||
This stub allows the the package to fallback to their system installation of
|
||||
praw if the bundled package is missing. This technique was inspired by the
|
||||
requests library and how it handles dependencies.
|
||||
|
||||
Reference:
|
||||
https://github.com/kennethreitz/requests/blob/master/requests/packages/__init__.py
|
||||
@@ -11,6 +11,7 @@ import sys
|
||||
|
||||
|
||||
__praw_hash__ = 'a632ff005fc09e74a8d3d276adc10aa92638962c'
|
||||
__praw_bundled__ = True
|
||||
|
||||
|
||||
try:
|
||||
@@ -21,3 +22,4 @@ except ImportError:
|
||||
msg = 'Invalid PRAW version {0}, exiting'.format(praw.__version__)
|
||||
raise RuntimeError(msg)
|
||||
sys.modules['%s.praw' % __name__] = praw
|
||||
__praw_bundled__ = False
|
||||
|
||||
@@ -174,7 +174,7 @@ def reddit(vcr, request):
|
||||
os.remove(filename)
|
||||
|
||||
with vcr.use_cassette(cassette_name):
|
||||
with patch('praw.Reddit.get_access_information'):
|
||||
with patch('rtv.packages.praw.Reddit.get_access_information'):
|
||||
reddit = praw.Reddit(user_agent='rtv test suite',
|
||||
decode_html_entities=False,
|
||||
disable_update_check=True)
|
||||
|
||||
8
tests/test_packages.py
Normal file
8
tests/test_packages.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from rtv import packages
|
||||
|
||||
|
||||
def test_praw3_package():
|
||||
# Sanity check that the package was installed
|
||||
assert packages.praw
|
||||
assert len(packages.__praw_hash__) == 40
|
||||
assert packages.__praw_bundled__ is True
|
||||
@@ -230,9 +230,9 @@ def test_submission_vote(submission_page, refresh_token):
|
||||
submission_page.oauth.authorize()
|
||||
|
||||
# Test voting on the submission
|
||||
with mock.patch('praw.objects.Submission.upvote') as upvote, \
|
||||
mock.patch('praw.objects.Submission.downvote') as downvote, \
|
||||
mock.patch('praw.objects.Submission.clear_vote') as clear_vote:
|
||||
with mock.patch('rtv.packages.praw.objects.Submission.upvote') as upvote, \
|
||||
mock.patch('rtv.packages.praw.objects.Submission.downvote') as downvote, \
|
||||
mock.patch('rtv.packages.praw.objects.Submission.clear_vote') as clear_vote:
|
||||
|
||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
||||
|
||||
@@ -279,8 +279,8 @@ def test_submission_save(submission_page, refresh_token):
|
||||
submission_page.oauth.authorize()
|
||||
|
||||
# Test save on the submission
|
||||
with mock.patch('praw.objects.Submission.save') as save, \
|
||||
mock.patch('praw.objects.Submission.unsave') as unsave:
|
||||
with mock.patch('rtv.packages.praw.objects.Submission.save') as save, \
|
||||
mock.patch('rtv.packages.praw.objects.Submission.unsave') as unsave:
|
||||
|
||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
||||
|
||||
@@ -311,8 +311,8 @@ def test_submission_comment_save(submission_page, terminal, refresh_token):
|
||||
submission_page.controller.trigger('j')
|
||||
|
||||
# Test save on the coment submission
|
||||
with mock.patch('praw.objects.Comment.save') as save, \
|
||||
mock.patch('praw.objects.Comment.unsave') as unsave:
|
||||
with mock.patch('rtv.packages.praw.objects.Comment.save') as save, \
|
||||
mock.patch('rtv.packages.praw.objects.Comment.unsave') as unsave:
|
||||
|
||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
||||
|
||||
@@ -339,8 +339,8 @@ def test_submission_comment(submission_page, terminal, refresh_token):
|
||||
submission_page.oauth.authorize()
|
||||
|
||||
# Leave a comment
|
||||
with mock.patch('praw.objects.Submission.add_comment') as add_comment, \
|
||||
mock.patch.object(terminal, 'open_editor') as open_editor, \
|
||||
with mock.patch('rtv.packages.praw.objects.Submission.add_comment') as add_comment, \
|
||||
mock.patch.object(terminal, 'open_editor') as open_editor, \
|
||||
mock.patch('time.sleep'):
|
||||
open_editor.return_value.__enter__.return_value = 'comment text'
|
||||
submission_page.controller.trigger('c')
|
||||
@@ -371,8 +371,8 @@ def test_submission_delete(submission_page, terminal, refresh_token):
|
||||
# Spoof the author and try to delete again
|
||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
||||
data['author'] = submission_page.reddit.user.name
|
||||
with mock.patch('praw.objects.Comment.delete') as delete, \
|
||||
mock.patch.object(terminal.stdscr, 'getch') as getch, \
|
||||
with mock.patch('rtv.packages.praw.objects.Comment.delete') as delete, \
|
||||
mock.patch.object(terminal.stdscr, 'getch') as getch, \
|
||||
mock.patch('time.sleep'):
|
||||
getch.return_value = ord('y')
|
||||
submission_page.controller.trigger('d')
|
||||
@@ -395,8 +395,8 @@ def test_submission_edit(submission_page, terminal, refresh_token):
|
||||
# Spoof the submission and try to edit again
|
||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
||||
data['author'] = submission_page.reddit.user.name
|
||||
with mock.patch('praw.objects.Submission.edit') as edit, \
|
||||
mock.patch.object(terminal, 'open_editor') as open_editor, \
|
||||
with mock.patch('rtv.packages.praw.objects.Submission.edit') as edit, \
|
||||
mock.patch.object(terminal, 'open_editor') as open_editor, \
|
||||
mock.patch('time.sleep'):
|
||||
open_editor.return_value.__enter__.return_value = 'submission text'
|
||||
|
||||
@@ -411,7 +411,7 @@ def test_submission_edit(submission_page, terminal, refresh_token):
|
||||
# Spoof the author and edit the comment
|
||||
data = submission_page.content.get(submission_page.nav.absolute_index)
|
||||
data['author'] = submission_page.reddit.user.name
|
||||
with mock.patch('praw.objects.Comment.edit') as edit, \
|
||||
with mock.patch('rtv.packages.praw.objects.Comment.edit') as edit, \
|
||||
mock.patch.object(terminal, 'open_editor') as open_editor, \
|
||||
mock.patch('time.sleep'):
|
||||
open_editor.return_value.__enter__.return_value = 'comment text'
|
||||
|
||||
@@ -30,7 +30,9 @@ def test_terminal_properties(terminal, config):
|
||||
assert isinstance(terminal.guilded[0], six.text_type)
|
||||
|
||||
terminal._display = None
|
||||
with mock.patch.dict('os.environ', {'DISPLAY': ''}):
|
||||
with mock.patch('rtv.terminal.sys') as sys, \
|
||||
mock.patch.dict('os.environ', {'DISPLAY': ''}):
|
||||
sys.platform = 'linux'
|
||||
assert terminal.display is False
|
||||
|
||||
terminal._display = None
|
||||
|
||||
Reference in New Issue
Block a user