OLD | NEW |
(Empty) | |
| 1 # This file is part of Adblock Plus <https://adblockplus.org/>, |
| 2 # Copyright (C) 2006-present eyeo GmbH |
| 3 # |
| 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 |
| 6 # published by the Free Software Foundation. |
| 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. |
| 12 # |
| 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/>. |
| 15 |
| 16 """Functional tests for the rendering 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 |
| 22 from __future__ import unicode_literals |
| 23 |
| 24 import pytest |
| 25 import subprocess |
| 26 import io |
| 27 |
| 28 from test_differ import BASE, LATEST |
| 29 |
| 30 |
| 31 @pytest.fixture |
| 32 def rootdir(tmpdir): |
| 33 """Directory with example filter lists.""" |
| 34 rootdir = tmpdir.join('root') |
| 35 rootdir.mkdir() |
| 36 rootdir.join('base.txt').write_text(BASE, encoding='utf8') |
| 37 rootdir.join('latest.txt').write_text(LATEST, encoding='utf8') |
| 38 |
| 39 return rootdir |
| 40 |
| 41 |
| 42 @pytest.fixture |
| 43 def dstfile(tmpdir): |
| 44 """Destination file for saving the diff output.""" |
| 45 return tmpdir.join('dst') |
| 46 |
| 47 |
| 48 def run_script(*args, **kw): |
| 49 """Run diff rendering script with given arguments and return its output.""" |
| 50 cmd = ['fldiff'] + list(args) |
| 51 |
| 52 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, |
| 53 stdout=subprocess.PIPE, stdin=subprocess.PIPE, |
| 54 **kw) |
| 55 stdout, stderr = proc.communicate() |
| 56 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8') |
| 57 |
| 58 |
| 59 def test_diff_with_outfile(rootdir, dstfile): |
| 60 run_script(str(rootdir.join('base.txt')), |
| 61 str(rootdir.join('latest.txt')), |
| 62 str(dstfile)) |
| 63 with io.open(str(dstfile), encoding='utf-8') as dst: |
| 64 result = dst.read() |
| 65 assert '+ &ad_channel=\xa3' in result |
| 66 |
| 67 |
| 68 def test_no_outfile(rootdir): |
| 69 _, _, out = run_script(str(rootdir.join('base.txt')), |
| 70 str(rootdir.join('latest.txt'))) |
| 71 assert '[Adblock Plus Diff]' in out |
| 72 |
| 73 |
| 74 def test_no_base_file(rootdir): |
| 75 code, err, _ = run_script('wrong.txt', str(rootdir.join('latest.txt'))) |
| 76 assert code == 1 |
| 77 assert 'No such file or directory' in err |
| 78 |
| 79 |
| 80 def test_no_latest_file(rootdir): |
| 81 code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt') |
| 82 assert code == 1 |
| 83 assert 'No such file or directory' in err |
| 84 |
| 85 |
| 86 def test_diff_to_self(rootdir): |
| 87 _, _, out = run_script(str(rootdir.join('latest.txt')), |
| 88 str(rootdir.join('latest.txt'))) |
| 89 assert out == '[Adblock Plus Diff]\n' |
OLD | NEW |