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

Side by Side Diff: tests/test_page_outputs.py

Issue 29755806: Noissue - convert test_page_outputs to pytest-regtest (Closed)
Patch Set: Combine page outputs Created April 23, 2018, 8:55 a.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/translate-tmpl ('k') | tox.ini » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from __future__ import print_function
2
1 import os 3 import os
2 import sys 4 import sys
3 import runpy 5 import runpy
4 import pytest 6 import pytest
5 import urllib2 7 import urllib2
6 8
7 from .conftest import ROOTPATH 9 from .conftest import PAGE_LIST, LANG_LIST
8 from .utils import get_dir_contents, run_test_server 10 from .utils import get_dir_contents, run_test_server
9 11
10 12
11 def get_expected_outputs(test_type):
12 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output')
13 outputs = get_dir_contents(expected_out_path)
14 for filename in list(outputs):
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.
17 if filename.endswith('@' + test_type):
18 realname = filename.split('@')[0]
19 outputs[realname] = outputs[filename]
20 if '@' in filename:
21 del outputs[filename]
22 return outputs.items()
23
24
25 static_expected_outputs = get_expected_outputs('static')
26 dynamic_expected_outputs = get_expected_outputs('dynamic')
27
28
29 @pytest.fixture(scope='session', params=['master', None]) 13 @pytest.fixture(scope='session', params=['master', None])
30 def revision(request): 14 def revision(request):
31 return request.param 15 return request.param
32 16
33 17
34 @pytest.fixture(scope='session') 18 @pytest.fixture(scope='session')
35 def static_output(revision, request, temp_site): 19 def static_output(revision, request, temp_site):
36 static_out_path = os.path.join(temp_site, 'static_out') 20 static_out_path = os.path.join(temp_site, 'static_out')
37 sys.argv = ['filler', temp_site, static_out_path] 21 sys.argv = ['filler', temp_site, static_out_path]
38 if revision is not None: 22 if revision is not None:
39 sys.argv += ['--rev', revision] 23 sys.argv += ['--rev', revision]
40 24
41 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') 25 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
42 return static_out_path 26 return static_out_path
43 27
44 28
45 @pytest.fixture(scope='module') 29 @pytest.fixture(scope='module')
46 def dynamic_server(temp_site): 30 def dynamic_server(temp_site):
47 with run_test_server(temp_site) as ts: 31 with run_test_server(temp_site) as ts:
48 yield ts 32 yield ts
49 33
50 34
51 @pytest.fixture(scope='session') 35 @pytest.fixture(scope='session')
52 def output_pages(static_output): 36 def output_pages(static_output):
53 return get_dir_contents(static_output) 37 return get_dir_contents(static_output)
54 38
55 39
56 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) 40 def test_static(regtest, output_pages, revision):
57 def test_static(output_pages, filename, expected_output): 41 for path in output_pages:
58 if expected_output.startswith('## MISSING'): 42 regtest.write('### {} ###\n{}\n'.format(path, output_pages[path]))
59 assert filename not in output_pages
60 else:
61 assert expected_output == output_pages[filename]
62 43
63 44
64 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) 45 def test_dynamic(regtest, dynamic_server):
65 def test_dynamic(dynamic_server, filename, expected_output): 46 for lang in LANG_LIST:
66 response = urllib2.urlopen(dynamic_server + filename) 47 for page in PAGE_LIST:
67 assert expected_output == response.read().strip() 48 path = '{}/{}'.format(lang, page)
49 response = urllib2.urlopen(dynamic_server + path)
50 regtest.write('### {} ###\n{}\n'.format(path, response.read()))
68 51
69 52
70 def test_revision_arg(revision, output_pages): 53 def test_revision_arg(revision, output_pages):
71 if revision is None: 54 if revision is None:
72 assert 'en/bar' in output_pages 55 assert 'en/bar' in output_pages
73 else: 56 else:
74 assert 'en/bar' not in output_pages 57 assert 'en/bar' not in output_pages
OLDNEW
« no previous file with comments | « tests/expected_output/en/translate-tmpl ('k') | tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld