Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes
test.test_mailbox.TestMbox Class Reference
Inheritance diagram for test.test_mailbox.TestMbox:
Inheritance graph
[legend]
Collaboration diagram for test.test_mailbox.TestMbox:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_file_perms
def tearDown
def assertMailboxEmpty
def test_add_from_string
def test_add_from_bytes
def test_add_mbox_or_mmdf_message
def test_open_close_open
def test_add_and_close
def test_lock_conflict
def test_relock
def setUp
def test_add
def test_add_invalid_8bit_bytes_header
def test_invalid_nonascii_header_as_string
def test_add_nonascii_string_header_raises
def test_add_that_raises_leaves_mailbox_empty
def test_add_8bit_body
def test_add_binary_file
def test_add_binary_nonascii_file
def test_add_text_file_warns
def test_add_StringIO_warns
def test_add_nonascii_StringIO_raises
def test_remove
def test_delitem
def test_discard
def test_get
def test_getitem
def test_get_message
def test_get_bytes
def test_get_string
def test_get_file
def test_get_file_can_be_closed_twice
def test_iterkeys
def test_keys
def test_itervalues
def test_iter
def test_values
def test_iteritems
def test_items
def test_contains
def test_len
def test_set_item
def test_clear
def test_pop
def test_popitem
def test_update
def test_flush
def test_lock_unlock
def test_close
def test_dump_message

Static Public Attributes

 maxDiff = None

Private Attributes

 _box

Static Private Attributes

tuple _factory = lambdaself,path,factoryNone:mailbox.mbox(path, factory)

Detailed Description

Definition at line 1014 of file test_mailbox.py.


Member Function Documentation

Definition at line 920 of file test_mailbox.py.

00920 
00921     def assertMailboxEmpty(self):
00922         with open(self._path) as f:
00923             self.assertEqual(f.readlines(), [])

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_mailbox.TestMailbox.setUp (   self) [inherited]

Reimplemented in test.test_mailbox.TestMaildir.

Definition at line 58 of file test_mailbox.py.

00058 
00059     def setUp(self):
00060         self._path = support.TESTFN
00061         self._delete_recursively(self._path)
00062         self._box = self._factory(self._path)

Here is the caller graph for this function:

def test.test_mailbox._TestMboxMMDF.tearDown (   self) [inherited]

Reimplemented from test.test_mailbox.TestMailbox.

Definition at line 913 of file test_mailbox.py.

00913 
00914     def tearDown(self):
00915         super().tearDown()
00916         self._box.close()
00917         self._delete_recursively(self._path)
00918         for lock_remnant in glob.glob(self._path + '.*'):
00919             support.unlink(lock_remnant)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_mailbox.TestMailbox.test_add (   self) [inherited]

Definition at line 67 of file test_mailbox.py.

00067 
00068     def test_add(self):
00069         # Add copies of a sample message
00070         keys = []
00071         keys.append(self._box.add(self._template % 0))
00072         self.assertEqual(len(self._box), 1)
00073         keys.append(self._box.add(mailbox.Message(_sample_message)))
00074         self.assertEqual(len(self._box), 2)
00075         keys.append(self._box.add(email.message_from_string(_sample_message)))
00076         self.assertEqual(len(self._box), 3)
00077         keys.append(self._box.add(io.BytesIO(_bytes_sample_message)))
00078         self.assertEqual(len(self._box), 4)
00079         keys.append(self._box.add(_sample_message))
00080         self.assertEqual(len(self._box), 5)
00081         keys.append(self._box.add(_bytes_sample_message))
00082         self.assertEqual(len(self._box), 6)
00083         with self.assertWarns(DeprecationWarning):
00084             keys.append(self._box.add(
00085                 io.TextIOWrapper(io.BytesIO(_bytes_sample_message))))
00086         self.assertEqual(len(self._box), 7)
00087         self.assertEqual(self._box.get_string(keys[0]), self._template % 0)
00088         for i in (1, 2, 3, 4, 5, 6):
00089             self._check_sample(self._box[keys[i]])

Here is the call graph for this function:

Definition at line 139 of file test_mailbox.py.

00139 
00140     def test_add_8bit_body(self):
00141         key = self._box.add(self._non_latin_bin_msg)
00142         self.assertEqual(self._box.get_bytes(key),
00143                          self._non_latin_bin_msg)
00144         with self._box.get_file(key) as f:
00145             self.assertEqual(f.read(),
00146                              self._non_latin_bin_msg.replace(b'\n',
00147                                 os.linesep.encode()))
00148         self.assertEqual(self._box[key].get_payload(),
00149                         "Да, они летят.\n")

Here is the call graph for this function:

Definition at line 956 of file test_mailbox.py.

00956 
00957     def test_add_and_close(self):
00958         # Verifying that closing a mailbox doesn't change added items
00959         self._box.add(_sample_message)
00960         for i in range(3):
00961             self._box.add(self._template % i)
00962         self._box.add(_sample_message)
00963         self._box._file.flush()
00964         self._box._file.seek(0)
00965         contents = self._box._file.read()
00966         self._box.close()
00967         with open(self._path, 'rb') as f:
00968             self.assertEqual(contents, f.read())
00969         self._box = self._factory(self._path)

Here is the call graph for this function:

Definition at line 150 of file test_mailbox.py.

00150 
00151     def test_add_binary_file(self):
00152         with tempfile.TemporaryFile('wb+') as f:
00153             f.write(_bytes_sample_message)
00154             f.seek(0)
00155             key = self._box.add(f)
00156         # See issue 11062
00157         if not isinstance(self._box, mailbox.Babyl):
00158             self.assertEqual(self._box.get_bytes(key).split(b'\n'),
00159                 _bytes_sample_message.split(b'\n'))

Here is the call graph for this function:

Definition at line 160 of file test_mailbox.py.

00160 
00161     def test_add_binary_nonascii_file(self):
00162         with tempfile.TemporaryFile('wb+') as f:
00163             f.write(self._non_latin_bin_msg)
00164             f.seek(0)
00165             key = self._box.add(f)
00166         # See issue 11062
00167         if not isinstance(self._box, mailbox.Babyl):
00168             self.assertEqual(self._box.get_bytes(key).split(b'\n'),
00169                 self._non_latin_bin_msg.split(b'\n'))

Here is the call graph for this function:

Definition at line 930 of file test_mailbox.py.

00930 
00931     def test_add_from_bytes(self):
00932         # Add a byte string starting with 'From ' to the mailbox
00933         key = self._box.add(b'From foo@bar blah\nFrom: foo\n\n0')
00934         self.assertEqual(self._box[key].get_from(), 'foo@bar blah')
00935         self.assertEqual(self._box[key].get_payload(), '0')

Here is the call graph for this function:

Definition at line 924 of file test_mailbox.py.

00924 
00925     def test_add_from_string(self):
00926         # Add a string starting with 'From ' to the mailbox
00927         key = self._box.add('From foo@bar blah\nFrom: foo\n\n0')
00928         self.assertEqual(self._box[key].get_from(), 'foo@bar blah')
00929         self.assertEqual(self._box[key].get_payload(), '0')

Here is the call graph for this function:

Definition at line 97 of file test_mailbox.py.

00097 
00098     def test_add_invalid_8bit_bytes_header(self):
00099         key = self._box.add(self._nonascii_msg.encode('latin1'))
00100         self.assertEqual(len(self._box), 1)
00101         self.assertEqual(self._box.get_bytes(key),
00102             self._nonascii_msg.encode('latin1'))

Here is the call graph for this function:

Definition at line 936 of file test_mailbox.py.

00936 
00937     def test_add_mbox_or_mmdf_message(self):
00938         # Add an mboxMessage or MMDFMessage
00939         for class_ in (mailbox.mboxMessage, mailbox.MMDFMessage):
00940             msg = class_('From foo@bar blah\nFrom: foo\n\n0')
00941             key = self._box.add(msg)

Definition at line 110 of file test_mailbox.py.

00110 
00111     def test_add_nonascii_string_header_raises(self):
00112         with self.assertRaisesRegex(ValueError, "ASCII-only"):
00113             self._box.add(self._nonascii_msg)
00114         self._box.flush()
00115         self.assertEqual(len(self._box), 0)
00116         self.assertMailboxEmpty()

Here is the call graph for this function:

Definition at line 186 of file test_mailbox.py.

00186 
00187     def test_add_nonascii_StringIO_raises(self):
00188         with self.assertWarns(DeprecationWarning):
00189             with self.assertRaisesRegex(ValueError, "ASCII-only"):
00190                 self._box.add(io.StringIO(self._nonascii_msg))
00191         self.assertEqual(len(self._box), 0)
00192         self._box.close()
00193         self.assertMailboxEmpty()

Here is the call graph for this function:

Definition at line 181 of file test_mailbox.py.

00181 
00182     def test_add_StringIO_warns(self):
00183         with self.assertWarns(DeprecationWarning):
00184             key = self._box.add(io.StringIO(self._template % "0"))
00185         self.assertEqual(self._box.get_string(key), self._template % "0")

Here is the call graph for this function:

Definition at line 170 of file test_mailbox.py.

00170 
00171     def test_add_text_file_warns(self):
00172         with tempfile.TemporaryFile('w+') as f:
00173             f.write(_sample_message)
00174             f.seek(0)
00175             with self.assertWarns(DeprecationWarning):
00176                 key = self._box.add(f)
00177         # See issue 11062
00178         if not isinstance(self._box, mailbox.Babyl):
00179             self.assertEqual(self._box.get_bytes(key).split(b'\n'),
00180                 _bytes_sample_message.split(b'\n'))

Here is the call graph for this function:

Definition at line 117 of file test_mailbox.py.

00117 
00118     def test_add_that_raises_leaves_mailbox_empty(self):
00119         # XXX This test will start failing when Message learns to handle
00120         # non-ASCII string headers, and a different internal failure will
00121         # need to be found or manufactured.
00122         with self.assertRaises(ValueError):
00123             self._box.add(email.message_from_string("From: Alphöso"))
00124         self.assertEqual(len(self._box), 0)
00125         self._box.close()
00126         self.assertMailboxEmpty()

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_clear (   self,
  iterations = 10 
) [inherited]

Definition at line 423 of file test_mailbox.py.

00423 
00424     def test_clear(self, iterations=10):
00425         # Remove all messages using clear()
00426         keys = []
00427         for i in range(iterations):
00428             self._box.add(self._template % i)
00429         for i, key in enumerate(keys):
00430             self.assertEqual(self._box.get_string(key), self._template % i)
00431         self._box.clear()
00432         self.assertEqual(len(self._box), 0)
00433         for i, key in enumerate(keys):
00434             self.assertRaises(KeyError, lambda: self._box.get_string(key))

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_close (   self) [inherited]

Definition at line 515 of file test_mailbox.py.

00515 
00516     def test_close(self):
00517         # Close mailbox and flush changes to disk
00518         self._test_flush_or_close(self._box.close, False)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_contains (   self) [inherited]

Definition at line 365 of file test_mailbox.py.

00365 
00366     def test_contains(self):
00367         # Check existence of keys using __contains__()
00368         self.assertNotIn('foo', self._box)
00369         key0 = self._box.add(self._template % 0)
00370         self.assertIn(key0, self._box)
00371         self.assertNotIn('foo', self._box)
00372         key1 = self._box.add(self._template % 1)
00373         self.assertIn(key1, self._box)
00374         self.assertIn(key0, self._box)
00375         self.assertNotIn('foo', self._box)
00376         self._box.remove(key0)
00377         self.assertNotIn(key0, self._box)
00378         self.assertIn(key1, self._box)
00379         self.assertNotIn('foo', self._box)
00380         self._box.remove(key1)
00381         self.assertNotIn(key1, self._box)
00382         self.assertNotIn(key0, self._box)
00383         self.assertNotIn('foo', self._box)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_delitem (   self) [inherited]

Definition at line 198 of file test_mailbox.py.

00198 
00199     def test_delitem(self):
00200         # Remove messages using __delitem__()
00201         self._test_remove_or_delitem(self._box.__delitem__)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_discard (   self,
  repetitions = 10 
) [inherited]

Definition at line 224 of file test_mailbox.py.

00224 
00225     def test_discard(self, repetitions=10):
00226         # Discard messages
00227         key0 = self._box.add(self._template % 0)
00228         key1 = self._box.add(self._template % 1)
00229         self.assertEqual(len(self._box), 2)
00230         self._box.discard(key0)
00231         self.assertEqual(len(self._box), 1)
00232         self.assertRaises(KeyError, lambda: self._box[key0])
00233         self._box.discard(key0)
00234         self.assertEqual(len(self._box), 1)
00235         self.assertRaises(KeyError, lambda: self._box[key0])

Here is the call graph for this function:

Definition at line 535 of file test_mailbox.py.

00535 
00536     def test_dump_message(self):
00537         # Write message representations to disk
00538         for input in (email.message_from_string(_sample_message),
00539                       _sample_message, io.BytesIO(_bytes_sample_message)):
00540             output = io.BytesIO()
00541             self._box._dump_message(input, output)
00542             self.assertEqual(output.getvalue(),
00543                 _bytes_sample_message.replace(b'\n', os.linesep.encode()))
00544         output = io.BytesIO()
00545         self.assertRaises(TypeError,
00546                           lambda: self._box._dump_message(None, output))

Here is the call graph for this function:

Definition at line 1018 of file test_mailbox.py.

01018 
01019     def test_file_perms(self):
01020         # From bug #3228, we want to verify that the mailbox file isn't executable,
01021         # even if the umask is set to something that would leave executable bits set.
01022         # We only run this test on platforms that support umask.
01023         if hasattr(os, 'umask') and hasattr(os, 'stat'):
01024             try:
01025                 old_umask = os.umask(0o077)
01026                 self._box.close()
01027                 os.unlink(self._path)
01028                 self._box = mailbox.mbox(self._path, create=True)
01029                 self._box.add('')
01030                 self._box.close()
01031             finally:
01032                 os.umask(old_umask)
01033 
01034             st = os.stat(self._path)
01035             perms = st.st_mode
01036             self.assertFalse((perms & 0o111)) # Execute bits should all be off.

def test.test_mailbox.TestMailbox.test_flush (   self) [inherited]

Definition at line 503 of file test_mailbox.py.

00503 
00504     def test_flush(self):
00505         # Write changes to disk
00506         self._test_flush_or_close(self._box.flush, True)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_get (   self) [inherited]

Definition at line 236 of file test_mailbox.py.

00236 
00237     def test_get(self):
00238         # Retrieve messages using get()
00239         key0 = self._box.add(self._template % 0)
00240         msg = self._box.get(key0)
00241         self.assertEqual(msg['from'], 'foo')
00242         self.assertEqual(msg.get_payload(), '0')
00243         self.assertIs(self._box.get('foo'), None)
00244         self.assertIs(self._box.get('foo', False), False)
00245         self._box.close()
00246         self._box = self._factory(self._path)
00247         key1 = self._box.add(self._template % 1)
00248         msg = self._box.get(key1)
00249         self.assertEqual(msg['from'], 'foo')
00250         self.assertEqual(msg.get_payload(), '1')

Here is the call graph for this function:

Definition at line 271 of file test_mailbox.py.

00271 
00272     def test_get_bytes(self):
00273         # Get bytes representations of messages
00274         key0 = self._box.add(self._template % 0)
00275         key1 = self._box.add(_sample_message)
00276         self.assertEqual(self._box.get_bytes(key0),
00277             (self._template % 0).encode('ascii'))
00278         self.assertEqual(self._box.get_bytes(key1), _bytes_sample_message)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_get_file (   self) [inherited]

Definition at line 287 of file test_mailbox.py.

00287 
00288     def test_get_file(self):
00289         # Get file representations of messages
00290         key0 = self._box.add(self._template % 0)
00291         key1 = self._box.add(_sample_message)
00292         with self._box.get_file(key0) as file:
00293             data0 = file.read()
00294         with self._box.get_file(key1) as file:
00295             data1 = file.read()
00296         self.assertEqual(data0.decode('ascii').replace(os.linesep, '\n'),
00297                          self._template % 0)
00298         self.assertEqual(data1.decode('ascii').replace(os.linesep, '\n'),
00299                          _sample_message)

Here is the call graph for this function:

Definition at line 300 of file test_mailbox.py.

00300 
00301     def test_get_file_can_be_closed_twice(self):
00302         # Issue 11700
00303         key = self._box.add(_sample_message)
00304         f = self._box.get_file(key)
00305         f.close()
00306         f.close()

Definition at line 261 of file test_mailbox.py.

00261 
00262     def test_get_message(self):
00263         # Get Message representations of messages
00264         key0 = self._box.add(self._template % 0)
00265         key1 = self._box.add(_sample_message)
00266         msg0 = self._box.get_message(key0)
00267         self.assertIsInstance(msg0, mailbox.Message)
00268         self.assertEqual(msg0['from'], 'foo')
00269         self.assertEqual(msg0.get_payload(), '0')
00270         self._check_sample(self._box.get_message(key1))

Here is the call graph for this function:

Definition at line 279 of file test_mailbox.py.

00279 
00280     def test_get_string(self):
00281         # Get string representations of messages
00282         key0 = self._box.add(self._template % 0)
00283         key1 = self._box.add(_sample_message)
00284         self.assertEqual(self._box.get_string(key0), self._template % 0)
00285         self.assertEqual(self._box.get_string(key1).split('\n'),
00286                          _sample_message.split('\n'))

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_getitem (   self) [inherited]

Definition at line 251 of file test_mailbox.py.

00251 
00252     def test_getitem(self):
00253         # Retrieve message using __getitem__()
00254         key0 = self._box.add(self._template % 0)
00255         msg = self._box[key0]
00256         self.assertEqual(msg['from'], 'foo')
00257         self.assertEqual(msg.get_payload(), '0')
00258         self.assertRaises(KeyError, lambda: self._box['foo'])
00259         self._box.discard(key0)
00260         self.assertRaises(KeyError, lambda: self._box[key0])

Here is the call graph for this function:

Definition at line 103 of file test_mailbox.py.

00103 
00104     def test_invalid_nonascii_header_as_string(self):
00105         subj = self._nonascii_msg.splitlines()[1]
00106         key = self._box.add(subj.encode('latin1'))
00107         self.assertEqual(self._box.get_string(key),
00108             'Subject: =?unknown-8bit?b?RmFsaW5hcHThciBo4Xpob3pzeuFsbO104XNz'
00109             'YWwuIE3hciByZW5kZWx06Ww/?=\n\n')

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_items (   self) [inherited]

Definition at line 334 of file test_mailbox.py.

00334 
00335     def test_items(self):
00336         # Get keys and values using items()
00337         self._check_iteration(self._box.items, do_keys=True, do_values=True)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_iter (   self) [inherited]

Definition at line 320 of file test_mailbox.py.

00320 
00321     def test_iter(self):
00322         # Get values using __iter__()
00323         self._check_iteration(self._box.__iter__, do_keys=False,
00324                               do_values=True)

Here is the call graph for this function:

Definition at line 329 of file test_mailbox.py.

00329 
00330     def test_iteritems(self):
00331         # Get keys and values using iteritems()
00332         self._check_iteration(self._box.items, do_keys=True,
00333                               do_values=True)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_iterkeys (   self) [inherited]

Definition at line 307 of file test_mailbox.py.

00307 
00308     def test_iterkeys(self):
00309         # Get keys using iterkeys()
00310         self._check_iteration(self._box.keys, do_keys=True, do_values=False)

Here is the call graph for this function:

Definition at line 315 of file test_mailbox.py.

00315 
00316     def test_itervalues(self):
00317         # Get values using itervalues()
00318         self._check_iteration(self._box.values, do_keys=False,
00319                               do_values=True)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_keys (   self) [inherited]

Definition at line 311 of file test_mailbox.py.

00311 
00312     def test_keys(self):
00313         # Get keys using keys()
00314         self._check_iteration(self._box.keys, do_keys=True, do_values=False)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_len (   self,
  repetitions = 10 
) [inherited]

Definition at line 384 of file test_mailbox.py.

00384 
00385     def test_len(self, repetitions=10):
00386         # Get message count
00387         keys = []
00388         for i in range(repetitions):
00389             self.assertEqual(len(self._box), i)
00390             keys.append(self._box.add(self._template % i))
00391             self.assertEqual(len(self._box), i + 1)
00392         for i in range(repetitions):
00393             self.assertEqual(len(self._box), repetitions - i)
00394             self._box.remove(keys[i])
00395             self.assertEqual(len(self._box), repetitions - i - 1)

Here is the call graph for this function:

Definition at line 970 of file test_mailbox.py.

00970 
00971     def test_lock_conflict(self):
00972         # Fork off a subprocess that will lock the file for 2 seconds,
00973         # unlock it, and then exit.
00974         if not hasattr(os, 'fork'):
00975             return
00976         pid = os.fork()
00977         if pid == 0:
00978             # In the child, lock the mailbox.
00979             try:
00980                 self._box.lock()
00981                 time.sleep(2)
00982                 self._box.unlock()
00983             finally:
00984                 os._exit(0)
00985 
00986         # In the parent, sleep a bit to give the child time to acquire
00987         # the lock.
00988         time.sleep(0.5)
00989         try:
00990             self.assertRaises(mailbox.ExternalClashError,
00991                               self._box.lock)
00992         finally:
00993             # Wait for child to exit.  Locking should now succeed.
00994             exited_pid, status = os.waitpid(pid, 0)
00995 
00996         self._box.lock()
00997         self._box.unlock()

Here is the call graph for this function:

Reimplemented in test.test_mailbox.TestMaildir.

Definition at line 507 of file test_mailbox.py.

00507 
00508     def test_lock_unlock(self):
00509         # Lock and unlock the mailbox
00510         self.assertFalse(os.path.exists(self._get_lock_path()))
00511         self._box.lock()
00512         self.assertTrue(os.path.exists(self._get_lock_path()))
00513         self._box.unlock()
00514         self.assertFalse(os.path.exists(self._get_lock_path()))

Here is the call graph for this function:

Definition at line 942 of file test_mailbox.py.

00942 
00943     def test_open_close_open(self):
00944         # Open and inspect previously-created mailbox
00945         values = [self._template % i for i in range(3)]
00946         for value in values:
00947             self._box.add(value)
00948         self._box.close()
00949         mtime = os.path.getmtime(self._path)
00950         self._box = self._factory(self._path)
00951         self.assertEqual(len(self._box), 3)
00952         for key in self._box.keys():
00953             self.assertIn(self._box.get_string(key), values)
00954         self._box.close()
00955         self.assertEqual(mtime, os.path.getmtime(self._path))

def test.test_mailbox.TestMailbox.test_pop (   self) [inherited]

Definition at line 435 of file test_mailbox.py.

00435 
00436     def test_pop(self):
00437         # Get and remove a message using pop()
00438         key0 = self._box.add(self._template % 0)
00439         self.assertIn(key0, self._box)
00440         key1 = self._box.add(self._template % 1)
00441         self.assertIn(key1, self._box)
00442         self.assertEqual(self._box.pop(key0).get_payload(), '0')
00443         self.assertNotIn(key0, self._box)
00444         self.assertIn(key1, self._box)
00445         key2 = self._box.add(self._template % 2)
00446         self.assertIn(key2, self._box)
00447         self.assertEqual(self._box.pop(key2).get_payload(), '2')
00448         self.assertNotIn(key2, self._box)
00449         self.assertIn(key1, self._box)
00450         self.assertEqual(self._box.pop(key1).get_payload(), '1')
00451         self.assertNotIn(key1, self._box)
00452         self.assertEqual(len(self._box), 0)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_popitem (   self,
  iterations = 10 
) [inherited]

Definition at line 453 of file test_mailbox.py.

00453 
00454     def test_popitem(self, iterations=10):
00455         # Get and remove an arbitrary (key, message) using popitem()
00456         keys = []
00457         for i in range(10):
00458             keys.append(self._box.add(self._template % i))
00459         seen = []
00460         for i in range(10):
00461             key, msg = self._box.popitem()
00462             self.assertIn(key, keys)
00463             self.assertNotIn(key, seen)
00464             seen.append(key)
00465             self.assertEqual(int(msg.get_payload()), keys.index(key))
00466         self.assertEqual(len(self._box), 0)
00467         for key in keys:
00468             self.assertRaises(KeyError, lambda: self._box[key])

Here is the call graph for this function:

def test.test_mailbox._TestMboxMMDF.test_relock (   self) [inherited]

Definition at line 998 of file test_mailbox.py.

00998 
00999     def test_relock(self):
01000         # Test case for bug #1575506: the mailbox class was locking the
01001         # wrong file object in its flush() method.
01002         msg = "Subject: sub\n\nbody\n"
01003         key1 = self._box.add(msg)
01004         self._box.flush()
01005         self._box.close()
01006 
01007         self._box = self._factory(self._path)
01008         self._box.lock()
01009         key2 = self._box.add(msg)
01010         self._box.flush()
01011         self.assertTrue(self._box._locked)
01012         self._box.close()
01013 

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_remove (   self) [inherited]

Definition at line 194 of file test_mailbox.py.

00194 
00195     def test_remove(self):
00196         # Remove messages using remove()
00197         self._test_remove_or_delitem(self._box.remove)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_set_item (   self) [inherited]

Definition at line 396 of file test_mailbox.py.

00396 
00397     def test_set_item(self):
00398         # Modify messages using __setitem__()
00399         key0 = self._box.add(self._template % 'original 0')
00400         self.assertEqual(self._box.get_string(key0),
00401                          self._template % 'original 0')
00402         key1 = self._box.add(self._template % 'original 1')
00403         self.assertEqual(self._box.get_string(key1),
00404                          self._template % 'original 1')
00405         self._box[key0] = self._template % 'changed 0'
00406         self.assertEqual(self._box.get_string(key0),
00407                          self._template % 'changed 0')
00408         self._box[key1] = self._template % 'changed 1'
00409         self.assertEqual(self._box.get_string(key1),
00410                          self._template % 'changed 1')
00411         self._box[key0] = _sample_message
00412         self._check_sample(self._box[key0])
00413         self._box[key1] = self._box[key0]
00414         self._check_sample(self._box[key1])
00415         self._box[key0] = self._template % 'original 0'
00416         self.assertEqual(self._box.get_string(key0),
00417                      self._template % 'original 0')
00418         self._check_sample(self._box[key1])
00419         self.assertRaises(KeyError,
00420                           lambda: self._box.__setitem__('foo', 'bar'))
00421         self.assertRaises(KeyError, lambda: self._box['foo'])
00422         self.assertEqual(len(self._box), 2)

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_update (   self) [inherited]

Definition at line 469 of file test_mailbox.py.

00469 
00470     def test_update(self):
00471         # Modify multiple messages using update()
00472         key0 = self._box.add(self._template % 'original 0')
00473         key1 = self._box.add(self._template % 'original 1')
00474         key2 = self._box.add(self._template % 'original 2')
00475         self._box.update({key0: self._template % 'changed 0',
00476                           key2: _sample_message})
00477         self.assertEqual(len(self._box), 3)
00478         self.assertEqual(self._box.get_string(key0),
00479                      self._template % 'changed 0')
00480         self.assertEqual(self._box.get_string(key1),
00481                      self._template % 'original 1')
00482         self._check_sample(self._box[key2])
00483         self._box.update([(key2, self._template % 'changed 2'),
00484                     (key1, self._template % 'changed 1'),
00485                     (key0, self._template % 'original 0')])
00486         self.assertEqual(len(self._box), 3)
00487         self.assertEqual(self._box.get_string(key0),
00488                      self._template % 'original 0')
00489         self.assertEqual(self._box.get_string(key1),
00490                      self._template % 'changed 1')
00491         self.assertEqual(self._box.get_string(key2),
00492                      self._template % 'changed 2')
00493         self.assertRaises(KeyError,
00494                           lambda: self._box.update({'foo': 'bar',
00495                                           key0: self._template % "changed 0"}))
00496         self.assertEqual(len(self._box), 3)
00497         self.assertEqual(self._box.get_string(key0),
00498                      self._template % "changed 0")
00499         self.assertEqual(self._box.get_string(key1),
00500                      self._template % "changed 1")
00501         self.assertEqual(self._box.get_string(key2),
00502                      self._template % "changed 2")

Here is the call graph for this function:

def test.test_mailbox.TestMailbox.test_values (   self) [inherited]

Definition at line 325 of file test_mailbox.py.

00325 
00326     def test_values(self):
00327         # Get values using values()
00328         self._check_iteration(self._box.values, do_keys=False, do_values=True)

Here is the call graph for this function:


Member Data Documentation

Reimplemented from test.test_mailbox._TestMboxMMDF.

Definition at line 1027 of file test_mailbox.py.

tuple test.test_mailbox.TestMbox._factory = lambdaself,path,factoryNone:mailbox.mbox(path, factory) [static, private]

Reimplemented from test.test_mailbox.TestMailbox.

Definition at line 1016 of file test_mailbox.py.

test.test_mailbox.TestMailbox.maxDiff = None [static, inherited]

Definition at line 53 of file test_mailbox.py.


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