Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 """Functional tests for the rendering script. | 16 """Functional tests for the diff script.""" |
17 | |
18 These tests create files on the filesystem, bring up a small webserver and | |
19 generally test the script under reasonably realistic conditions. | |
20 """ | |
21 | 17 |
22 from __future__ import unicode_literals | 18 from __future__ import unicode_literals |
23 | 19 |
24 import pytest | 20 import pytest |
25 import subprocess | 21 import subprocess |
22 import io | |
26 | 23 |
27 from test_differ import BASE, LATEST, EXPECTED | 24 from test_differ import BASE, LATEST |
28 from abp.filters.diff_script import main as diff_script | |
29 | 25 |
30 | 26 |
31 @pytest.fixture | 27 @pytest.fixture |
32 def rootdir(tmpdir): | 28 def rootdir(tmpdir): |
33 """Directory with example filter lists.""" | 29 """Directory with example filter lists.""" |
34 rootdir = tmpdir.join('root') | 30 rootdir = tmpdir.join('root') |
35 rootdir.mkdir() | 31 rootdir.mkdir() |
36 rootdir.join('base.txt').write(BASE) | 32 rootdir.join('base.txt').write_text(BASE, encoding='utf8') |
37 rootdir.join('latest.txt').write(LATEST) | 33 rootdir.join('latest.txt').write_text(LATEST, encoding='utf8') |
38 | 34 |
39 return rootdir | 35 return rootdir |
40 | 36 |
41 | 37 |
42 @pytest.fixture | 38 @pytest.fixture |
43 def dstfile(tmpdir): | 39 def dstfile(tmpdir): |
44 """Destination file for saving the diff output.""" | 40 """Destination file for saving the diff output.""" |
45 return tmpdir.join('dst') | 41 return tmpdir.join('dst') |
46 | 42 |
47 | 43 |
48 def run_script(*args, **kw): | 44 def run_script(*args, **kw): |
49 """Run diff rendering script with given arguments and return its output.""" | 45 """Run diff rendering script with given arguments and return its output.""" |
50 cmd = ['fldiff'] + list(args) | 46 cmd = ['fldiff'] + list(args) |
51 | 47 |
52 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, | 48 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, |
53 stdout=subprocess.PIPE, stdin=subprocess.PIPE, | 49 stdout=subprocess.PIPE, stdin=subprocess.PIPE, |
54 **kw) | 50 **kw) |
55 stdout, stderr = proc.communicate() | 51 stdout, stderr = proc.communicate() |
56 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8') | 52 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8') |
57 | 53 |
58 | 54 |
59 def test_diff_with_dict(rootdir, dstfile): | |
60 args = {} | |
61 args['base'] = str(rootdir.join('base.txt')) | |
62 args['latest'] = str(rootdir.join('latest.txt')) | |
63 args['outfile'] = str(dstfile) | |
64 diff_script(args) | |
65 result = dstfile.read() | |
66 assert set(result.splitlines()) == set(EXPECTED.splitlines()) | |
67 | |
68 | |
69 def test_diff_with_outfile(rootdir, dstfile): | 55 def test_diff_with_outfile(rootdir, dstfile): |
70 run_script(str(rootdir.join('base.txt')), | 56 run_script(str(rootdir.join('base.txt')), |
rhowell
2018/09/18 17:23:33
Should the script be called like:
1) fldiff base=b
Vasily Kuznetsov
2018/09/19 18:40:03
I think `fldiff base.txt latest.txt` is the best a
rhowell
2018/09/21 08:37:08
Acknowledged.
| |
71 str(rootdir.join('latest.txt')), | 57 str(rootdir.join('latest.txt')), |
72 str(dstfile)) | 58 str(dstfile)) |
73 result = dstfile.read() | 59 with io.open(str(dstfile), encoding='utf-8') as dst: |
74 assert set(result.splitlines()) == set(EXPECTED.splitlines()) | 60 result = dst.read() |
61 assert '+ &ad_channel=\xa3' in result | |
75 | 62 |
76 | 63 |
77 def test_no_outfile(rootdir): | 64 def test_no_outfile(rootdir): |
78 _, _, out = run_script(str(rootdir.join('base.txt')), | 65 _, _, out = run_script(str(rootdir.join('base.txt')), |
79 str(rootdir.join('latest.txt'))) | 66 str(rootdir.join('latest.txt'))) |
80 assert '[Adblock Plus Diff]' in out | 67 assert '[Adblock Plus Diff]' in out |
81 | 68 |
82 | 69 |
83 def test_no_base_file(rootdir): | 70 def test_no_base_file(rootdir): |
84 code, err, _ = run_script('wrong.txt', str(rootdir.join('latest.txt'))) | 71 code, err, _ = run_script('wrong.txt', str(rootdir.join('latest.txt'))) |
85 assert code == 1 | 72 assert code == 1 |
86 assert 'No such file or directory' in err | 73 assert 'No such file or directory' in err |
rhowell
2018/09/18 16:01:54
I'm not sure if these errors are being handled pro
| |
87 | 74 |
88 | 75 |
89 def test_no_latest_file(rootdir): | 76 def test_no_latest_file(rootdir): |
90 code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt') | 77 code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt') |
91 assert code == 1 | 78 assert code == 1 |
92 assert 'No such file or directory' in err | 79 assert 'No such file or directory' in err |
93 | 80 |
94 | 81 |
95 def test_diff_to_self(rootdir): | 82 def test_diff_to_self(rootdir): |
96 _, _, out = run_script(str(rootdir.join('latest.txt')), | 83 _, _, out = run_script(str(rootdir.join('latest.txt')), |
97 str(rootdir.join('latest.txt'))) | 84 str(rootdir.join('latest.txt'))) |
98 assert out == '[Adblock Plus Diff]\n' | 85 assert out == '[Adblock Plus Diff]\n' |
LEFT | RIGHT |