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.
11
-
PORT='8081'
32
+
PORT="8081"
33
+
# Use the localhost for testing.
34
+
HOST="http://127.0.0.1:"+PORT
12
35
13
36
14
37
# Provide access to the currently-active ModuleFixture object.
@@ -17,41 +40,50 @@
17
40
18
41
# 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.
19
42
classModuleFixture(unittest.TestCase):
20
-
def__init__(self,
43
+
def__init__(
44
+
self,
21
45
# 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.
22
46
module_path,
23
47
# True if the sphinx-build process must exit with status of 0 (success)
# 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.
47
79
#
48
80
# `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
86
+
#self.driver = webdriver.PhantomJS() # use this for Jenkins auto testing
55
87
options=Options()
56
88
options.add_argument("--window-size=1200,800")
57
89
self.driver=webdriver.Chrome(chrome_options=options) # good for development.
@@ -60,6 +92,17 @@ def setUpModule(self):
60
92
globalmf
61
93
mf=self
62
94
95
+
# Wait for the webserver to come up.
96
+
fortriesinrange(50):
97
+
try:
98
+
urlopen(HOST, timeout=5)
99
+
exceptURLError:
100
+
# Wait for the server to come up.
101
+
time.sleep(0.1)
102
+
else:
103
+
# The server is up. We're done.
104
+
break
105
+
63
106
deftearDownModule(self):
64
107
# Shut down Selenium.
65
108
self.driver.quit()
@@ -86,6 +129,7 @@ def tearDownModule(self):
86
129
defrunTest(self):
87
130
pass
88
131
132
+
89
133
# Provide a simple way to instantiante a ModuleFixture in a test module. Typical use:
90
134
#
91
135
# .. code:: Python
@@ -106,10 +150,10 @@ class RunestoneTestCase(unittest.TestCase):
106
150
defsetUp(self):
107
151
# Use the shared module-wide driver.
108
152
self.driver=mf.driver
109
-
self.host='http://127.0.0.1:'+PORT
153
+
self.host=HOST
110
154
111
155
deftearDown(self):
112
156
# 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