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

Delta Between Two Patch Sets: tests/test_page_outputs.py

Issue 29495555: Fixes 5343 - add global function: get_canonical_url (Closed)
Left Patch Set: Created July 23, 2017, 4:35 p.m.
Right Patch Set: Add comment about test-type-specific expected output handling Created Aug. 3, 2017, 9:10 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/expected_output/sitemap ('k') | tests/test_site/pages/get_page_url.tmpl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import os 1 import os
2 import sys 2 import sys
3 import time 3 import time
4 import runpy 4 import runpy
5 import signal 5 import signal
6 import pytest 6 import pytest
7 import urllib2 7 import urllib2
8 import subprocess 8 import subprocess
9 from conftest import ROOTPATH 9 from conftest import ROOTPATH
10 10
11 11
12 def get_dir_contents(path): 12 def get_dir_contents(path):
13 return_data = {} 13 return_data = {}
14 for dirpath, dirnames, filenames in os.walk(path): 14 for dirpath, dirnames, filenames in os.walk(path):
15 for output_file in filenames: 15 for output_file in filenames:
16 with open(os.path.join(dirpath, output_file)) as f: 16 with open(os.path.join(dirpath, output_file)) as f:
17 return_data[output_file] = f.read().strip() 17 return_data[output_file] = f.read().strip()
Vasily Kuznetsov 2017/07/23 16:55:33 Increase test robustness a bit.
18 return return_data 18 return return_data
19 19
20 20
21 def get_expected_outputs(test_type): 21 def get_expected_outputs(test_type):
22 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') 22 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output')
23 outputs = get_dir_contents(expected_out_path) 23 outputs = get_dir_contents(expected_out_path)
24 for filename in list(outputs): 24 for filename in list(outputs):
25 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz")
Vasily Kuznetsov 2017/08/03 09:12:20 I added a comment to make it more clear what's goi
26 # and remove the expected outputs that don't apply for this test type.
25 if filename.endswith('@' + test_type): 27 if filename.endswith('@' + test_type):
26 realname = filename.split('@')[0] 28 realname = filename.split('@')[0]
27 outputs[realname] = outputs[filename] 29 outputs[realname] = outputs[filename]
28 if '@' in filename: 30 if '@' in filename:
29 del outputs[filename] 31 del outputs[filename]
30 return outputs.items() 32 return outputs.items()
31 33
32 34
33 static_expected_outputs = get_expected_outputs('static') 35 static_expected_outputs = get_expected_outputs('static')
34 dynamic_expected_outputs = get_expected_outputs('dynamic') 36 dynamic_expected_outputs = get_expected_outputs('dynamic')
(...skipping 17 matching lines...) Expand all
52 54
53 @pytest.yield_fixture() 55 @pytest.yield_fixture()
54 def dynamic_server(temp_site): 56 def dynamic_server(temp_site):
55 args = ['python', 'runserver.py', temp_site] 57 args = ['python', 'runserver.py', temp_site]
56 # Werkzeug is a dependency of flask which we are using for the mock api 58 # Werkzeug is a dependency of flask which we are using for the mock api
57 # however there is an issue with Werkzeug that prevents it from properly 59 # however there is an issue with Werkzeug that prevents it from properly
58 # handling the SIGTERM sent by p.kill() or terminate() 60 # handling the SIGTERM sent by p.kill() or terminate()
59 # Issue: https://github.com/pallets/werkzeug/issues/58 61 # Issue: https://github.com/pallets/werkzeug/issues/58
60 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid) 62 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
61 time.sleep(0.5) 63 time.sleep(0.5)
62 yield 'http://localhost:5000/en/' 64 yield 'http://localhost:5000/en/'
Vasily Kuznetsov 2017/07/23 16:55:33 This was producing "root" as current locale in the
63 os.killpg(os.getpgid(p.pid), signal.SIGTERM) 65 os.killpg(os.getpgid(p.pid), signal.SIGTERM)
64 66
65 67
66 @pytest.fixture(scope='session') 68 @pytest.fixture(scope='session')
67 def output_pages(static_output): 69 def output_pages(static_output):
68 return get_dir_contents(static_output) 70 return get_dir_contents(static_output)
69 71
70 72
71 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) 73 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs)
72 def test_static(output_pages, filename, expected_output): 74 def test_static(output_pages, filename, expected_output):
73 assert output_pages[filename] == expected_output 75 assert output_pages[filename] == expected_output
74 76
75 77
76 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) 78 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
77 def test_dynamic(dynamic_server, filename, expected_output): 79 def test_dynamic(dynamic_server, filename, expected_output):
78 response = urllib2.urlopen(dynamic_server + filename) 80 response = urllib2.urlopen(dynamic_server + filename)
79 assert response.read().strip() == expected_output 81 assert response.read().strip() == expected_output
80 82
81 83
82 def test_revision_arg(revision, output_pages): 84 def test_revision_arg(revision, output_pages):
83 if revision is None: 85 if revision is None:
84 assert 'bar' in output_pages 86 assert 'bar' in output_pages
85 else: 87 else:
86 assert 'bar' not in output_pages 88 assert 'bar' not in output_pages
LEFTRIGHT

Powered by Google App Engine
This is Rietveld