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

Unified 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: Created Sept. 18, 2018, 3:57 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« abp/filters/diff_script.py ('K') | « setup.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_diff_script.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_diff_script.py
@@ -0,0 +1,98 @@
+# This file is part of Adblock Plus <https://adblockplus.org/>,
+# Copyright (C) 2006-present eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+"""Functional tests for the rendering script.
+
+These tests create files on the filesystem, bring up a small webserver and
+generally test the script under reasonably realistic conditions.
+"""
+
+from __future__ import unicode_literals
+
+import pytest
+import subprocess
+
+from test_differ import BASE, LATEST, EXPECTED
+from abp.filters.diff_script import main as diff_script
+
+
+@pytest.fixture
+def rootdir(tmpdir):
+ """Directory with example filter lists."""
+ rootdir = tmpdir.join('root')
+ rootdir.mkdir()
+ rootdir.join('base.txt').write(BASE)
+ rootdir.join('latest.txt').write(LATEST)
+
+ return rootdir
+
+
+@pytest.fixture
+def dstfile(tmpdir):
+ """Destination file for saving the diff output."""
+ return tmpdir.join('dst')
+
+
+def run_script(*args, **kw):
+ """Run diff rendering script with given arguments and return its output."""
+ cmd = ['fldiff'] + list(args)
+
+ proc = subprocess.Popen(cmd, stderr=subprocess.PIPE,
+ stdout=subprocess.PIPE, stdin=subprocess.PIPE,
+ **kw)
+ stdout, stderr = proc.communicate()
+ return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8')
+
+
+def test_diff_with_dict(rootdir, dstfile):
+ args = {}
+ args['base'] = str(rootdir.join('base.txt'))
+ args['latest'] = str(rootdir.join('latest.txt'))
+ args['outfile'] = str(dstfile)
+ diff_script(args)
+ result = dstfile.read()
+ assert set(result.splitlines()) == set(EXPECTED.splitlines())
+
+
+def test_diff_with_outfile(rootdir, dstfile):
+ run_script(str(rootdir.join('base.txt')),
rhowell 2018/09/18 17:23:33 Should the script be called like: 1) fldiff base=b
Vasily Kuznetsov 2018/09/19 18:40:03 I think `fldiff base.txt latest.txt` is the best a
rhowell 2018/09/21 08:37:08 Acknowledged.
+ str(rootdir.join('latest.txt')),
+ str(dstfile))
+ result = dstfile.read()
+ assert set(result.splitlines()) == set(EXPECTED.splitlines())
+
+
+def test_no_outfile(rootdir):
+ _, _, out = run_script(str(rootdir.join('base.txt')),
+ str(rootdir.join('latest.txt')))
+ assert '[Adblock Plus Diff]' in out
+
+
+def test_no_base_file(rootdir):
+ code, err, _ = run_script('wrong.txt', str(rootdir.join('latest.txt')))
+ assert code == 1
+ assert 'No such file or directory' in err
rhowell 2018/09/18 16:01:54 I'm not sure if these errors are being handled pro
+
+
+def test_no_latest_file(rootdir):
+ code, err, _ = run_script(str(rootdir.join('base.txt')), 'wrong.txt')
+ assert code == 1
+ assert 'No such file or directory' in err
+
+
+def test_diff_to_self(rootdir):
+ _, _, out = run_script(str(rootdir.join('latest.txt')),
+ str(rootdir.join('latest.txt')))
+ assert out == '[Adblock Plus Diff]\n'
« 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