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: Created April 18, 2018, 9:30 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/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 @pytest.mark.parametrize('page', PAGE_LIST)
57 def test_static(output_pages, filename, expected_output): 41 @pytest.mark.parametrize('lang', LANG_LIST)
58 if expected_output.startswith('## MISSING'): 42 def test_static(regtest, output_pages, revision, page, lang):
59 assert filename not in output_pages 43 path = '{}/{}'.format(lang, page)
44 if path in output_pages:
45 regtest.write(output_pages[path])
60 else: 46 else:
61 assert expected_output == output_pages[filename] 47 regtest.write('## MISSING')
62 48
63 49
64 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) 50 @pytest.mark.parametrize('page', PAGE_LIST)
65 def test_dynamic(dynamic_server, filename, expected_output): 51 @pytest.mark.parametrize('lang', LANG_LIST)
66 response = urllib2.urlopen(dynamic_server + filename) 52 def test_dynamic(regtest, dynamic_server, page, lang):
67 assert expected_output == response.read().strip() 53 path = '{}/{}'.format(lang, page)
54 response = urllib2.urlopen(dynamic_server + path)
55 regtest.write(response.read())
68 56
69 57
70 def test_revision_arg(revision, output_pages): 58 def test_revision_arg(revision, output_pages):
71 if revision is None: 59 if revision is None:
72 assert 'en/bar' in output_pages 60 assert 'en/bar' in output_pages
73 else: 61 else:
74 assert 'en/bar' not in output_pages 62 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