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: Created July 6, 2018, 11:39 a.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
« README.md ('K') | « 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..0c36999c2115977556849f76a54770a1e575145b 100644
--- a/tests/test_render_script.py
+++ b/tests/test_render_script.py
@@ -93,9 +93,14 @@ 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():
Vasily Kuznetsov 2018/07/09 17:00:57 Space missing here (weird that flake8 is ok...)
Tudor Avram 2018/07/10 16:09:47 Done.
+ test_in = kw.pop('test_in').encode('utf-8')
+ 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')
def test_render_no_includes(rootdir, dstfile):
@@ -106,7 +111,7 @@ def test_render_no_includes(rootdir, dstfile):
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 +127,54 @@ 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_stdin_stdout(rootdir):
Vasily Kuznetsov 2018/07/09 17:00:57 Wouldn't it be simpler to model this and the follo
Tudor Avram 2018/07/10 08:06:20 Ok, will do that. From what I see, the case for in
+ test_input = '[Adblock]\ntest\nwww.test.test\ntest.test.test\n'
+ expected_body = 'test\nwww.test.test\ntest.test.test\n'
+ expected_header = '[Adblock]'
+
+ _, _, stdout = run_script('-i', 'inc=inc', '-v',
+ cwd=str(rootdir), test_in=test_input)
+ lines = stdout.split('\n')
+ assert expected_header == lines[0]
+ assert expected_body in stdout
+
+
+def test_filein_stdout(rootdir):
+ expected = 'I am included!'
+ _, _, stdout = run_script('includer.txt', '-i', 'inc=inc',
+ cwd=str(rootdir))
+
+ assert expected in stdout
+
+
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 +183,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 +192,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 +203,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 +212,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))
« README.md ('K') | « abp/filters/sources.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld