Left: | ||
Right: |
OLD | NEW |
---|---|
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 import pytest | 16 import pytest |
17 | 17 |
18 from abp.filters.sources import FSSource, NotFound | 18 from abp.filters.sources import FSSource, NotFound, WebSource |
19 | 19 |
20 | 20 |
21 @pytest.fixture | 21 @pytest.fixture |
22 def fssource_dir(tmpdir): | 22 def fssource_dir(tmpdir): |
23 tmpdir.mkdir('root') | 23 tmpdir.mkdir('root') |
24 not_in_source = tmpdir.join('not-in-source.txt') | 24 not_in_source = tmpdir.join('not-in-source.txt') |
25 not_in_source.write('! secret') | 25 not_in_source.write('! secret') |
26 root = tmpdir.join('root') | 26 root = tmpdir.join('root') |
27 root.mkdir('foo') | 27 root.mkdir('foo') |
28 foobar = root.join('foo', 'bar.txt') | 28 foobar = root.join('foo', 'bar.txt') |
29 foobar.write('! foo/bar.txt\n! end') | 29 foobar.write('! foo/bar.txt\n! end') |
30 return str(root) | 30 return str(root) |
31 | 31 |
32 | 32 |
33 @pytest.fixture | 33 @pytest.fixture |
34 def fssource(fssource_dir): | 34 def fssource(fssource_dir): |
35 return FSSource(fssource_dir) | 35 return FSSource(fssource_dir) |
36 | 36 |
37 | 37 |
38 @pytest.fixture | |
39 def websource(fssource_dir): | |
40 return WebSource(fssource_dir) | |
41 | |
42 | |
38 def test_read_file(fssource): | 43 def test_read_file(fssource): |
39 assert list(fssource.get('foo/bar.txt')) == ['! foo/bar.txt', '! end'] | 44 assert list(fssource.get('foo/bar.txt')) == ['! foo/bar.txt', '! end'] |
40 | 45 |
41 | 46 |
42 def test_escape_source(fssource): | 47 def test_escape_source(fssource): |
43 with pytest.raises(ValueError): | 48 with pytest.raises(ValueError): |
44 list(fssource.get('../not-in-source.txt')) | 49 list(fssource.get('../not-in-source.txt')) |
45 | 50 |
46 | 51 |
47 def test_read_missing_file(fssource): | 52 def test_read_missing_file(fssource): |
48 with pytest.raises(NotFound): | 53 with pytest.raises(NotFound): |
49 list(fssource.get('foo/baz.txt')) | 54 list(fssource.get('foo/baz.txt')) |
55 | |
56 | |
57 def test_fssource_get_err(fssource): | |
58 with pytest.raises(IOError): | |
59 list(fssource.get('')) | |
60 | |
61 | |
62 def test_websource_get_err(websource): | |
Sebastian Noack
2018/12/29 03:24:56
Shouldn't this rather go in test_web_source.py?
rhowell
2019/01/03 04:42:27
Yeah, looks like it should, but this test is no lo
| |
63 with pytest.raises(ValueError): | |
64 list(websource.get('')) | |
OLD | NEW |