Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 # There are cases where we need to test outputs which differ depending |
17 # on how they are generated; either statically or dynamically | |
17 if filename.endswith('@' + test_type): | 18 if filename.endswith('@' + test_type): |
18 realname = filename.split('@')[0] | 19 realname = filename.split('@')[0] |
19 outputs[realname] = outputs[filename] | 20 outputs[realname] = outputs[filename] |
20 if ':' in filename: | 21 # Move bookmark specific output (e.g. "xyx@static+master -> xyz+master) |
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
| |
22 # There are cases where we need to test outputs which differ depending | |
23 # on the bookmark which they are generated from: | |
24 # https://issues.adblockplus.org/ticket/6605 | |
25 if '+' in filename: | |
21 realname = ''.join(filename.split('@' + test_type)) | 26 realname = ''.join(filename.split('@' + test_type)) |
22 outputs[realname] = outputs[filename] | 27 outputs[realname] = outputs[filename] |
28 # Remove the expected outputs that don't apply for this test type. | |
23 if '@' in filename: | 29 if '@' in filename: |
24 del outputs[filename] | 30 del outputs[filename] |
25 return outputs.items() | 31 return outputs.items() |
26 | 32 |
27 | 33 |
28 static_expected_outputs = get_expected_outputs('static') | 34 static_expected_outputs = get_expected_outputs('static') |
29 dynamic_expected_outputs = get_expected_outputs('dynamic') | 35 dynamic_expected_outputs = get_expected_outputs('dynamic') |
30 | 36 |
31 | 37 |
32 @pytest.fixture(scope='session', params=['master', None]) | 38 @pytest.fixture(scope='session', params=['master', None]) |
(...skipping 20 matching lines...) Expand all Loading... | |
53 | 59 |
54 @pytest.fixture(scope='session') | 60 @pytest.fixture(scope='session') |
55 def output_pages(static_output): | 61 def output_pages(static_output): |
56 return get_dir_contents(static_output) | 62 return get_dir_contents(static_output) |
57 | 63 |
58 | 64 |
59 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) | 65 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) |
60 def test_static(revision, output_pages, filename, expected_output): | 66 def test_static(revision, output_pages, filename, expected_output): |
61 if expected_output.startswith('## MISSING'): | 67 if expected_output.startswith('## MISSING'): |
62 assert filename not in output_pages | 68 assert filename not in output_pages |
63 elif revision and ':' + revision in filename: | 69 elif revision and '+' + revision in filename: |
64 filename = filename.split(':')[0] | 70 filename = filename.split('+')[0] |
65 assert expected_output == output_pages[filename] | 71 assert expected_output == output_pages[filename] |
66 elif not revision and ':' not in filename: | 72 elif not revision and '+' not in filename: |
67 assert expected_output == output_pages[filename] | 73 assert expected_output == output_pages[filename] |
68 | 74 |
69 | 75 |
70 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) | 76 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) |
71 def test_dynamic(dynamic_server, filename, expected_output): | 77 def test_dynamic(dynamic_server, filename, expected_output): |
72 response = urllib2.urlopen(dynamic_server + filename) | 78 response = urllib2.urlopen(dynamic_server + filename) |
73 assert expected_output == response.read().strip() | 79 assert expected_output == response.read().strip() |
74 | 80 |
75 | 81 |
76 def test_revision_arg(revision, output_pages): | 82 def test_revision_arg(revision, output_pages): |
77 if revision is None: | 83 if revision is None: |
78 assert 'en/bar' in output_pages | 84 assert 'en/bar' in output_pages |
79 else: | 85 else: |
80 assert 'en/bar' not in output_pages | 86 assert 'en/bar' not in output_pages |
LEFT | RIGHT |