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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 @pytest.fixture | 87 @pytest.fixture |
88 def dstfile(tmpdir): | 88 def dstfile(tmpdir): |
89 """Destination file for saving rendered list.""" | 89 """Destination file for saving rendered list.""" |
90 return tmpdir.join('dst') | 90 return tmpdir.join('dst') |
91 | 91 |
92 | 92 |
93 def run_script(*args, **kw): | 93 def run_script(*args, **kw): |
94 """Run rendering script with given arguments and return its output.""" | 94 """Run rendering script with given arguments and return its output.""" |
95 cmd = ['flrender'] + list(args) | 95 cmd = ['flrender'] + list(args) |
96 | 96 |
97 test_in = None | 97 test_in = kw.pop('test_in', None) |
98 if 'test_in' in kw.keys(): | |
99 test_in = kw.pop('test_in') | |
Vasily Kuznetsov
2018/07/13 17:41:04
I just found that you can replace this and the two
Tudor Avram
2018/07/16 09:17:11
Done.
| |
100 if test_in is not None: | 98 if test_in is not None: |
101 test_in = test_in.encode('utf-8') | 99 test_in = test_in.encode('utf-8') |
102 | 100 |
103 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, | 101 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, |
104 stdout=subprocess.PIPE, stdin=subprocess.PIPE, | 102 stdout=subprocess.PIPE, stdin=subprocess.PIPE, |
105 **kw) | 103 **kw) |
106 stdout, stderr = proc.communicate(input=test_in) | 104 stdout, stderr = proc.communicate(input=test_in) |
107 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8') | 105 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8') |
108 | 106 |
109 | 107 |
110 @pytest.mark.parametrize('test_input, args', [ | 108 @pytest.mark.parametrize('test_input, args', [ |
111 ('None', ("'simple.txt'", 'str(dstfile)')), | 109 ('None', ["'simple.txt'", 'str(dstfile)']), |
Vasily Kuznetsov
2018/07/13 17:41:04
We iterate over the inner tuple, so according to o
| |
112 ('None', ("'simple.txt'",)), | 110 ('None', ["'simple.txt'"]), |
113 ("rootdir.join('simple.txt').read()", ()), | 111 ("rootdir.join('simple.txt').read()", []), |
114 ]) | 112 ]) |
115 def test_render_no_includes(test_input, args, rootdir, dstfile): | 113 def test_render_no_includes(test_input, args, rootdir, dstfile): |
116 _locals = locals() | 114 test_input = eval(test_input) |
117 test_input = eval(test_input, _locals) | 115 args = list(map(eval, args)) |
Vasily Kuznetsov
2018/07/13 17:41:04
But this eval doesn't need the _locals, right? It
Tudor Avram
2018/07/16 09:17:11
Done.
| |
118 args = [eval(arg, _locals) for arg in args] | |
Vasily Kuznetsov
2018/07/13 17:41:04
It seems that if you use map(eval, args) instead o
Tudor Avram
2018/07/16 09:17:12
Done.
| |
119 | |
120 _, _, stdout = run_script(*args, cwd=str(rootdir), test_in=test_input) | 116 _, _, stdout = run_script(*args, cwd=str(rootdir), test_in=test_input) |
121 | 117 |
122 if len(args) > 1: | 118 if len(args) > 1: |
123 assert 'Ok' in dstfile.read() | 119 output = dstfile.read() |
124 else: | 120 else: |
125 assert 'Ok' in stdout | 121 output = stdout |
122 | |
123 assert 'Ok' in output | |
124 assert '! Checksum:' in output | |
126 | 125 |
127 | 126 |
128 def test_render_unicode(rootdir, dstfile): | 127 def test_render_unicode(rootdir, dstfile): |
129 code, err, _ = run_script(str(rootdir.join('unicode.txt')), str(dstfile)) | 128 code, err, _ = run_script(str(rootdir.join('unicode.txt')), str(dstfile)) |
130 assert '\u1234' in dstfile.read(mode='rb').decode('utf-8') | 129 assert '\u1234' in dstfile.read(mode='rb').decode('utf-8') |
131 | 130 |
132 | 131 |
133 def test_render_with_includes(rootdir, dstfile): | 132 def test_render_with_includes(rootdir, dstfile): |
134 run_script(str(rootdir.join('includer.txt')), str(dstfile), | 133 run_script(str(rootdir.join('includer.txt')), str(dstfile), |
135 '-i', 'inc=' + str(rootdir.join('inc'))) | 134 '-i', 'inc=' + str(rootdir.join('inc'))) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 203 |
205 @pytest.mark.slowtest | 204 @pytest.mark.slowtest |
206 def test_failed_web_include(rootdir, dstfile, webserver_port): | 205 def test_failed_web_include(rootdir, dstfile, webserver_port): |
207 url = 'http://localhost:{}/missing.txt'.format(webserver_port) | 206 url = 'http://localhost:{}/missing.txt'.format(webserver_port) |
208 webinc = rootdir.join('webinc.txt') | 207 webinc = rootdir.join('webinc.txt') |
209 webinc.write('[Adblock]\n%include {}%'.format(url)) | 208 webinc.write('[Adblock]\n%include {}%'.format(url)) |
210 code, err, _ = run_script(str(webinc), str(dstfile)) | 209 code, err, _ = run_script(str(webinc), str(dstfile)) |
211 assert code == 1 | 210 assert code == 1 |
212 assert err.startswith( | 211 assert err.startswith( |
213 "HTTP 404 Not found: '{0}' when including '{0}'".format(url)) | 212 "HTTP 404 Not found: '{0}' when including '{0}'".format(url)) |
LEFT | RIGHT |