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

Side by Side Diff: tests/utils.py

Issue 29555839: Issue 5336 - Allow additional include, page, and template paths using CMS (Closed)
Patch Set: Address comments on PS2, improve docstring of create_source Created Sept. 28, 2017, 9 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
« cms/sources.py ('K') | « tests/test_page_outputs.py ('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
(Empty)
1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH
3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15
16 import contextlib
17 import os
18 import signal
19 import subprocess
20 import time
21
22
23 def get_dir_contents(path):
24 # TODO: This function is duplicated in test_page_outputs.py.
25 dirdata = {}
26 for dirpath, dirnames, filenames in os.walk(path):
27 for output_file in filenames:
28 filepath = os.path.join(dirpath, output_file)
29 with open(filepath) as f:
30 locale = os.path.split(os.path.split(filepath)[0])[1]
31 dirdata[os.path.join(locale, output_file)] = f.read().strip()
32 return dirdata
33
34
35 @contextlib.contextmanager
36 def run_test_server(site_path):
37 """Run test server, yield its URL. Terminate server on next iteration.
38
39 This function is intended be used in a pytest fixture.
40 """
41 args = ['python', 'runserver.py', site_path]
42 # Werkzeug is a dependency of flask which we are using for the mock api
43 # however there is an issue with Werkzeug that prevents it from properly
44 # handling the SIGTERM sent by p.kill() or terminate()
45 # Issue: https://github.com/pallets/werkzeug/issues/58
46 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
47 time.sleep(0.5)
48 yield 'http://localhost:5000/'
49 os.killpg(os.getpgid(p.pid), signal.SIGTERM)
OLDNEW
« cms/sources.py ('K') | « tests/test_page_outputs.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld