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

Unified Diff: tests/utils.py

Issue 29555839: Issue 5336 - Allow additional include, page, and template paths using CMS (Closed)
Patch Set: Address comments on PS1 Created Sept. 27, 2017, 11:33 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/test_page_outputs.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/utils.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/utils.py
@@ -0,0 +1,49 @@
+# This file is part of the Adblock Plus web scripts,
+# Copyright (C) 2006-present eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import contextlib
+import os
+import signal
+import subprocess
+import time
+
+
+def get_dir_contents(path):
+ # TODO: This function is duplicated in test_page_outputs.py.
+ dirdata = {}
+ for dirpath, dirnames, filenames in os.walk(path):
+ for output_file in filenames:
+ filepath = os.path.join(dirpath, output_file)
+ with open(filepath) as f:
+ locale = os.path.split(os.path.split(filepath)[0])[1]
+ dirdata[os.path.join(locale, output_file)] = f.read().strip()
+ return dirdata
+
+
+@contextlib.contextmanager
+def run_test_server(site_path):
+ """Run test server, yield its URL. Terminate server on next iteration.
+
+ This function is intended be used in a pytest fixture.
+ """
+ args = ['python', 'runserver.py', site_path]
+ # Werkzeug is a dependency of flask which we are using for the mock api
+ # however there is an issue with Werkzeug that prevents it from properly
+ # handling the SIGTERM sent by p.kill() or terminate()
+ # Issue: https://github.com/pallets/werkzeug/issues/58
+ p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
+ time.sleep(0.5)
+ yield 'http://localhost:5000/'
+ os.killpg(os.getpgid(p.pid), signal.SIGTERM)
« no previous file with comments | « tests/test_page_outputs.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld