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

Side by Side Diff: tests/utils.py

Issue 29912588: Issue 7019 - [CMS] Refactor `test_server.py` (Closed)
Patch Set: Created Oct. 16, 2018, 11:42 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
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 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 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 29 matching lines...) Expand all
40 def run_test_server(site_path): 40 def run_test_server(site_path):
41 """Run test server, yield its URL. Terminate server on next iteration. 41 """Run test server, yield its URL. Terminate server on next iteration.
42 42
43 This function is intended be used in a pytest fixture. 43 This function is intended be used in a pytest fixture.
44 """ 44 """
45 args = ['python', 'runserver.py', site_path] 45 args = ['python', 'runserver.py', site_path]
46 # Werkzeug is a dependency of flask which we are using for the mock api 46 # Werkzeug is a dependency of flask which we are using for the mock api
47 # however there is an issue with Werkzeug that prevents it from properly 47 # however there is an issue with Werkzeug that prevents it from properly
48 # handling the SIGTERM sent by p.kill() or terminate() 48 # handling the SIGTERM sent by p.kill() or terminate()
49 # Issue: https://github.com/pallets/werkzeug/issues/58 49 # Issue: https://github.com/pallets/werkzeug/issues/58
50
Vasily Kuznetsov 2018/10/16 13:18:23 This looks kind of unrelated. Probably better remo
Tudor Avram 2018/10/18 13:44:05 Done.
50 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid) 51 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
51 time.sleep(0.5) 52 time.sleep(0.5)
52 yield 'http://localhost:5000/' 53 yield 'http://localhost:5000/'
53 os.killpg(os.getpgid(p.pid), signal.SIGTERM) 54 os.killpg(os.getpgid(p.pid), signal.SIGTERM)
54 55
55 56
56 def create_in_memory_zip(file_names, file_data): 57 def create_in_memory_zip(file_names, file_data):
57 """Create a BytesIO object with the contents of a zip file. 58 """Create a BytesIO object with the contents of a zip file.
58 59
59 Parameters 60 Parameters
(...skipping 17 matching lines...) Expand all
77 78
78 memory_zip.seek(0) 79 memory_zip.seek(0)
79 return memory_zip 80 return memory_zip
80 81
81 82
82 def exception_test(func, exception, exp_msg, *args, **kw): 83 def exception_test(func, exception, exp_msg, *args, **kw):
83 with pytest.raises(exception) as err: 84 with pytest.raises(exception) as err:
84 func(*args, **kw) 85 func(*args, **kw)
85 86
86 assert exp_msg in str(err.value) 87 assert exp_msg in str(err.value)
OLDNEW

Powered by Google App Engine
This is Rietveld