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: Fix docstring Created Sept. 26, 2018, 6:20 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
« no previous file with comments | « setup.py ('k') | tests/test_differ.py » ('j') | 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 diff script."""
17
18 from __future__ import unicode_literals
19
20 import pytest
21 import subprocess
22 import io
23
24 from test_differ import BASE, LATEST
25
26
27 @pytest.fixture
28 def rootdir(tmpdir):
29 """Directory with example filter lists."""
30 rootdir = tmpdir.join('root')
31 rootdir.mkdir()
32 rootdir.join('base.txt').write_text(BASE, encoding='utf8')
33 rootdir.join('latest.txt').write_text(LATEST, encoding='utf8')
34
35 return rootdir
36
37
38 @pytest.fixture
39 def dstfile(tmpdir):
40 """Destination file for saving the diff output."""
41 return tmpdir.join('dst')
42
43
44 def run_script(*args, **kw):
45 """Run diff rendering script with given arguments and return its output."""
46 cmd = ['fldiff'] + list(args)
47
48 proc = subprocess.Popen(cmd, stderr=subprocess.PIPE,
49 stdout=subprocess.PIPE, stdin=subprocess.PIPE,
50 **kw)
51 stdout, stderr = proc.communicate()
52 return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8')
53
54
55 def test_diff_with_outfile(rootdir, dstfile):
56 run_script(str(rootdir.join('base.txt')),
57 str(rootdir.join('latest.txt')),
58 str(dstfile))
59 with io.open(str(dstfile), encoding='utf-8') as dst:
60 result = dst.read()
61 assert '+ &ad_channel=\xa3' in result
62
63
64 def test_no_outfile(rootdir):
65 _, _, out = run_script(str(rootdir.join('base.txt')),
66 str(rootdir.join('latest.txt')))
67 assert '[Adblock Plus Diff]' in out
68
69
70 def test_no_base_file(rootdir):
71 code, err, _ = run_script('wrong.txt', str(rootdir.join('latest.txt')))
72 assert code == 1
73 assert 'No such file or directory' in err
74
75
76 def test_no_latest_file(rootdir):
77 code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt')
78 assert code == 1
79 assert 'No such file or directory' in err
80
81
82 def test_diff_to_self(rootdir):
83 _, _, out = run_script(str(rootdir.join('latest.txt')),
84 str(rootdir.join('latest.txt')))
85 assert out == '[Adblock Plus Diff]\n'
OLDNEW
« no previous file with comments | « setup.py ('k') | tests/test_differ.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld