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

Unified Diff: tests/test_render_script.py

Issue 29824555: Issue #4116: Make infile and outfile parameters of flrender script from python-abp optional (Closed)
Patch Set: Updated tests and README.md Created July 10, 2018, 4:07 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
« no previous file with comments | « abp/filters/sources.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_render_script.py
diff --git a/tests/test_render_script.py b/tests/test_render_script.py
index f78ff543e74fe83e5595c33ff2917042c99b4247..f1609543b416e6228818f88fdee0eb3a13e84d01 100644
--- a/tests/test_render_script.py
+++ b/tests/test_render_script.py
@@ -93,20 +93,40 @@ def dstfile(tmpdir):
def run_script(*args, **kw):
"""Run rendering script with given arguments and return its output."""
cmd = ['flrender'] + list(args)
- proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, **kw)
- stdout, stderr = proc.communicate()
- return proc.returncode, stderr.decode('utf-8')
+ test_in = None
+ if 'test_in' in kw.keys():
+ test_in = kw.pop('test_in')
Vasily Kuznetsov 2018/07/13 17:41:04 I just found that you can replace this and the two
Tudor Avram 2018/07/16 09:17:11 Done.
+ if test_in is not None:
+ test_in = test_in.encode('utf-8')
-def test_render_no_includes(rootdir, dstfile):
- run_script(str(rootdir.join('simple.txt')), str(dstfile))
- result = dstfile.read()
- assert 'Ok' in result
- assert '! Checksum:' in result
+ proc = subprocess.Popen(cmd, stderr=subprocess.PIPE,
+ stdout=subprocess.PIPE, stdin=subprocess.PIPE,
+ **kw)
+ stdout, stderr = proc.communicate(input=test_in)
+ return proc.returncode, stderr.decode('utf-8'), stdout.decode('utf-8')
+
+
+@pytest.mark.parametrize('test_input, args', [
+ ('None', ("'simple.txt'", 'str(dstfile)')),
Vasily Kuznetsov 2018/07/13 17:41:04 We iterate over the inner tuple, so according to o
+ ('None', ("'simple.txt'",)),
+ ("rootdir.join('simple.txt').read()", ()),
+])
+def test_render_no_includes(test_input, args, rootdir, dstfile):
+ _locals = locals()
+ test_input = eval(test_input, _locals)
Vasily Kuznetsov 2018/07/13 17:41:04 But this eval doesn't need the _locals, right? It
Tudor Avram 2018/07/16 09:17:11 Done.
+ args = [eval(arg, _locals) for arg in args]
Vasily Kuznetsov 2018/07/13 17:41:04 It seems that if you use map(eval, args) instead o
Tudor Avram 2018/07/16 09:17:12 Done.
+
+ _, _, stdout = run_script(*args, cwd=str(rootdir), test_in=test_input)
+
+ if len(args) > 1:
+ assert 'Ok' in dstfile.read()
+ else:
+ assert 'Ok' in stdout
def test_render_unicode(rootdir, dstfile):
- code, err = run_script(str(rootdir.join('unicode.txt')), str(dstfile))
+ code, err, _ = run_script(str(rootdir.join('unicode.txt')), str(dstfile))
assert '\u1234' in dstfile.read(mode='rb').decode('utf-8')
@@ -122,33 +142,34 @@ def test_render_with_includes_relative(rootdir, dstfile):
def test_render_verbose(rootdir, dstfile):
- code, err = run_script('includer.txt', str(dstfile),
- '-i', 'inc=inc', '-v', cwd=str(rootdir))
+ code, err, _ = run_script('includer.txt', str(dstfile),
+ '-i', 'inc=inc', '-v', cwd=str(rootdir))
assert err == 'Rendering: includer.txt\n- including: inc:includee.txt\n'
def test_no_header(rootdir, dstfile):
- code, err = run_script('inc/includee.txt', str(dstfile), cwd=str(rootdir))
+ code, err, _ = run_script('inc/includee.txt', str(dstfile),
+ cwd=str(rootdir))
assert code == 1
assert err == 'No header found at the beginning of the input.\n'
def test_wrong_file(dstfile):
- code, err = run_script('wrong.txt', str(dstfile))
+ code, err, _ = run_script('wrong.txt', str(dstfile))
assert code == 1
assert err == "File not found: 'wrong.txt'\n"
def test_wrong_include_source(rootdir, dstfile):
- code, err = run_script('brk.txt', str(dstfile), cwd=str(rootdir))
+ code, err, _ = run_script('brk.txt', str(dstfile), cwd=str(rootdir))
assert code == 1
assert err == ("Unknown source: 'inc' when including 'inc:broken.txt' "
"from 'brk.txt'\n")
def test_wrong_include(rootdir, dstfile):
- code, err = run_script('brk.txt', str(dstfile),
- '-i', 'inc=inc', cwd=str(rootdir))
+ code, err, _ = run_script('brk.txt', str(dstfile),
+ '-i', 'inc=inc', cwd=str(rootdir))
missing_path = str(rootdir.join('inc', 'missing.txt'))
expect = ("File not found: '{}' when including 'missing.txt' "
"from 'inc:broken.txt' from 'brk.txt'\n").format(missing_path)
@@ -157,8 +178,8 @@ def test_wrong_include(rootdir, dstfile):
def test_circular_includes(rootdir, dstfile):
- code, err = run_script('circ.txt', str(dstfile),
- '-i', 'inc=inc', cwd=str(rootdir))
+ code, err, _ = run_script('circ.txt', str(dstfile),
+ '-i', 'inc=inc', cwd=str(rootdir))
expect = ("Include loop encountered when including 'circular.txt' "
"from 'circular.txt' from 'inc:circular.txt' from 'circ.txt'\n")
assert code == 1
@@ -166,7 +187,7 @@ def test_circular_includes(rootdir, dstfile):
def test_wrong_source(rootdir, dstfile):
- code, err = run_script('foo:bar.txt', str(dstfile))
+ code, err, _ = run_script('foo:bar.txt', str(dstfile))
assert code == 1
assert err == "Unknown source: 'foo'\n"
@@ -177,7 +198,7 @@ def test_web_include(rootdir, dstfile, webserver_port):
url = 'http://localhost:{}/metainc.txt'.format(webserver_port)
webinc = rootdir.join('webinc.txt')
webinc.write('[Adblock]\n%include {}%'.format(url))
- code, err = run_script(str(webinc), str(dstfile))
+ code, err, _ = run_script(str(webinc), str(dstfile))
assert 'Web \u1234' in dstfile.read(mode='rb').decode('utf-8')
@@ -186,7 +207,7 @@ def test_failed_web_include(rootdir, dstfile, webserver_port):
url = 'http://localhost:{}/missing.txt'.format(webserver_port)
webinc = rootdir.join('webinc.txt')
webinc.write('[Adblock]\n%include {}%'.format(url))
- code, err = run_script(str(webinc), str(dstfile))
+ code, err, _ = run_script(str(webinc), str(dstfile))
assert code == 1
assert err.startswith(
"HTTP 404 Not found: '{0}' when including '{0}'".format(url))
« no previous file with comments | « abp/filters/sources.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld