Index: tests/test_page_outputs.py |
=================================================================== |
--- a/tests/test_page_outputs.py |
+++ b/tests/test_page_outputs.py |
@@ -11,38 +11,37 @@ |
from cms.bin.test_server import DynamicServerHandler |
-def get_expected_outputs(test_type): |
- expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') |
- 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] |
+def get_expected_outputs(test_type, with_common=True): |
+ root = os.path.join(ROOTPATH, 'tests', 'expected_output') |
+ outputs = {} |
+ if with_common: |
+ outputs = get_dir_contents(os.path.join(root, 'common')) |
+ outputs.update(get_dir_contents(os.path.join(root, test_type))) |
return outputs.items() |
static_expected_outputs = get_expected_outputs('static') |
dynamic_expected_outputs = get_expected_outputs('dynamic') |
+relative_expected_outputs = get_expected_outputs('relative', False) |
+ |
+ |
+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 +52,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 +67,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() |