| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 import logging | 1 import logging |
| 2 import os | 2 import os |
| 3 import sys | 3 import sys |
| 4 import runpy | 4 import runpy |
| 5 | 5 |
| 6 import mock | 6 import mock |
| 7 import pytest | 7 import pytest |
| 8 | 8 |
| 9 from .conftest import ROOTPATH | 9 from .conftest import ROOTPATH |
| 10 from .utils import get_dir_contents, exception_test | 10 from .utils import get_dir_contents, exception_test |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 def test_cache(output_pages): | 64 def test_cache(output_pages): |
| 65 source = FileSource(os.path.join('test_site')) | 65 source = FileSource(os.path.join('test_site')) |
| 66 assert source.get_cache_dir() == os.path.join('test_site', 'cache') | 66 assert source.get_cache_dir() == os.path.join('test_site', 'cache') |
| 67 | 67 |
| 68 | 68 |
| 69 def test_broken_link_warnings(temp_site, tmpdir_factory, caplog): | 69 def test_broken_link_warnings(temp_site, tmpdir_factory, caplog): |
| 70 caplog.set_level(logging.WARNING) | 70 caplog.set_level(logging.WARNING) |
| 71 generate_static_pages(temp_site, tmpdir_factory) | 71 generate_static_pages(temp_site, tmpdir_factory) |
| 72 messages = {t[2] for t in caplog.record_tuples} | 72 messages = {t[2] for t in caplog.record_tuples} |
| 73 expected_messages = [ | 73 expected_messages = [ |
| 74 'Link to "missing" (from "brokenlink") cannot be resolved', | 74 'Link from "brokenlink" to "missing" cannot be resolved', |
| 75 'Link to "missing" (from "brokenlink-html") cannot be resolved', | 75 'Link from "brokenlink-html" to "missing" cannot be resolved', |
| 76 'Link to "missing" (from "brokenlink-tmpl") cannot be resolved', | 76 'Link from "brokenlink-tmpl" to "missing" cannot be resolved', |
| 77 ] | 77 ] |
| 78 for message in expected_messages: | 78 for message in expected_messages: |
| 79 assert message in messages | 79 assert message in messages |
|
rhowell
2019/04/12 20:17:12
NIT: This test might be a bit stricter if we used
Vasily Kuznetsov
2019/04/15 16:48:45
Yes, I thought about it too. In the end I decided
rhowell
2019/04/16 01:46:58
Makes sense.
| |
| 80 raise messages | |
| 80 | 81 |
| 81 | 82 |
| 82 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) | 83 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) |
| 83 def test_dynamic_server_handler(filename, expected_output, temp_site): | 84 def test_dynamic_server_handler(filename, expected_output, temp_site): |
| 84 | 85 |
| 85 def cleanup(page): | 86 def cleanup(page): |
| 86 return page.replace(os.linesep, '').strip() | 87 return page.replace(os.linesep, '').strip() |
| 87 | 88 |
| 88 handler = DynamicServerHandler('localhost', 5000, str(temp_site)) | 89 handler = DynamicServerHandler('localhost', 5000, str(temp_site)) |
| 89 environ = {'PATH_INFO': filename} | 90 environ = {'PATH_INFO': filename} |
| 90 | 91 |
| 91 generated_page = handler(environ, lambda x, y: None) | 92 generated_page = handler(environ, lambda x, y: None) |
| 92 | 93 |
| 93 assert cleanup(expected_output) == cleanup(generated_page[0]) | 94 assert cleanup(expected_output) == cleanup(generated_page[0]) |
| 94 | 95 |
| 95 | 96 |
| 96 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) | 97 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) |
| 97 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): | 98 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): |
| 98 handler = DynamicServerHandler('localhost', 5000, | 99 handler = DynamicServerHandler('localhost', 5000, |
| 99 str(temp_site_with_conflicts)) | 100 str(temp_site_with_conflicts)) |
| 100 environ = {'PATH_INFO': page} | 101 environ = {'PATH_INFO': page} |
| 101 exp_msg = 'The requested page conflicts with another page.' | 102 exp_msg = 'The requested page conflicts with another page.' |
| 102 | 103 |
| 103 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) | 104 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) |
| LEFT | RIGHT |