Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: tests/test_page_outputs.py

Issue 29753617: Issue 6545 - get_pages_metadata now returns all pages (Closed)
Patch Set: Rebase, changes comments to add citation to explain weird logic chain Created May 6, 2018, 10:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/expected_output/en/sitemap@static+master ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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]
21 # Move bookmark specific output (e.g. "xyx@static+master -> xyz+master)
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:
26 realname = ''.join(filename.split('@' + test_type))
27 outputs[realname] = outputs[filename]
28 # Remove the expected outputs that don't apply for this test type.
20 if '@' in filename: 29 if '@' in filename:
21 del outputs[filename] 30 del outputs[filename]
22 return outputs.items() 31 return outputs.items()
23 32
24 33
25 static_expected_outputs = get_expected_outputs('static') 34 static_expected_outputs = get_expected_outputs('static')
26 dynamic_expected_outputs = get_expected_outputs('dynamic') 35 dynamic_expected_outputs = get_expected_outputs('dynamic')
27 36
28 37
29 @pytest.fixture(scope='session', params=['master', None]) 38 @pytest.fixture(scope='session', params=['master', None])
(...skipping 17 matching lines...) Expand all
47 with run_test_server(temp_site) as ts: 56 with run_test_server(temp_site) as ts:
48 yield ts 57 yield ts
49 58
50 59
51 @pytest.fixture(scope='session') 60 @pytest.fixture(scope='session')
52 def output_pages(static_output): 61 def output_pages(static_output):
53 return get_dir_contents(static_output) 62 return get_dir_contents(static_output)
54 63
55 64
56 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) 65 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs)
57 def test_static(output_pages, filename, expected_output): 66 def test_static(revision, output_pages, filename, expected_output):
58 if expected_output.startswith('## MISSING'): 67 if expected_output.startswith('## MISSING'):
59 assert filename not in output_pages 68 assert filename not in output_pages
60 else: 69 elif revision and '+' + revision in filename:
70 filename = filename.split('+')[0]
71 assert expected_output == output_pages[filename]
72 elif not revision and '+' not in filename:
61 assert expected_output == output_pages[filename] 73 assert expected_output == output_pages[filename]
62 74
63 75
64 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) 76 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
65 def test_dynamic(dynamic_server, filename, expected_output): 77 def test_dynamic(dynamic_server, filename, expected_output):
66 response = urllib2.urlopen(dynamic_server + filename) 78 response = urllib2.urlopen(dynamic_server + filename)
67 assert expected_output == response.read().strip() 79 assert expected_output == response.read().strip()
68 80
69 81
70 def test_revision_arg(revision, output_pages): 82 def test_revision_arg(revision, output_pages):
71 if revision is None: 83 if revision is None:
72 assert 'en/bar' in output_pages 84 assert 'en/bar' in output_pages
73 else: 85 else:
74 assert 'en/bar' not in output_pages 86 assert 'en/bar' not in output_pages
OLDNEW
« no previous file with comments | « tests/expected_output/en/sitemap@static+master ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld