Left: | ||
Right: |
OLD | NEW |
---|---|
1 import os | 1 import os |
2 import sys | 2 import sys |
3 import runpy | 3 import runpy |
4 import pytest | 4 import pytest |
5 import urllib2 | 5 import urllib2 |
6 | 6 |
7 from .conftest import ROOTPATH | 7 from .conftest import ROOTPATH |
8 from .utils import get_dir_contents, run_test_server | 8 from .utils import get_dir_contents, run_test_server |
9 | 9 |
10 | 10 |
11 def get_expected_outputs(test_type): | 11 def get_expected_outputs(test_type): |
12 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') | 12 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') |
13 outputs = get_dir_contents(expected_out_path) | 13 outputs = get_dir_contents(expected_out_path) |
14 for filename in list(outputs): | 14 for filename in list(outputs): |
15 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") | 15 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") |
16 # and remove the expected outputs that don't apply for this test type. | 16 # and remove the expected outputs that don't apply for this test type. |
17 if filename.endswith('@' + test_type): | 17 if filename.endswith('@' + test_type): |
18 realname = filename.split('@')[0] | 18 realname = filename.split('@')[0] |
19 outputs[realname] = outputs[filename] | 19 outputs[realname] = outputs[filename] |
20 if ':' in filename: | |
Vasily Kuznetsov
2018/04/17 18:36:08
It seems like the code in this `if` is not necessa
Jon Sonesen
2018/04/17 21:02:40
As discussed very IRC the code is necessary howeve
| |
21 realname = ''.join(filename.split('@' + test_type)) | |
22 outputs[realname] = outputs[filename] | |
20 if '@' in filename: | 23 if '@' in filename: |
21 del outputs[filename] | 24 del outputs[filename] |
22 return outputs.items() | 25 return outputs.items() |
23 | 26 |
24 | 27 |
25 static_expected_outputs = get_expected_outputs('static') | 28 static_expected_outputs = get_expected_outputs('static') |
26 dynamic_expected_outputs = get_expected_outputs('dynamic') | 29 dynamic_expected_outputs = get_expected_outputs('dynamic') |
27 | 30 |
28 | 31 |
29 @pytest.fixture(scope='session', params=['master', None]) | 32 @pytest.fixture(scope='session', params=['master', None]) |
(...skipping 17 matching lines...) Expand all Loading... | |
47 with run_test_server(temp_site) as ts: | 50 with run_test_server(temp_site) as ts: |
48 yield ts | 51 yield ts |
49 | 52 |
50 | 53 |
51 @pytest.fixture(scope='session') | 54 @pytest.fixture(scope='session') |
52 def output_pages(static_output): | 55 def output_pages(static_output): |
53 return get_dir_contents(static_output) | 56 return get_dir_contents(static_output) |
54 | 57 |
55 | 58 |
56 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) | 59 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) |
57 def test_static(output_pages, filename, expected_output): | 60 def test_static(revision, output_pages, filename, expected_output): |
58 if expected_output.startswith('## MISSING'): | 61 if expected_output.startswith('## MISSING'): |
59 assert filename not in output_pages | 62 assert filename not in output_pages |
60 else: | 63 elif revision and ':' + revision in filename: |
64 filename = filename.split(':')[0] | |
65 assert expected_output == output_pages[filename] | |
66 elif not revision and ':' not in filename: | |
61 assert expected_output == output_pages[filename] | 67 assert expected_output == output_pages[filename] |
62 | 68 |
63 | 69 |
64 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) | 70 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) |
65 def test_dynamic(dynamic_server, filename, expected_output): | 71 def test_dynamic(dynamic_server, filename, expected_output): |
66 response = urllib2.urlopen(dynamic_server + filename) | 72 response = urllib2.urlopen(dynamic_server + filename) |
67 assert expected_output == response.read().strip() | 73 assert expected_output == response.read().strip() |
68 | 74 |
69 | 75 |
70 def test_revision_arg(revision, output_pages): | 76 def test_revision_arg(revision, output_pages): |
71 if revision is None: | 77 if revision is None: |
72 assert 'en/bar' in output_pages | 78 assert 'en/bar' in output_pages |
73 else: | 79 else: |
74 assert 'en/bar' not in output_pages | 80 assert 'en/bar' not in output_pages |
OLD | NEW |