Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: tests/test_diff_script.py

Issue 29884571: Issue 6945 - Add script to make filter list diffs (Closed) Base URL: https://hg.adblockplus.org/python-abp/
Patch Set: Use io.open instead of open() Created Sept. 18, 2018, 5:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« abp/filters/diff_script.py ('K') | « setup.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
27 from test_differ import BASE, LATEST, EXPECTED
28 from abp.filters.diff_script import main as diff_script
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(BASE)
37 rootdir.join('latest.txt').write(LATEST)
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_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):
70 run_script(str(rootdir.join('base.txt')),
71 str(rootdir.join('latest.txt')),
72 str(dstfile))
73 result = dstfile.read()
74 assert set(result.splitlines()) == set(EXPECTED.splitlines())
75
76
77 def test_no_outfile(rootdir):
78 _, _, out = run_script(str(rootdir.join('base.txt')),
79 str(rootdir.join('latest.txt')))
80 assert '[Adblock Plus Diff]' in out
81
82
83 def test_no_base_file(rootdir):
84 code, err, _ = run_script('wrong.txt', str(rootdir.join('latest.txt')))
85 assert code == 1
86 assert 'No such file or directory' in err
87
88
89 def test_no_latest_file(rootdir):
90 code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt')
91 assert code == 1
92 assert 'No such file or directory' in err
93
94
95 def test_diff_to_self(rootdir):
96 _, _, out = run_script(str(rootdir.join('latest.txt')),
97 str(rootdir.join('latest.txt')))
98 assert out == '[Adblock Plus Diff]\n'
OLDNEW
« abp/filters/diff_script.py ('K') | « setup.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld