Rev 4660: Cleanup emacs-bzr-send-XXXXXX.el leaks in /tmp during selftest. in file:///home/vila/src/bzr/experimental/test-isolation/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Sep 2 09:26:27 BST 2009


At file:///home/vila/src/bzr/experimental/test-isolation/

------------------------------------------------------------
revno: 4660
revision-id: v.ladeuil+lp at free.fr-20090902082627-cit8vm6tefu9hwk2
parent: pqm at pqm.ubuntu.com-20090827132024-h13eo7blndo2dfpl
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: test-isolation
timestamp: Wed 2009-09-02 10:26:27 +0200
message:
  Cleanup emacs-bzr-send-XXXXXX.el leaks in /tmp during selftest.
  
  * tests/test_mail_client.py:
  (TestEmacsMail.test_commandline,
  TestEmacsMail.test_commandline_is_8bit): Cleanup the generated tmp
  file.
  
  * mail_client.py:
  (EmacsMail.__init__, EmacsMail._get_compose_commandline): Keep
  track of the tmp file to ease cleanup during testing.
-------------- next part --------------
=== modified file 'bzrlib/mail_client.py'
--- a/bzrlib/mail_client.py	2009-06-10 03:56:49 +0000
+++ b/bzrlib/mail_client.py	2009-09-02 08:26:27 +0000
@@ -424,6 +424,10 @@
 
     _client_commands = ['emacsclient']
 
+    def __init__(self, config):
+        super(EmacsMail, self).__init__(config)
+        self.elisp_tmp_file = None
+
     def _prepare_send_function(self):
         """Write our wrapper function into a temporary file.
 
@@ -500,6 +504,7 @@
         if attach_path is not None:
             # Do not create a file if there is no attachment
             elisp = self._prepare_send_function()
+            self.elisp_tmp_file = elisp
             lmmform = '(load "%s")' % elisp
             mmform  = '(bzr-add-mime-att "%s")' % \
                 self._encode_path(attach_path, 'attachment')

=== modified file 'bzrlib/tests/test_mail_client.py'
--- a/bzrlib/tests/test_mail_client.py	2009-06-10 03:56:49 +0000
+++ b/bzrlib/tests/test_mail_client.py	2009-09-02 08:26:27 +0000
@@ -97,6 +97,8 @@
         # We won't be able to know the temporary file name at this stage
         # so we can't raise an assertion with assertEqual
         cmdline = eclient._get_compose_commandline(None, None, 'file%')
+        if eclient.elisp_tmp_file is not None:
+            self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
         commandline = ' '.join(cmdline)
         self.assertContainsRe(commandline, '--eval')
         self.assertContainsRe(commandline, '(compose-mail nil nil)')
@@ -107,6 +109,8 @@
         eclient = mail_client.EmacsMail(None)
         commandline = eclient._get_compose_commandline(u'jrandom at example.org',
             u'Hi there!', u'file%')
+        if eclient.elisp_tmp_file is not None:
+            self.addCleanup(osutils.delete_any, eclient.elisp_tmp_file)
         for item in commandline:
             self.assertFalse(isinstance(item, unicode),
                 'Command-line item %r is unicode!' % item)



More information about the bazaar-commits mailing list