Back to index

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

List of all members.

Public Member Functions

def setUp
def assertMailboxEmpty
def test_add_MM
def test_get_MM
def test_set_MM
def test_consistent_factory
def test_initialize_new
def test_initialize_existing
def test_list_folders
def test_get_folder
def test_add_and_remove_folders
def test_clean
def test_create_tmp
def test_refresh
def test_lookup
def test_lock_unlock
def test_folder
def test_directory_in_folder
def test_file_permissions
def test_folder_file_perms
def test_reread
def tearDown
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_close
def test_dump_message

Static Public Attributes

 maxDiff = None

Private Member Functions

def _check_basics

Private Attributes

 _box

Static Private Attributes

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

Detailed Description

Definition at line 588 of file test_mailbox.py.


Member Function Documentation

def test.test_mailbox.TestMaildir._check_basics (   self,
  factory = None 
) [private]

Definition at line 675 of file test_mailbox.py.

00675 
00676     def _check_basics(self, factory=None):
00677         # (Used by test_open_new() and test_open_existing().)
00678         self.assertEqual(self._box._path, os.path.abspath(self._path))
00679         self.assertEqual(self._box._factory, factory)
00680         for subdir in '', 'tmp', 'new', 'cur':
00681             path = os.path.join(self._path, subdir)
00682             mode = os.stat(path)[stat.ST_MODE]
00683             self.assertTrue(stat.S_ISDIR(mode), "Not a directory: '%s'" % path)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 597 of file test_mailbox.py.

00597 
00598     def assertMailboxEmpty(self):
00599         self.assertEqual(os.listdir(os.path.join(self._path, 'tmp')), [])

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from test.test_mailbox.TestMailbox.

Definition at line 592 of file test_mailbox.py.

00592 
00593     def setUp(self):
00594         TestMailbox.setUp(self)
00595         if os.name in ('nt', 'os2') or sys.platform == 'cygwin':
00596             self._box.colon = '!'

Here is the caller graph for this function:

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

Reimplemented in test.test_mailbox.TestBabyl, and test.test_mailbox._TestMboxMMDF.

Definition at line 63 of file test_mailbox.py.

00063 
00064     def tearDown(self):
00065         self._box.close()
00066         self._delete_recursively(self._path)

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 703 of file test_mailbox.py.

00703 
00704     def test_add_and_remove_folders(self):
00705         # Delete folders
00706         self._box.add_folder('one')
00707         self._box.add_folder('two')
00708         self.assertEqual(len(self._box.list_folders()), 2)
00709         self.assertEqual(set(self._box.list_folders()), set(('one', 'two')))
00710         self._box.remove_folder('one')
00711         self.assertEqual(len(self._box.list_folders()), 1)
00712         self.assertEqual(set(self._box.list_folders()), set(('two',)))
00713         self._box.add_folder('three')
00714         self.assertEqual(len(self._box.list_folders()), 2)
00715         self.assertEqual(set(self._box.list_folders()), set(('two', 'three')))
00716         self._box.remove_folder('three')
00717         self.assertEqual(len(self._box.list_folders()), 1)
00718         self.assertEqual(set(self._box.list_folders()), set(('two',)))
00719         self._box.remove_folder('two')
00720         self.assertEqual(len(self._box.list_folders()), 0)
00721         self.assertEqual(self._box.list_folders(), [])

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 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 600 of file test_mailbox.py.

00600 
00601     def test_add_MM(self):
00602         # Add a MaildirMessage instance
00603         msg = mailbox.MaildirMessage(self._template % 0)
00604         msg.set_subdir('cur')
00605         msg.set_info('foo')
00606         key = self._box.add(msg)
00607         self.assertTrue(os.path.exists(os.path.join(self._path, 'cur', '%s%sfoo' %
00608                                                  (key, self._box.colon))))

Here is the call graph for this function:

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:

Definition at line 722 of file test_mailbox.py.

00722 
00723     def test_clean(self):
00724         # Remove old files from 'tmp'
00725         foo_path = os.path.join(self._path, 'tmp', 'foo')
00726         bar_path = os.path.join(self._path, 'tmp', 'bar')
00727         with open(foo_path, 'w') as f:
00728             f.write("@")
00729         with open(bar_path, 'w') as f:
00730             f.write("@")
00731         self._box.clean()
00732         self.assertTrue(os.path.exists(foo_path))
00733         self.assertTrue(os.path.exists(bar_path))
00734         foo_stat = os.stat(foo_path)
00735         os.utime(foo_path, (time.time() - 129600 - 2,
00736                             foo_stat.st_mtime))
00737         self._box.clean()
00738         self.assertFalse(os.path.exists(foo_path))
00739         self.assertTrue(os.path.exists(bar_path))

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:

Definition at line 643 of file test_mailbox.py.

00643 
00644     def test_consistent_factory(self):
00645         # Add a message.
00646         msg = mailbox.MaildirMessage(self._template % 0)
00647         msg.set_subdir('cur')
00648         msg.set_flags('RF')
00649         key = self._box.add(msg)
00650 
00651         # Create new mailbox with
00652         class FakeMessage(mailbox.MaildirMessage):
00653             pass
00654         box = mailbox.Maildir(self._path, factory=FakeMessage)
00655         box.colon = self._box.colon
00656         msg2 = box.get_message(key)
00657         self.assertIsInstance(msg2, FakeMessage)

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.TestMaildir.test_create_tmp (   self,
  repetitions = 10 
)

Definition at line 740 of file test_mailbox.py.

00740 
00741     def test_create_tmp(self, repetitions=10):
00742         # Create files in tmp directory
00743         hostname = socket.gethostname()
00744         if '/' in hostname:
00745             hostname = hostname.replace('/', r'\057')
00746         if ':' in hostname:
00747             hostname = hostname.replace(':', r'\072')
00748         pid = os.getpid()
00749         pattern = re.compile(r"(?P<time>\d+)\.M(?P<M>\d{1,6})P(?P<P>\d+)"
00750                              r"Q(?P<Q>\d+)\.(?P<host>[^:/]+)")
00751         previous_groups = None
00752         for x in range(repetitions):
00753             tmp_file = self._box._create_tmp()
00754             head, tail = os.path.split(tmp_file.name)
00755             self.assertEqual(head, os.path.abspath(os.path.join(self._path,
00756                                                                 "tmp")),
00757                              "File in wrong location: '%s'" % head)
00758             match = pattern.match(tail)
00759             self.assertIsNot(match, None, "Invalid file name: '%s'" % tail)
00760             groups = match.groups()
00761             if previous_groups is not None:
00762                 self.assertTrue(int(groups[0] >= previous_groups[0]),
00763                              "Non-monotonic seconds: '%s' before '%s'" %
00764                              (previous_groups[0], groups[0]))
00765                 self.assertTrue(int(groups[1] >= previous_groups[1]) or
00766                              groups[0] != groups[1],
00767                              "Non-monotonic milliseconds: '%s' before '%s'" %
00768                              (previous_groups[1], groups[1]))
00769                 self.assertEqual(int(groups[2]), pid,
00770                              "Process ID mismatch: '%s' should be '%s'" %
00771                              (groups[2], pid))
00772                 self.assertEqual(int(groups[3]), int(previous_groups[3]) + 1,
00773                              "Non-sequential counter: '%s' before '%s'" %
00774                              (previous_groups[3], groups[3]))
00775                 self.assertEqual(groups[4], hostname,
00776                              "Host name mismatch: '%s' should be '%s'" %
00777                              (groups[4], hostname))
00778             previous_groups = groups
00779             tmp_file.write(_bytes_sample_message)
00780             tmp_file.seek(0)
00781             self.assertEqual(tmp_file.read(), _bytes_sample_message)
00782             tmp_file.close()
00783         file_count = len(os.listdir(os.path.join(self._path, "tmp")))
00784         self.assertEqual(file_count, repetitions,
00785                      "Wrong file count: '%s' should be '%s'" %
00786                      (file_count, repetitions))

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:

Definition at line 834 of file test_mailbox.py.

00834 
00835     def test_directory_in_folder (self):
00836         # Test that mailboxes still work if there's a stray extra directory
00837         # in a folder.
00838         for i in range(10):
00839             self._box.add(mailbox.Message(_sample_message))
00840 
00841         # Create a stray directory
00842         os.mkdir(os.path.join(self._path, 'cur', 'stray-dir'))
00843 
00844         # Check that looping still works with the directory present.
00845         for msg in self._box:
00846             pass

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 847 of file test_mailbox.py.

00847 
00848     def test_file_permissions(self):
00849         # Verify that message files are created without execute permissions
00850         if not hasattr(os, "stat") or not hasattr(os, "umask"):
00851             return
00852         msg = mailbox.MaildirMessage(self._template % 0)
00853         orig_umask = os.umask(0)
00854         try:
00855             key = self._box.add(msg)
00856         finally:
00857             os.umask(orig_umask)
00858         path = os.path.join(self._path, self._box._lookup(key))
00859         mode = os.stat(path).st_mode
00860         self.assertFalse(mode & 0o111)

Here is the call graph for this function:

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:

Definition at line 822 of file test_mailbox.py.

00822 
00823     def test_folder (self):
00824         # Test for bug #1569790: verify that folders returned by .get_folder()
00825         # use the same factory function.
00826         def dummy_factory (s):
00827             return None
00828         box = self._factory(self._path, factory=dummy_factory)
00829         folder = box.add_folder('folder1')
00830         self.assertIs(folder._factory, dummy_factory)
00831 
00832         folder1_alias = box.get_folder('folder1')
00833         self.assertIs(folder1_alias._factory, dummy_factory)

Here is the call graph for this function:

Definition at line 861 of file test_mailbox.py.

00861 
00862     def test_folder_file_perms(self):
00863         # From bug #3228, we want to verify that the file created inside a Maildir
00864         # subfolder isn't marked as executable.
00865         if not hasattr(os, "stat") or not hasattr(os, "umask"):
00866             return
00867 
00868         orig_umask = os.umask(0)
00869         try:
00870             subfolder = self._box.add_folder('subfolder')
00871         finally:
00872             os.umask(orig_umask)
00873 
00874         path = os.path.join(subfolder._path, 'maildirfolder')
00875         st = os.stat(path)
00876         perms = st.st_mode
00877         self.assertFalse((perms & 0o111)) # Execute bits should all be off.

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 693 of file test_mailbox.py.

00693 
00694     def test_get_folder(self):
00695         # Open folders
00696         self._box.add_folder('foo.bar')
00697         folder0 = self._box.get_folder('foo.bar')
00698         folder0.add(self._template % 'bar')
00699         self.assertTrue(os.path.isdir(os.path.join(self._path, '.foo.bar')))
00700         folder1 = self._box.get_folder('foo.bar')
00701         self.assertEqual(folder1.get_string(folder1.keys()[0]),
00702                          self._template % 'bar')

Here is the call graph for this function:

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 609 of file test_mailbox.py.

00609 
00610     def test_get_MM(self):
00611         # Get a MaildirMessage instance
00612         msg = mailbox.MaildirMessage(self._template % 0)
00613         msg.set_subdir('cur')
00614         msg.set_flags('RF')
00615         key = self._box.add(msg)
00616         msg_returned = self._box.get_message(key)
00617         self.assertIsInstance(msg_returned, mailbox.MaildirMessage)
00618         self.assertEqual(msg_returned.get_subdir(), 'cur')
00619         self.assertEqual(msg_returned.get_flags(), 'FR')

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 667 of file test_mailbox.py.

00667 
00668     def test_initialize_existing(self):
00669         # Initialize an existing mailbox
00670         self.tearDown()
00671         for subdir in '', 'tmp', 'new', 'cur':
00672             os.mkdir(os.path.normpath(os.path.join(self._path, subdir)))
00673         self._box = mailbox.Maildir(self._path)
00674         self._check_basics()

Definition at line 658 of file test_mailbox.py.

00658 
00659     def test_initialize_new(self):
00660         # Initialize a non-existent mailbox
00661         self.tearDown()
00662         self._box = mailbox.Maildir(self._path)
00663         self._check_basics()
00664         self._delete_recursively(self._path)
00665         self._box = self._factory(self._path, factory=None)
00666         self._check_basics()

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 684 of file test_mailbox.py.

00684 
00685     def test_list_folders(self):
00686         # List folders
00687         self._box.add_folder('one')
00688         self._box.add_folder('two')
00689         self._box.add_folder('three')
00690         self.assertEqual(len(self._box.list_folders()), 3)
00691         self.assertEqual(set(self._box.list_folders()),
00692                      set(('one', 'two', 'three')))

Here is the call graph for this function:

Reimplemented from test.test_mailbox.TestMailbox.

Definition at line 817 of file test_mailbox.py.

00817 
00818     def test_lock_unlock(self):
00819         # Lock and unlock the mailbox. For Maildir, this does nothing.
00820         self._box.lock()
00821         self._box.unlock()

Definition at line 804 of file test_mailbox.py.

00804 
00805     def test_lookup(self):
00806         # Look up message subpaths in the TOC
00807         self.assertRaises(KeyError, lambda: self._box._lookup('foo'))
00808         key0 = self._box.add(self._template % 0)
00809         self.assertEqual(self._box._lookup(key0), os.path.join('new', key0))
00810         os.remove(os.path.join(self._path, 'new', key0))
00811         self.assertEqual(self._box._toc, {key0: os.path.join('new', key0)})
00812         # Be sure that the TOC is read back from disk (see issue #6896
00813         # about bad mtime behaviour on some systems).
00814         self._box.flush()
00815         self.assertRaises(KeyError, lambda: self._box._lookup(key0))
00816         self.assertEqual(self._box._toc, {})

Here is the call graph for this function:

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:

Definition at line 787 of file test_mailbox.py.

00787 
00788     def test_refresh(self):
00789         # Update the table of contents
00790         self.assertEqual(self._box._toc, {})
00791         key0 = self._box.add(self._template % 0)
00792         key1 = self._box.add(self._template % 1)
00793         self.assertEqual(self._box._toc, {})
00794         self._box._refresh()
00795         self.assertEqual(self._box._toc, {key0: os.path.join('new', key0),
00796                                           key1: os.path.join('new', key1)})
00797         key2 = self._box.add(self._template % 2)
00798         self.assertEqual(self._box._toc, {key0: os.path.join('new', key0),
00799                                           key1: os.path.join('new', key1)})
00800         self._box._refresh()
00801         self.assertEqual(self._box._toc, {key0: os.path.join('new', key0),
00802                                           key1: os.path.join('new', key1),
00803                                           key2: os.path.join('new', key2)})

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:

Definition at line 878 of file test_mailbox.py.

00878 
00879     def test_reread(self):
00880 
00881         # Put the last modified times more than two seconds into the past
00882         # (because mtime may have a two second granularity)
00883         for subdir in ('cur', 'new'):
00884             os.utime(os.path.join(self._box._path, subdir),
00885                      (time.time()-5,)*2)
00886 
00887         # Because mtime has a two second granularity in worst case (FAT), a
00888         # refresh is done unconditionally if called for within
00889         # two-second-plus-a-bit of the last one, just in case the mbox has
00890         # changed; so now we have to wait for that interval to expire.
00891         time.sleep(2.01 + self._box._skewfactor)
00892 
00893         # Re-reading causes the ._toc attribute to be assigned a new dictionary
00894         # object, so we'll check that the ._toc attribute isn't a different
00895         # object.
00896         orig_toc = self._box._toc
00897         def refreshed():
00898             return self._box._toc is not orig_toc
00899 
00900         self._box._refresh()
00901         self.assertFalse(refreshed())
00902 
00903         # Now, write something into cur and remove it.  This changes
00904         # the mtime and should cause a re-read.
00905         filename = os.path.join(self._path, 'cur', 'stray-file')
00906         f = open(filename, 'w')
00907         f.close()
00908         os.unlink(filename)
00909         self._box._refresh()
00910         self.assertTrue(refreshed())

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:

Definition at line 620 of file test_mailbox.py.

00620 
00621     def test_set_MM(self):
00622         # Set with a MaildirMessage instance
00623         msg0 = mailbox.MaildirMessage(self._template % 0)
00624         msg0.set_flags('TP')
00625         key = self._box.add(msg0)
00626         msg_returned = self._box.get_message(key)
00627         self.assertEqual(msg_returned.get_subdir(), 'new')
00628         self.assertEqual(msg_returned.get_flags(), 'PT')
00629         msg1 = mailbox.MaildirMessage(self._template % 1)
00630         self._box[key] = msg1
00631         msg_returned = self._box.get_message(key)
00632         self.assertEqual(msg_returned.get_subdir(), 'new')
00633         self.assertEqual(msg_returned.get_flags(), '')
00634         self.assertEqual(msg_returned.get_payload(), '1')
00635         msg2 = mailbox.MaildirMessage(self._template % 2)
00636         msg2.set_info('2,S')
00637         self._box[key] = msg2
00638         self._box[key] = self._template % 3
00639         msg_returned = self._box.get_message(key)
00640         self.assertEqual(msg_returned.get_subdir(), 'new')
00641         self.assertEqual(msg_returned.get_flags(), 'S')
00642         self.assertEqual(msg_returned.get_payload(), '3')

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.TestMailbox.

Definition at line 661 of file test_mailbox.py.

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

Reimplemented from test.test_mailbox.TestMailbox.

Definition at line 590 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: