Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: tests/test_web_source.py

Issue 29465720: Issue 4970 - Document the library API of python-abp (Closed)
Patch Set: Rebase to match the new master and retouche the docstrings. Created Oct. 24, 2017, 4:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 from __future__ import unicode_literals 16 from __future__ import unicode_literals
17 17
18 import pytest 18 import pytest
19 import mock 19 import mock
20 20
21 try: 21 try:
22 from StringIO import StringIO 22 from StringIO import StringIO
23 from urllib2 import HTTPError 23 from urllib2 import HTTPError
24 except ImportError: # The modules were renamed/moved in Python 3. 24 except ImportError: # The modules were renamed/moved in Python 3.
25 from io import BytesIO as StringIO 25 from io import BytesIO as StringIO
26 from urllib.error import HTTPError 26 from urllib.error import HTTPError
27 27
28 from abp.filters import WebSource, NotFound 28 from abp.filters.sources import WebSource, NotFound
29 29
30 30
31 @pytest.fixture 31 @pytest.fixture
32 def web_mock(request): 32 def web_mock(request):
33 """Replace urlopen with our test implementation.""" 33 """Replace urlopen with our test implementation."""
34 patcher = mock.patch('abp.filters.sources.urlopen') 34 patcher = mock.patch('abp.filters.sources.urlopen')
35 ret = patcher.start() 35 ret = patcher.start()
36 request.addfinalizer(patcher.stop) 36 request.addfinalizer(patcher.stop)
37 return ret 37 return ret
38 38
(...skipping 23 matching lines...) Expand all
62 web_mock.return_value = response_mock('utf-8', b'\xc3\xbc') 62 web_mock.return_value = response_mock('utf-8', b'\xc3\xbc')
63 assert list(http_source.get('//foo/bar.txt')) == ['\xfc'] 63 assert list(http_source.get('//foo/bar.txt')) == ['\xfc']
64 web_mock.return_value = response_mock(None, b'\xc3\xbc') 64 web_mock.return_value = response_mock(None, b'\xc3\xbc')
65 assert list(http_source.get('//foo/bar.txt')) == ['\xfc'] 65 assert list(http_source.get('//foo/bar.txt')) == ['\xfc']
66 66
67 67
68 def test_404(web_mock, http_source): 68 def test_404(web_mock, http_source):
69 web_mock.side_effect = HTTPError('', 404, 'Not found', [], StringIO(b'')) 69 web_mock.side_effect = HTTPError('', 404, 'Not found', [], StringIO(b''))
70 with pytest.raises(NotFound): 70 with pytest.raises(NotFound):
71 list(http_source.get('//foo/bar.txt')) 71 list(http_source.get('//foo/bar.txt'))
OLDNEW
« tests/test_render_script.py ('K') | « tests/test_render_script.py ('k') | tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld