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

Side by Side Diff: tests/test_page_outputs.py

Issue 29805580: Issue 6728 - Remove Mercurial dependency (Closed)
Patch Set: Addremove files to diff Created June 12, 2018, 11:01 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
OLDNEW
1 import os 1 import os
2 import sys 2 import sys
3 import runpy 3 import runpy
4
5 import mock
4 import pytest 6 import pytest
5 import urllib2 7 import urllib2
6 8
7 from .conftest import ROOTPATH 9 from .conftest import ROOTPATH
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): 13 def get_expected_outputs(test_type):
12 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') 14 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output')
13 outputs = get_dir_contents(expected_out_path) 15 outputs = get_dir_contents(expected_out_path)
14 for filename in list(outputs): 16 for filename in list(outputs):
15 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") 17 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz")
16 # There are cases where we need to test outputs which differ depending 18 # There are cases where we need to test outputs which differ depending
17 # on how they are generated; either statically or dynamically 19 # on how they are generated; either statically or dynamically
18 if filename.endswith('@' + test_type): 20 if filename.endswith('@' + test_type):
19 realname = filename.split('@')[0] 21 realname = filename.split('@')[0]
20 outputs[realname] = outputs[filename] 22 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. 23 # Remove the expected outputs that don't apply for this test type.
29 if '@' in filename: 24 if '@' in filename:
30 del outputs[filename] 25 del outputs[filename]
31 return outputs.items() 26 return outputs.items()
32 27
33 28
34 static_expected_outputs = get_expected_outputs('static') 29 static_expected_outputs = get_expected_outputs('static')
35 dynamic_expected_outputs = get_expected_outputs('dynamic') 30 dynamic_expected_outputs = get_expected_outputs('dynamic')
36 31
37 32
38 @pytest.fixture(scope='session', params=['master', None]) 33 @mock.patch('cms.sources.FileSource.version', 1)
39 def revision(request):
40 return request.param
41
42
43 @pytest.fixture(scope='session') 34 @pytest.fixture(scope='session')
44 def static_output(revision, request, temp_site): 35 def static_output(request, temp_site):
45 static_out_path = os.path.join(temp_site, 'static_out') 36 static_out_path = os.path.join(temp_site, 'static_out')
46 sys.argv = ['filler', temp_site, static_out_path] 37 sys.argv = ['filler', temp_site, static_out_path]
47 if revision is not None:
48 sys.argv += ['--rev', revision]
49 38
50 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') 39 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
51 return static_out_path 40 return static_out_path
52 41
53 42
54 @pytest.fixture(scope='module') 43 @pytest.fixture(scope='module')
55 def dynamic_server(temp_site): 44 def dynamic_server(temp_site):
56 with run_test_server(temp_site) as ts: 45 with run_test_server(temp_site) as ts:
57 yield ts 46 yield ts
58 47
59 48
60 @pytest.fixture(scope='session') 49 @pytest.fixture(scope='session')
61 def output_pages(static_output): 50 def output_pages(static_output):
62 return get_dir_contents(static_output) 51 return get_dir_contents(static_output)
63 52
64 53
65 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) 54 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs)
66 def test_static(revision, output_pages, filename, expected_output): 55 def test_static(output_pages, filename, expected_output):
67 if expected_output.startswith('## MISSING'): 56 if expected_output.startswith('## MISSING'):
68 assert filename not in output_pages 57 assert filename not in output_pages
69 elif revision and '+' + revision in filename: 58 return
Vasily Kuznetsov 2018/06/13 13:35:23 Maybe this could just be replaced with `else:`.
Jon Sonesen 2018/06/14 19:24:15 Heh, yeah for sure whoops
Vasily Kuznetsov 2018/07/03 08:50:24 This one seems to still be there in PS3
70 filename = filename.split('+')[0] 59 assert expected_output == output_pages[filename]
71 assert expected_output == output_pages[filename]
72 elif not revision and '+' not in filename:
73 assert expected_output == output_pages[filename]
74 60
75 61
76 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) 62 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
77 def test_dynamic(dynamic_server, filename, expected_output): 63 def test_dynamic(dynamic_server, filename, expected_output):
78 response = urllib2.urlopen(dynamic_server + filename) 64 response = urllib2.urlopen(dynamic_server + filename)
79 assert expected_output == response.read().strip() 65 assert expected_output == response.read().strip()
80
81
82 def test_revision_arg(revision, output_pages):
83 if revision is None:
84 assert 'en/bar' in output_pages
85 else:
86 assert 'en/bar' not in output_pages
OLDNEW
« tests/conftest.py ('K') | « tests/expected_output/en/sitemap@static+master ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld