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

Delta Between Two Patch Sets: tests/utils.py

Issue 29912588: Issue 7019 - [CMS] Refactor `test_server.py` (Closed)
Left Patch Set: Simplified server waiting logic Created Oct. 29, 2018, 10:40 a.m.
Right Patch Set: Addressed docstring nit Created Oct. 29, 2018, 11 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/test_page_outputs.py ('k') | tox.ini » ('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 # 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 def _wait_for_server(): 75 def _wait_for_server():
76 """Test the server started by `run_test_server` and fail after 2s. 76 """Test the server started by `run_test_server` and fail after 2s.
77 77
78 Expects the server to be active at `http://localhost:5000/`. 78 Expects the server to be active at `http://localhost:5000/`.
79 79
80 Raises 80 Raises
81 ------ 81 ------
82 Exception 82 Exception
83 If the server is not running after retry-ing for 2 seconds. 83 If the server is not running after retry-ing for 2 seconds.
84 This will be the exception raised by 84 This will be the exception raised by `urllib2.urlopen`.
85 85
86 """ 86 """
87 start_time = time.time() 87 start_time = time.time()
88 88
89 while True: 89 while True:
90 try: 90 try:
91 urllib2.urlopen('http://localhost:5000/') 91 urllib2.urlopen('http://localhost:5000/')
92 break 92 break
93 except Exception: 93 except Exception:
94 time.sleep(.1) 94 time.sleep(.1)
(...skipping 25 matching lines...) Expand all
120 120
121 memory_zip.seek(0) 121 memory_zip.seek(0)
122 return memory_zip 122 return memory_zip
123 123
124 124
125 def exception_test(func, exception, exp_msg, *args, **kw): 125 def exception_test(func, exception, exp_msg, *args, **kw):
126 with pytest.raises(exception) as err: 126 with pytest.raises(exception) as err:
127 func(*args, **kw) 127 func(*args, **kw)
128 128
129 assert exp_msg in str(err.value) 129 assert exp_msg in str(err.value)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld