Skip to content

Commit

Permalink
Coverage and deprecated functions for test_ftpserver.py. Coverage for…
Browse files Browse the repository at this point in the history
… asynerror.py
  • Loading branch information
jamadden committed Oct 26, 2017
1 parent 2f11f6f commit 0627b81
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
29 changes: 10 additions & 19 deletions src/zope/server/ftp/tests/test_ftpserver.py
Expand Up @@ -44,9 +44,10 @@ def retrlines(ftpconn, cmd):
return ''.join(res)


class Tests(unittest.TestCase, AsyncoreErrorHook):
class Tests(AsyncoreErrorHook, unittest.TestCase):

def setUp(self):
super(Tests, self).setUp()
# Avoid the tests hanging for a long time if something goes wrong
socket.setdefaulttimeout(10)

Expand All @@ -59,7 +60,6 @@ def setUp(self):
# TODO tests should be more careful to clear the socket map.
asyncore.poll(0.1)
self.orig_map_size = len(asyncore.socket_map)
self.hook_asyncore_error()

root_dir = demofs.Directory()
root_dir['test'] = demofs.Directory()
Expand Down Expand Up @@ -90,7 +90,7 @@ def setUp(self):
self.thread.setDaemon(True)
self.thread.start()
self.thread_started.wait(10.0)
self.assert_(self.thread_started.isSet())
self.assertTrue(self.thread_started.isSet())

def tearDown(self):
self.run_loop = 0
Expand All @@ -108,7 +108,7 @@ def tearDown(self):
break
asyncore.poll(0.1)

self.unhook_asyncore_error()
super(Tests, self).tearDown()

def loop(self):
self.thread_started.set()
Expand All @@ -123,8 +123,8 @@ def loop(self):
continue
except select.error as data:
print("EXCEPTION POLLING IN LOOP(): %s" % data)
if data[0] == EBADF:
for key in asyncore.socket_map.keys():
if data.args[0] == EBADF:
for key in asyncore.socket_map:
print("")
try:
select.select([], [], [key], 0.0)
Expand Down Expand Up @@ -172,7 +172,7 @@ def execute(self, commands, login=1):
for command in commands:
ftp.send(command.encode('ascii') + b'\r\n')
result = ftp.recv(10000).decode('ascii')
self.failUnless(result.endswith('\r\n'))
self.assertTrue(result.endswith('\r\n'))
finally:
ftp.close()
return result
Expand Down Expand Up @@ -281,9 +281,9 @@ def testLIST(self):
conn.login('anonymous', 'bar')
self.assertRaises(ftplib.Error, retrlines, conn, 'LIST /foo')
listing = retrlines(conn, 'LIST')
self.assert_(len(listing) > 0)
self.assertGreater(len(listing), 0)
listing = retrlines(conn, 'LIST -la')
self.assert_(len(listing) > 0)
self.assertGreater(len(listing), 0)
finally:
conn.close()
# Make sure no garbage was left behind.
Expand All @@ -297,7 +297,7 @@ def testMKDLIST(self):
conn.login('foo', 'bar')
listing = []
conn.retrlines('LIST /test', listing.append)
self.assert_(len(listing) > 2)
self.assertGreaterEqual(len(listing), 2)
listing = []
conn.retrlines('LIST -lad test/f1', listing.append)
self.assertEqual(len(listing), 1)
Expand Down Expand Up @@ -382,12 +382,3 @@ def testUSER(self):
status_messages['PASS_REQUIRED'])
self.assertEqual(self.execute('USER', 0).rstrip(),
status_messages['ERR_ARGS'])



def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(Tests)

if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
2 changes: 1 addition & 1 deletion src/zope/server/tests/asyncerror.py
Expand Up @@ -35,7 +35,7 @@ def setUp(self):
self.hook_asyncore_error()

def tearDown(self):
self.unhook_asycnore_error()
self.unhook_asyncore_error()

def hook_asyncore_error(self):
self._asyncore_traceback = asyncore.compact_traceback
Expand Down
18 changes: 18 additions & 0 deletions src/zope/server/tests/test_asyncerror.py
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""
Tests for asyncerror.py
"""

import unittest
from zope.server.tests.asyncerror import AsyncoreErrorHook

class TestAsyncoreErrorHook(AsyncoreErrorHook,
unittest.TestCase):

def test_handle_asynore_error(self):
try:
raise Exception()
except Exception:
with self.assertRaises(AssertionError):
self.handle_asyncore_error()

0 comments on commit 0627b81

Please sign in to comment.