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

Unified Diff: tests/test_page_outputs.py

Issue 29355396: Issue 4380 - Add Mock Crowdin API and Sync Test (Closed)
Patch Set: Created Sept. 30, 2016, 7:20 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
Index: tests/test_page_outputs.py
===================================================================
--- a/tests/test_page_outputs.py
+++ b/tests/test_page_outputs.py
@@ -1,18 +1,17 @@
import os
import sys
-import shutil
import time
import runpy
+import signal
import pytest
import urllib2
import subprocess
-
-ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+from conftest import ROOTPATH
def get_dir_contents(path):
return_data = {}
for dirpath, dirnames, filenames in os.walk(path):
for output_file in filenames:
with open(os.path.join(dirpath, output_file)) as f:
return_data[output_file] = f.read()
@@ -22,40 +21,34 @@
def get_expected_outputs():
expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output')
return get_dir_contents(expected_out_path).items()
expected_outputs = get_expected_outputs()
@pytest.fixture(scope='session')
-def temp_site(tmpdir_factory):
- out_dir = tmpdir_factory.mktemp('temp_out')
- site_dir = out_dir.join('test_site').strpath
-
- shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
- subprocess.check_call(['hg', 'init', site_dir])
- subprocess.check_call(['hg', '-R', site_dir, 'commit', '-A', '-m', 'foo'])
- return site_dir
-
-
-@pytest.fixture(scope='session')
def static_output(request, temp_site):
static_out_path = os.path.join(temp_site, 'static_out')
sys.argv = ['filler', temp_site, static_out_path]
runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
return static_out_path
-@pytest.yield_fixture(scope='session')
+@pytest.yield_fixture()
def dynamic_server(temp_site):
- p = subprocess.Popen(['python', 'runserver.py', temp_site])
Jon Sonesen 2016/09/30 07:28:01 There is a problem with Werkzeug (a dependency tha
+ args = ['python', 'runserver.py', temp_site]
+ # 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/root/'
- p.terminate()
+ os.killpg(os.getpgid(p.pid), signal.SIGTERM)
@pytest.fixture(scope='session')
def output_pages(static_output):
return get_dir_contents(static_output)
@pytest.mark.parametrize('filename,expected_output', expected_outputs)

Powered by Google App Engine
This is Rietveld