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: Implement get_canonical_url (according to updated ticket) Created July 28, 2017, 10:07 a.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()
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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