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

Side by Side Diff: tests/test_page_outputs.py

Issue 29512555: Noissue - Adds better locale support to test suite (Closed)
Patch Set: remove pointless sort Created Aug. 11, 2017, 7:43 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 ('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 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 dirdata = {}
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 filepath = os.path.join(dirpath, output_file)
17 return_data[output_file] = f.read().strip() 17 with open(filepath) as f:
18 return return_data 18 locale = os.path.split(os.path.split(filepath)[0])[1]
19 dirdata[os.path.join(locale, output_file)] = f.read().strip()
20 return dirdata
19 21
20 22
21 def get_expected_outputs(test_type): 23 def get_expected_outputs(test_type):
22 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') 24 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output')
23 outputs = get_dir_contents(expected_out_path) 25 outputs = get_dir_contents(expected_out_path)
24 for filename in list(outputs): 26 for filename in list(outputs):
25 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") 27 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz")
26 # and remove the expected outputs that don't apply for this test type. 28 # and remove the expected outputs that don't apply for this test type.
27 if filename.endswith('@' + test_type): 29 if filename.endswith('@' + test_type):
28 realname = filename.split('@')[0] 30 realname = filename.split('@')[0]
(...skipping 25 matching lines...) Expand all
54 56
55 @pytest.yield_fixture() 57 @pytest.yield_fixture()
56 def dynamic_server(temp_site): 58 def dynamic_server(temp_site):
57 args = ['python', 'runserver.py', temp_site] 59 args = ['python', 'runserver.py', temp_site]
58 # Werkzeug is a dependency of flask which we are using for the mock api 60 # Werkzeug is a dependency of flask which we are using for the mock api
59 # however there is an issue with Werkzeug that prevents it from properly 61 # however there is an issue with Werkzeug that prevents it from properly
60 # handling the SIGTERM sent by p.kill() or terminate() 62 # handling the SIGTERM sent by p.kill() or terminate()
61 # Issue: https://github.com/pallets/werkzeug/issues/58 63 # Issue: https://github.com/pallets/werkzeug/issues/58
62 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid) 64 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
63 time.sleep(0.5) 65 time.sleep(0.5)
64 yield 'http://localhost:5000/en/' 66 yield 'http://localhost:5000/'
65 os.killpg(os.getpgid(p.pid), signal.SIGTERM) 67 os.killpg(os.getpgid(p.pid), signal.SIGTERM)
66 68
67 69
68 @pytest.fixture(scope='session') 70 @pytest.fixture(scope='session')
69 def output_pages(static_output): 71 def output_pages(static_output):
70 return get_dir_contents(static_output) 72 return get_dir_contents(static_output)
71 73
72 74
73 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) 75 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs)
74 def test_static(output_pages, filename, expected_output): 76 def test_static(output_pages, filename, expected_output):
75 assert output_pages[filename] == expected_output 77 assert output_pages[filename] == expected_output
76 78
77 79
78 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) 80 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
79 def test_dynamic(dynamic_server, filename, expected_output): 81 def test_dynamic(dynamic_server, filename, expected_output):
80 response = urllib2.urlopen(dynamic_server + filename) 82 response = urllib2.urlopen(dynamic_server + filename)
81 assert response.read().strip() == expected_output 83 assert response.read().strip() == expected_output
82 84
83 85
84 def test_revision_arg(revision, output_pages): 86 def test_revision_arg(revision, output_pages):
85 if revision is None: 87 if revision is None:
86 assert 'bar' in output_pages 88 assert 'en/bar' in output_pages
87 else: 89 else:
88 assert 'bar' not in output_pages 90 assert 'en/bar' not in output_pages
OLDNEW
« no previous file with comments | « tests/expected_output/en/translate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld