| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 import os | 1 import os |
| 2 import sys | 2 import sys |
| 3 import runpy | 3 import runpy |
| 4 | 4 |
| 5 import mock | 5 import mock |
| 6 import pytest | 6 import pytest |
| 7 | 7 |
| 8 from .conftest import ROOTPATH | 8 from .conftest import ROOTPATH |
| 9 from .utils import get_dir_contents, exception_test | 9 from .utils import get_dir_contents, exception_test |
| 10 from cms.sources import FileSource | 10 from cms.sources import FileSource |
| 11 from cms.bin.test_server import DynamicServerHandler | 11 from cms.bin.test_server import DynamicServerHandler |
| 12 | 12 |
| 13 | 13 |
| 14 def get_expected_outputs(test_type): | 14 def get_expected_outputs(test_type, with_common=True): |
| 15 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output', | 15 root = os.path.join(ROOTPATH, 'tests', 'expected_output') |
| 16 test_type) | 16 outputs = {} |
| 17 outputs = get_dir_contents(expected_out_path) | 17 if with_common: |
| 18 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output', | 18 outputs = get_dir_contents(os.path.join(root, 'common')) |
|
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.
| |
| 19 'common') | 19 outputs.update(get_dir_contents(os.path.join(root, test_type))) |
| 20 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.
| |
| 21 return outputs.items() | 20 return outputs.items() |
| 22 | 21 |
| 23 | 22 |
| 24 static_expected_outputs = get_expected_outputs('static') | 23 static_expected_outputs = get_expected_outputs('static') |
| 25 dynamic_expected_outputs = get_expected_outputs('dynamic') | 24 dynamic_expected_outputs = get_expected_outputs('dynamic') |
| 26 relative_expected_outputs = get_expected_outputs('relative') | 25 relative_expected_outputs = get_expected_outputs('relative', False) |
|
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.
| |
| 27 | 26 |
| 28 | 27 |
| 29 def generate_static_pages(temp_site, tmpdir_factory, *extra_args): | 28 def generate_static_pages(temp_site, tmpdir_factory, *extra_args): |
| 30 dst_path = str(tmpdir_factory.mktemp('static')) | 29 dst_path = str(tmpdir_factory.mktemp('static')) |
| 31 sys.argv = ['filler', temp_site, dst_path] + list(extra_args) | 30 sys.argv = ['filler', temp_site, dst_path] + list(extra_args) |
| 32 with mock.patch('cms.sources.FileSource.version', 1): | 31 with mock.patch('cms.sources.FileSource.version', 1): |
| 33 runpy.run_module('cms.bin.generate_static_pages', | 32 runpy.run_module('cms.bin.generate_static_pages', |
| 34 run_name='__main__') | 33 run_name='__main__') |
| 35 return get_dir_contents(dst_path) | 34 return get_dir_contents(dst_path) |
| 36 | 35 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 | 80 |
| 82 | 81 |
| 83 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) | 82 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) |
| 84 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): | 83 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): |
| 85 handler = DynamicServerHandler('localhost', 5000, | 84 handler = DynamicServerHandler('localhost', 5000, |
| 86 str(temp_site_with_conflicts)) | 85 str(temp_site_with_conflicts)) |
| 87 environ = {'PATH_INFO': page} | 86 environ = {'PATH_INFO': page} |
| 88 exp_msg = 'The requested page conflicts with another page.' | 87 exp_msg = 'The requested page conflicts with another page.' |
| 89 | 88 |
| 90 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) | 89 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) |
| LEFT | RIGHT |