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

Unified Diff: tests/test_page_outputs.py

Issue 29933596: Issue 5333 - Allow cms to generate relative pages (Closed) Base URL: https://hg.adblockplus.org/cms/
Patch Set: Address comments on PS2, rearrange test files (again) Created Nov. 7, 2018, 4:14 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
Index: tests/test_page_outputs.py
===================================================================
--- a/tests/test_page_outputs.py
+++ b/tests/test_page_outputs.py
@@ -12,37 +12,37 @@
def get_expected_outputs(test_type):
- expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output')
+ expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output',
+ test_type)
outputs = get_dir_contents(expected_out_path)
- for filename in list(outputs):
- # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz")
- # There are cases where we need to test outputs which differ depending
- # on how they are generated; either statically or dynamically
- if filename.endswith('@' + test_type):
- realname = filename.split('@')[0]
- outputs[realname] = outputs[filename]
- # Remove the expected outputs that don't apply for this test type.
- if '@' in filename:
- del outputs[filename]
+ expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output',
Vasily Kuznetsov 2018/11/07 18:03:02 Reusing variables like this is not a very good pra
rhowell 2018/11/07 20:05:26 Done.
+ 'common')
+ outputs.update(get_dir_contents(expected_out_path))
Vasily Kuznetsov 2018/11/07 18:03:02 It seems that the correct approach should be to lo
rhowell 2018/11/07 20:05:26 Done.
return outputs.items()
static_expected_outputs = get_expected_outputs('static')
dynamic_expected_outputs = get_expected_outputs('dynamic')
+relative_expected_outputs = get_expected_outputs('relative')
Vasily Kuznetsov 2018/11/07 18:03:02 My proposal was to also skip the common expected o
rhowell 2018/11/07 20:05:25 Done.
+
+
+def generate_static_pages(temp_site, tmpdir_factory, *extra_args):
+ dst_path = str(tmpdir_factory.mktemp('static'))
+ sys.argv = ['filler', temp_site, dst_path] + list(extra_args)
+ with mock.patch('cms.sources.FileSource.version', 1):
+ runpy.run_module('cms.bin.generate_static_pages',
+ run_name='__main__')
+ return get_dir_contents(dst_path)
@pytest.fixture(scope='session')
-def static_output(request, temp_site):
- static_out_path = os.path.join(temp_site, 'static_out')
- sys.argv = ['filler', temp_site, static_out_path]
- with mock.patch('cms.sources.FileSource.version', 1):
- runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
- return static_out_path
+def output_pages(temp_site, tmpdir_factory):
+ return generate_static_pages(temp_site, tmpdir_factory)
@pytest.fixture(scope='session')
-def output_pages(static_output):
- return get_dir_contents(static_output)
+def output_pages_relative(temp_site, tmpdir_factory):
+ return generate_static_pages(temp_site, tmpdir_factory, '--relative')
@pytest.mark.parametrize('filename,expected_output', static_expected_outputs)
@@ -53,6 +53,14 @@
assert expected_output == output_pages[filename]
+@pytest.mark.parametrize('filename,expected_output', relative_expected_outputs)
+def test_static_relative(output_pages_relative, filename, expected_output):
+ if expected_output.startswith('## MISSING'):
+ assert filename not in output_pages_relative
+ else:
+ assert expected_output == output_pages_relative[filename]
+
+
def test_cache(output_pages):
source = FileSource(os.path.join('test_site'))
assert source.get_cache_dir() == os.path.join('test_site', 'cache')
@@ -60,6 +68,7 @@
@pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
def test_dynamic_server_handler(filename, expected_output, temp_site):
+
def cleanup(page):
return page.replace(os.linesep, '').strip()

Powered by Google App Engine
This is Rietveld