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

Unified Diff: tests/test_diff_script.py

Issue 29922555: Issue 7059 - Modify fldiff so it can handle multiple files (Closed) Base URL: https://hg.adblockplus.org/python-abp
Patch Set: Address comments on PS1 Created Oct. 26, 2018, 9:40 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') | « abp/filters/diff_script.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
===================================================================
--- a/tests/test_diff_script.py
+++ b/tests/test_diff_script.py
@@ -20,8 +20,11 @@
import pytest
import subprocess
import io
+import os
+import re
from test_differ import BASE, LATEST
+from abp.filters.diff_script import main as diff_script
@pytest.fixture
@@ -29,16 +32,34 @@
"""Directory with example filter lists."""
rootdir = tmpdir.join('root')
rootdir.mkdir()
- rootdir.join('base.txt').write_text(BASE, encoding='utf8')
rootdir.join('latest.txt').write_text(LATEST, encoding='utf8')
-
return rootdir
@pytest.fixture
-def dstfile(tmpdir):
- """Destination file for saving the diff output."""
- return tmpdir.join('dst')
+def archive_dir(rootdir):
+ return rootdir.mkdir('archive')
+
+
+@pytest.fixture
+def diff_dir(rootdir):
+ return rootdir.mkdir('diff')
+
+
+@pytest.fixture
+def archived_files(archive_dir):
+ base2 = BASE + '&adnet=\n'
+ base2 = re.sub(r'! Version: \d+', '! Version: 112', base2)
+ archive_dir.join('list111.txt').write_text(BASE, encoding='utf8')
+ archive_dir.join('list112.txt').write_text(base2, encoding='utf8')
+ return [str(x) for x in archive_dir.listdir()]
+
+
+@pytest.fixture
+def base_no_version(archive_dir):
+ base = re.sub(r'! Version: \d+', '! ', BASE)
+ archive_dir.join('list113.txt').write_text(base, encoding='utf8')
+ return [str(x) for x in archive_dir.listdir()]
def run_script(*args, **kw):
@@ -52,34 +73,64 @@
return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8')
-def test_diff_with_outfile(rootdir, dstfile):
- run_script(str(rootdir.join('base.txt')),
- str(rootdir.join('latest.txt')),
- str(dstfile))
- with io.open(str(dstfile), encoding='utf-8') as dst:
- result = dst.read()
- assert '+ &ad_channel=\xa3' in result
+def _make_args(rootdir, diff_dir):
+ return [str(rootdir.join('latest.txt')), '-o ' + str(diff_dir)]
Vasily Kuznetsov 2018/10/29 16:31:48 '-o' and str(diff_dir) would be different argument
rhowell 2018/10/29 20:01:40 Ended up just removing this function, but I did sw
Vasily Kuznetsov 2018/10/29 23:47:33 Acknowledged.
-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_diff_with_dict(rootdir, archived_files, diff_dir):
+ arg = _make_args(rootdir, diff_dir)
Vasily Kuznetsov 2018/10/29 16:31:48 I wonder if _make_args is actually worth it. Here
rhowell 2018/10/29 20:01:40 Done.
+ arg.extend(archived_files)
+ diff_script(arg)
+ for root, dirs, files in os.walk(str(diff_dir)):
+ for file in files:
+ with io.open(str(diff_dir.join(file)), encoding='utf-8') as dst:
+ result = dst.read()
+ assert '- &ad.vid=$~xmlhttprequest' in result
+ assert '+ &ad_channel=\xa3' in result
+ assert '! Version: 123' in result
+
+
+def test_diff_with_outfile(rootdir, archived_files, diff_dir):
+ arg = _make_args(rootdir, diff_dir)
+ arg.extend(archived_files)
+ run_script(*arg)
Vasily Kuznetsov 2018/10/29 16:31:48 Following on the previous comment, here we'd get s
rhowell 2018/10/29 20:01:40 Done.
+ for root, dirs, files in os.walk(str(diff_dir)):
+ assert files
+ for file in files:
+ with io.open(str(diff_dir.join(file)), encoding='utf-8') as dst:
+ result = dst.read()
+ assert '- &ad.vid=$~xmlhttprequest' in result
+ assert '+ &ad_channel=\xa3' in result
+ assert '! Version: 123' in result
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
+ code, err, _ = run_script(str(rootdir.join('latest.txt')))
+ assert code == 2
+ assert 'usage: fldiff' in err
-def test_no_latest_file(rootdir):
+def test_missing_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'
+def test_diff_to_self(rootdir, diff_dir):
+ arg = _make_args(rootdir, diff_dir)
+ arg.append(str(rootdir.join('latest.txt')))
+ run_script(*arg)
+ for root, dirs, files in os.walk(str(diff_dir)):
+ assert files
+ for file in files:
+ with io.open(str(diff_dir.join(file)), encoding='utf-8') as dst:
+ result = dst.read()
+ assert result == '[Adblock Plus Diff]\n'
+
+
+def test_no_version(rootdir, base_no_version):
+ arg = _make_args(rootdir, diff_dir)
+ arg.extend(base_no_version)
+ code, err, _ = run_script(*arg)
+ assert code == 1
+ assert err == 'Unable to find Version in [Adblock Plus 2.0]\n'
« abp/filters/diff_script.py ('K') | « abp/filters/diff_script.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld