Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_asyncore.HelperFunctionTests Class Reference

List of all members.

Public Member Functions

def test_readwriteexc
def test_readwrite
def test_closeall
def test_closeall_default
def closeall_check
def test_compact_traceback

Public Attributes

 read
 write
 closed
 expt
 error_handled

Detailed Description

Definition at line 91 of file test_asyncore.py.


Member Function Documentation

Definition at line 187 of file test_asyncore.py.

00187 
00188     def closeall_check(self, usedefault):
00189         # Check that close_all() closes everything in a given map
00190 
00191         l = []
00192         testmap = {}
00193         for i in range(10):
00194             c = dummychannel()
00195             l.append(c)
00196             self.assertEqual(c.socket.closed, False)
00197             testmap[i] = c
00198 
00199         if usedefault:
00200             socketmap = asyncore.socket_map
00201             try:
00202                 asyncore.socket_map = testmap
00203                 asyncore.close_all()
00204             finally:
00205                 testmap, asyncore.socket_map = asyncore.socket_map, socketmap
00206         else:
00207             asyncore.close_all(testmap)
00208 
00209         self.assertEqual(len(testmap), 0)
00210 
00211         for c in l:
00212             self.assertEqual(c.socket.closed, True)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 181 of file test_asyncore.py.

00181 
00182     def test_closeall(self):
00183         self.closeall_check(False)

Here is the call graph for this function:

Definition at line 184 of file test_asyncore.py.

00184 
00185     def test_closeall_default(self):
00186         self.closeall_check(True)

Here is the call graph for this function:

Definition at line 213 of file test_asyncore.py.

00213 
00214     def test_compact_traceback(self):
00215         try:
00216             raise Exception("I don't like spam!")
00217         except:
00218             real_t, real_v, real_tb = sys.exc_info()
00219             r = asyncore.compact_traceback()
00220         else:
00221             self.fail("Expected exception")
00222 
00223         (f, function, line), t, v, info = r
00224         self.assertEqual(os.path.split(f)[-1], 'test_asyncore.py')
00225         self.assertEqual(function, 'test_compact_traceback')
00226         self.assertEqual(t, real_t)
00227         self.assertEqual(v, real_v)
00228         self.assertEqual(info, '[%s|%s|%s]' % (f, function, line))
00229 

Here is the call graph for this function:

Definition at line 122 of file test_asyncore.py.

00122 
00123     def test_readwrite(self):
00124         # Check that correct methods are called by readwrite()
00125 
00126         attributes = ('read', 'expt', 'write', 'closed', 'error_handled')
00127 
00128         expected = (
00129             (select.POLLIN, 'read'),
00130             (select.POLLPRI, 'expt'),
00131             (select.POLLOUT, 'write'),
00132             (select.POLLERR, 'closed'),
00133             (select.POLLHUP, 'closed'),
00134             (select.POLLNVAL, 'closed'),
00135             )
00136 
00137         class testobj:
00138             def __init__(self):
00139                 self.read = False
00140                 self.write = False
00141                 self.closed = False
00142                 self.expt = False
00143                 self.error_handled = False
00144 
00145             def handle_read_event(self):
00146                 self.read = True
00147 
00148             def handle_write_event(self):
00149                 self.write = True
00150 
00151             def handle_close(self):
00152                 self.closed = True
00153 
00154             def handle_expt_event(self):
00155                 self.expt = True
00156 
00157             def handle_error(self):
00158                 self.error_handled = True
00159 
00160         for flag, expectedattr in expected:
00161             tobj = testobj()
00162             self.assertEqual(getattr(tobj, expectedattr), False)
00163             asyncore.readwrite(tobj, flag)
00164 
00165             # Only the attribute modified by the routine we expect to be
00166             # called should be True.
00167             for attr in attributes:
00168                 self.assertEqual(getattr(tobj, attr), attr==expectedattr)
00169 
00170             # check that ExitNow exceptions in the object handler method
00171             # bubbles all the way up through asyncore readwrite call
00172             tr1 = exitingdummy()
00173             self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag)
00174 
00175             # check that an exception other than ExitNow in the object handler
00176             # method causes the handle_error method to get called
00177             tr2 = crashingdummy()
00178             self.assertEqual(tr2.error_handled, False)
00179             asyncore.readwrite(tr2, flag)
00180             self.assertEqual(tr2.error_handled, True)

Here is the call graph for this function:

Definition at line 92 of file test_asyncore.py.

00092 
00093     def test_readwriteexc(self):
00094         # Check exception handling behavior of read, write and _exception
00095 
00096         # check that ExitNow exceptions in the object handler method
00097         # bubbles all the way up through asyncore read/write/_exception calls
00098         tr1 = exitingdummy()
00099         self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
00100         self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
00101         self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
00102 
00103         # check that an exception other than ExitNow in the object handler
00104         # method causes the handle_error method to get called
00105         tr2 = crashingdummy()
00106         asyncore.read(tr2)
00107         self.assertEqual(tr2.error_handled, True)
00108 
00109         tr2 = crashingdummy()
00110         asyncore.write(tr2)
00111         self.assertEqual(tr2.error_handled, True)
00112 
00113         tr2 = crashingdummy()
00114         asyncore._exception(tr2)
00115         self.assertEqual(tr2.error_handled, True)

Here is the call graph for this function:


Member Data Documentation

Definition at line 140 of file test_asyncore.py.

Definition at line 142 of file test_asyncore.py.

Definition at line 141 of file test_asyncore.py.

Definition at line 138 of file test_asyncore.py.

Definition at line 139 of file test_asyncore.py.


The documentation for this class was generated from the following file: