Skip to content

Commit 2e12e25

Browse files
committed
Minor code style clean-up after servlet import fix
1 parent 382970e commit 2e12e25

File tree

6 files changed

+60
-51
lines changed

6 files changed

+60
-51
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ variable-naming-style = camelCase
4646

4747
good-names =
4848
b, c, d, e, f, g, h, i, j, k, m, n, p, q, r, s, t, ,v, w, x, y,
49-
dt, fd, fp, fs, ip, tm, ts, wr,
49+
dt, fd, fp, fs, ip, ok, tm, ts, wr,
5050
dir_, id_, input_, type_,
5151
allow_none, entry_point, has_key, start_response, ssl_ctx,
5252
memcache, redis,

webware/Testing/ServletImport.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
2-
from Page import Page
31
import sys
42

5-
mod_name = __name__ # we expect Testing.ServletImport
3+
from SidebarPage import SidebarPage
4+
5+
modName = __name__ # should be Testing.ServletImport
6+
67

7-
class ServletImport(Page):
8-
"""Test of import details."""
8+
class ServletImport(SidebarPage):
9+
"""Test of servlet import details."""
910

10-
def title(self):
11-
return self.__doc__
11+
def cornerTitle(self):
12+
return 'Testing'
1213

13-
def writeBody(self):
14-
self.writeln('<h2>Webware Servlet Import Test</h2>')
15-
self.writeln(f'<h3>{self.title()}</h3>')
16-
mod_name_from_class = ServletImport.__module__ # we expect Testing.ServletImport
17-
mod_name_consistent = mod_name == mod_name_from_class # we expect True
18-
servlet_in_sys_modules = mod_name in sys.modules # we expect True
19-
servlet_file_watched = __file__ in self.transaction().application()._imp.fileList(update=False) # we expect True
20-
self.writeln(
21-
f"<p>mod_name = <code>{mod_name}</code></p>"
22-
f"<p>mod_name_from_class = <code>{mod_name_from_class}</code></p>"
23-
f"<p>mod_name_consistent = <code>{mod_name_consistent}</code></p>"
24-
f"<p>servlet_in_sys_modules = <code>{servlet_in_sys_modules}</code></p>"
25-
f"<p>servlet_file_watched = <code>{servlet_file_watched}</code></p>"
14+
def writeContent(self):
15+
wr = self.writeln
16+
wr('<h2>Webware Servlet Import Test</h2>')
17+
wr(f'<h3>{self.__doc__}</h3>')
18+
modNameFromClass = ServletImport.__module__
19+
modNameConsistent = modName == modNameFromClass
20+
servletInSysModules = modName in sys.modules
21+
app = self.transaction().application()
22+
files = app._imp.fileList(update=False)
23+
servletFileWatched = __file__ in files
24+
wr(
25+
f"<p>modName = <code>{modName}</code></p>"
26+
f"<p>modNameFromClass = <code>{modNameFromClass}</code></p>"
27+
f"<p>modNameConsistent = <code>{modNameConsistent}</code></p>"
28+
f"<p>servletInSysModules = <code>{servletInSysModules}</code></p>"
29+
f"<p>servletFileWatched = <code>{servletFileWatched}</code></p>"
2630
)
31+
ok = modNameConsistent and servletInSysModules and servletInSysModules
32+
wr('<p style="color:{}"><b>Servlet import test {}.</b></p>'.format(
33+
'green' if ok else 'red', 'passed' if ok else 'failed'))

webware/Testing/TestCases.data

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@
6161
# If-Modified-Since
6262
/Testing/TestIMS --> TestIMS passed
6363

64-
# ServletImport
65-
/Testing/ServletImport --> Servlet imported as part of package
64+
# Servlet import details
65+
/Testing/ServletImport --> Servlet import test passed

webware/Tests/TestEndToEnd/AppTest.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class AppTest:
1717
settings = dict(
1818
PrintConfigAtStartUp=False
1919
)
20-
bufferOutput = True # set to False if you want to run pdb inside a test to debug it.
20+
catchOutput = True # set to False if you want to run pdb inside a test
2121

2222
@classmethod
2323
def setUpClass(cls):
2424
stdout, stderr = sys.stdout, sys.stderr
25-
if cls.bufferOutput:
25+
if cls.catchOutput:
2626
sys.stdout = sys.stderr = StringIO()
2727
cls.currentDir = getcwd()
2828
import webware
@@ -37,7 +37,7 @@ def setUpClass(cls):
3737
else:
3838
error = None
3939
finally:
40-
if cls.bufferOutput:
40+
if cls.catchOutput:
4141
output = sys.stdout.getvalue().rstrip()
4242
sys.stdout, sys.stderr = stdout, stderr
4343
else:
@@ -46,46 +46,47 @@ def setUpClass(cls):
4646
raise RuntimeError(
4747
'Error setting up application:\n' + error +
4848
'\nOutput was:\n' + output)
49-
if cls.bufferOutput:
50-
if (not output.startswith('Webware for Python')
51-
or 'Running in development mode' not in output
52-
or 'Loading context' not in output):
53-
raise AssertionError(
54-
'Application was not properly started.'
55-
' Output was:\n' + output)
49+
if cls.catchOutput and not (
50+
output.startswith('Webware for Python')
51+
and 'Running in development mode' in output
52+
and 'Loading context' in output):
53+
raise AssertionError(
54+
'Application was not properly started.'
55+
' Output was:\n' + output)
5656

5757
@classmethod
5858
def tearDownClass(cls):
5959
stdout, stderr = sys.stdout, sys.stderr
60-
if cls.bufferOutput:
60+
if cls.catchOutput:
6161
sys.stdout = sys.stderr = StringIO()
6262
cls.app.shutDown()
63-
if cls.bufferOutput:
63+
if cls.catchOutput:
6464
output = sys.stdout.getvalue().rstrip()
6565
sys.stdout, sys.stderr = stdout, stderr
6666
else:
6767
output = ''
6868
chdir(cls.currentDir)
69-
if cls.bufferOutput and output != ('Application is shutting down...\n'
70-
'Application has been successfully shutdown.'):
69+
if cls.catchOutput and output != (
70+
'Application is shutting down...\n'
71+
'Application has been successfully shutdown.'):
7172
raise AssertionError(
7273
'Application was not properly shut down. Output was:\n'
7374
+ output)
7475

7576
def setUp(self):
7677
self.stdout, self.stderr = sys.stdout, sys.stderr
77-
if self.bufferOutput:
78+
if self.catchOutput:
7879
sys.stdout = sys.stderr = StringIO()
7980

8081
def tearDown(self):
81-
if self.bufferOutput:
82+
if self.catchOutput:
8283
self.output = sys.stdout.getvalue().rstrip()
8384
sys.stdout, sys.stderr = self.stdout, self.stderr
8485
else:
8586
self.output = ''
8687

8788
def run(self, result=None):
8889
result = super().run(result) # pylint: disable=no-member
89-
if not result.wasSuccessful() and self.bufferOutput and self.output:
90+
if not result.wasSuccessful() and self.output:
9091
print("Application output was:")
9192
print(self.output)

webware/Tests/TestEndToEnd/TestAdmin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,13 @@ def testAppControl(self):
232232
'Reload the selected Python modules. Be careful!',
233233
'<input type="checkbox" name="reloads"'
234234
' value="Admin.AdminPage"> Admin.AdminPage<br>')
235-
236-
# things change, so don't hardcode the index of this checkbox.
237-
for i, checkbox in enumerate(r.html.find_all('input', attrs={'name': 'reloads'})):
235+
for i, checkbox in enumerate(
236+
r.html.find_all('input', attrs={'name': 'reloads'})):
238237
if checkbox.attrs['value'] == 'Admin.AdminPage':
238+
r.form.get('reloads', index=i).checked = True
239239
break
240240
else:
241-
assert False, 'Did not find expected checkbox for Admin.AdminPage'
242-
r.form.get('reloads', index=i).checked = True
241+
self.fail('Did not find expected checkbox for Admin.AdminPage')
243242
r = r.form.submit('action', index=1)
244243
self.assertEqual(r.status, '200 OK')
245244
r.mustcontain(

webware/Tests/TestEndToEnd/TestTesting.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,17 @@ def testCase17(self):
259259
self.assertEqual(len(r.body), size)
260260

261261
def testCase18(self):
262-
url = self.getTestCaseUrl(18, 'Servlet imported as part of package')
262+
url = self.getTestCaseUrl(18, 'Servlet import test passed')
263263
r = self.testApp.get(url)
264264
self.assertEqual(r.status, '200 OK')
265265
r.mustcontain(
266-
'<title>Test of import details.</title>',
267-
'<p>mod_name = <code>Testing.ServletImport</code></p>',
268-
'<p>mod_name_from_class = <code>Testing.ServletImport</code></p>',
269-
f"<p>servlet_in_sys_modules = <code>True</code></p>",
270-
)
266+
'<title>ServletImport</title>',
267+
'<h2>Webware Servlet Import Test</h2>',
268+
'<h3>Test of servlet import details.</h3>',
269+
'<p>modName = <code>Testing.ServletImport</code></p>',
270+
'<p>modNameFromClass = <code>Testing.ServletImport</code></p>',
271+
'passed', no='failed')
272+
271273

272274
class TestTestingWithExtraPathInfo(TestTesting):
273275

0 commit comments

Comments
 (0)