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 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 import subprocess | 21 import subprocess |
22 import io | 22 import io |
23 import os | 23 import os |
24 import re | 24 import re |
25 | 25 |
26 from test_differ import BASE, LATEST | 26 from test_differ import BASE, LATEST |
27 | 27 |
28 | 28 |
29 @pytest.fixture | 29 @pytest.fixture |
30 def rootdir(tmpdir): | 30 def rootdir(tmpdir): |
31 """Root directory holds the latest filter list, and folders for archived | 31 """Root directory for test files.""" |
Vasily Kuznetsov
2018/10/31 14:42:39
Multiline docstrings should "consist of a summary
rhowell
2018/10/31 19:11:46
Oops, thanks! I knew the multiline docstring looke
| |
32 lists and diffs.""" | |
33 rootdir = tmpdir.join('root') | 32 rootdir = tmpdir.join('root') |
34 rootdir.mkdir() | 33 rootdir.mkdir() |
35 rootdir.join('latest.txt').write_text(LATEST, encoding='utf8') | 34 rootdir.join('latest.txt').write_text(LATEST, encoding='utf8') |
36 return rootdir | 35 return rootdir |
37 | 36 |
38 | 37 |
39 @pytest.fixture | 38 @pytest.fixture |
40 def archive_dir(rootdir): | 39 def archive_dir(rootdir): |
41 return rootdir.mkdir('archive') | 40 return rootdir.mkdir('archive') |
42 | 41 |
(...skipping 26 matching lines...) Expand all Loading... | |
69 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, | 68 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, |
70 stdout=subprocess.PIPE, stdin=subprocess.PIPE, | 69 stdout=subprocess.PIPE, stdin=subprocess.PIPE, |
71 **kw) | 70 **kw) |
72 stdout, stderr = proc.communicate() | 71 stdout, stderr = proc.communicate() |
73 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8') | 72 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8') |
74 | 73 |
75 | 74 |
76 def test_diff_with_outfile(rootdir, archived_files, diff_dir): | 75 def test_diff_with_outfile(rootdir, archived_files, diff_dir): |
77 run_script(str(rootdir.join('latest.txt')), '-o', str(diff_dir), | 76 run_script(str(rootdir.join('latest.txt')), '-o', str(diff_dir), |
78 *archived_files) | 77 *archived_files) |
79 assert len(os.listdir(str(diff_dir))) == 2 | 78 assert len(diff_dir.listdir()) == 2 |
Vasily Kuznetsov
2018/10/31 14:42:39
It's a good idea to check how many files were crea
rhowell
2018/10/31 19:11:45
Yeah, it seems more consistent to use the function
| |
80 for file in diff_dir.visit(): | 79 for file in diff_dir.visit(): |
81 with io.open(str(file), encoding='utf-8') as dst: | 80 with io.open(str(file), encoding='utf-8') as dst: |
82 result = dst.read() | 81 result = dst.read() |
83 assert '- &ad.vid=$~xmlhttprequest' in result | 82 assert '- &ad.vid=$~xmlhttprequest' in result |
84 assert '+ &ad_channel=\xa3' in result | 83 assert '+ &ad_channel=\xa3' in result |
85 assert '! Version: 123' in result | 84 assert '! Version: 123' in result |
86 | 85 |
87 | 86 |
88 def test_diff_no_outfile(rootdir, archived_files): | 87 def test_diff_no_outfile(rootdir, archived_files): |
89 os.chdir(str(rootdir)) | 88 os.chdir(str(rootdir)) |
(...skipping 14 matching lines...) Expand all Loading... | |
104 | 103 |
105 def test_wrong_file(rootdir): | 104 def test_wrong_file(rootdir): |
106 code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt') | 105 code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt') |
107 assert code == 1 | 106 assert code == 1 |
108 assert 'No such file or directory' in err | 107 assert 'No such file or directory' in err |
109 | 108 |
110 | 109 |
111 def test_diff_to_self(rootdir, diff_dir): | 110 def test_diff_to_self(rootdir, diff_dir): |
112 run_script(str(rootdir.join('latest.txt')), '-o', str(diff_dir), | 111 run_script(str(rootdir.join('latest.txt')), '-o', str(diff_dir), |
113 str(rootdir.join('latest.txt'))) | 112 str(rootdir.join('latest.txt'))) |
114 assert len(os.listdir(str(diff_dir))) == 1 | 113 assert len(diff_dir.listdir()) == 1 |
115 for file in diff_dir.visit(): | 114 for file in diff_dir.visit(): |
116 with io.open(str(file), encoding='utf-8') as dst: | 115 with io.open(str(file), encoding='utf-8') as dst: |
117 result = dst.read() | 116 result = dst.read() |
118 assert result == '[Adblock Plus Diff]\n' | 117 assert result == '[Adblock Plus Diff]\n' |
119 | 118 |
120 | 119 |
121 def test_no_version(rootdir, base_no_version): | 120 def test_no_version(rootdir, base_no_version): |
122 code, err, _ = run_script(str(rootdir.join('latest.txt')), '-o', | 121 code, err, _ = run_script(str(rootdir.join('latest.txt')), '-o', |
123 str(diff_dir), *base_no_version) | 122 str(diff_dir), *base_no_version) |
124 assert code == 1 | 123 assert code == 1 |
125 assert 'Unable to find Version in ' in err | 124 assert 'Unable to find Version in ' in err |
126 | 125 |
127 | 126 |
128 def test_write_and_overwrite(rootdir, archived_files, diff_dir): | 127 def test_write_and_overwrite(rootdir, archived_files, diff_dir): |
129 test_diff_with_outfile(rootdir, archived_files, diff_dir) | 128 test_diff_with_outfile(rootdir, archived_files, diff_dir) |
130 latest = re.sub(r'&act=ads_', '! ', BASE) | 129 latest = re.sub(r'&act=ads_', '! ', BASE) |
131 latest = latest + '&adurl=\n' | 130 latest = latest + '&adurl=\n' |
132 rootdir.join('latest.txt').write_text(latest, encoding='utf8') | 131 rootdir.join('latest.txt').write_text(latest, encoding='utf8') |
133 run_script(str(rootdir.join('latest.txt')), '-o', str(diff_dir), | 132 run_script(str(rootdir.join('latest.txt')), '-o', str(diff_dir), |
134 *archived_files) | 133 *archived_files) |
135 assert len(os.listdir(str(diff_dir))) == 2 | 134 assert len(diff_dir.listdir()) == 2 |
136 for file in diff_dir.visit(): | 135 for file in diff_dir.visit(): |
137 with io.open(str(file), encoding='utf-8') as dst: | 136 with io.open(str(file), encoding='utf-8') as dst: |
138 result = dst.read() | 137 result = dst.read() |
139 assert '- &act=ads_' in result | 138 assert '- &act=ads_' in result |
140 assert '+ &adurl=' in result | 139 assert '+ &adurl=' in result |
141 assert '- &ad.vid=$~xmlhttprequest' not in result | 140 assert '- &ad.vid=$~xmlhttprequest' not in result |
LEFT | RIGHT |