You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 7, 2023. It is now read-only.
# Select an unused port for serving web pages to the test suite.
17
-
PORT='8081'
37
+
PORT="8081"
38
+
# Use the localhost for testing.
39
+
HOST="http://127.0.0.1:"+PORT
18
40
19
41
20
42
# Provide access to the currently-active ModuleFixture object.
@@ -23,25 +45,32 @@
23
45
24
46
# Define `module fixtures <https://docs.python.org/2/library/unittest.html#setupmodule-and-teardownmodule>`_ to build the test Runestone project, run the server, then shut it down when the tests complete.
25
47
classModuleFixture(unittest.TestCase):
26
-
def__init__(self,
48
+
def__init__(
49
+
self,
27
50
# The path to the Python module in which the test resides. This provides a simple way to determine the path in which to run runestone build/serve.
28
51
module_path,
29
52
# True if the sphinx-build process must exit with status of 0 (success)
pytest.exit("Unknown error while trying to kill stale runestone server")
72
101
73
102
# Run the server. Simply calling ``runestone serve`` fails, since the process killed isn't the actual server, but probably a setuptools-created launcher.
# Testing time in dominated by browser startup/shutdown. So, simply run all tests in a module in a single browser instance to speed things up. See ``RunestoneTestCase.setUp`` for additional code to (mostly) clear the browser between tests.
77
108
#
78
109
# `PyVirtualDisplay <http://pyvirtualdisplay.readthedocs.io/en/latest/>`_ only runs on X-windows, meaning Linux. Mac seems to have `some support <https://support.apple.com/en-us/HT201341>`_. Windows is out of the question.
#self.driver = webdriver.PhantomJS() # use this for Jenkins auto testing
115
+
#self.driver = webdriver.PhantomJS() # use this for Jenkins auto testing
85
116
options=Options()
86
117
options.add_argument("--window-size=1200,800")
87
118
options.add_argument("--no-sandbox")
@@ -91,6 +122,17 @@ def setUpModule(self):
91
122
globalmf
92
123
mf=self
93
124
125
+
# Wait for the webserver to come up.
126
+
fortriesinrange(50):
127
+
try:
128
+
urlopen(HOST, timeout=5)
129
+
exceptURLError:
130
+
# Wait for the server to come up.
131
+
time.sleep(0.1)
132
+
else:
133
+
# The server is up. We're done.
134
+
break
135
+
94
136
deftearDownModule(self):
95
137
# Shut down Selenium.
96
138
self.driver.quit()
@@ -117,6 +159,7 @@ def tearDownModule(self):
117
159
defrunTest(self):
118
160
pass
119
161
162
+
120
163
# Provide a simple way to instantiante a ModuleFixture in a test module. Typical use:
121
164
#
122
165
# .. code:: Python
@@ -137,10 +180,10 @@ class RunestoneTestCase(unittest.TestCase):
137
180
defsetUp(self):
138
181
# Use the shared module-wide driver.
139
182
self.driver=mf.driver
140
-
self.host='http://127.0.0.1:'+PORT
183
+
self.host=HOST
141
184
142
185
deftearDown(self):
143
186
# Clear as much as possible, to present an almost-fresh instance of a browser for the next test. (Shutting down then starting up a browswer is very slow.)
0 commit comments