/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_breakin.py

  • Committer: Adeodato Simó
  • Date: 2007-07-18 15:51:52 UTC
  • mto: (2639.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2640.
  • Revision ID: dato@net.com.org.es-20070718155152-pv6rwq41eckqyxem
New EmailMessage class, façade around email.Message and MIMEMultipart.

* bzrlib/email_message.py,
  bzrlib/tests/test_email_message.py:
  New files.

* bzrlib/tests/__init__.py:
  (test_suite): add bzrlib.tests.test_email_message.

* bzrlib/merge_directive.py:
  (MergeDirective.to_email): Use EmailMessage instead of email.Message.

* bzrlib/tests/test_merge_directive.py,
  bzrlib/tests/blackbox/test_merge_directive.py:
  (__main__): adjust EMAIL1 and EMAIL2 strings to how EmailMessage
  formats itself.

* bzrlib/smtp_connection.py:
  (SMTPConnection.get_message_addresses): do not use methods present in
  email.Message but not in EmailMessage (get_all). Use get() instead of
  __getitem__ to make explicit that None is returned if the header does
  not exist.

* bzrlib/tests/test_smtp_connection.py:
  (TestSMTPConnection.test_get_message_addresses, 
   TestSMTPConnection.test_destination_address_required): test the
   functions against EmailMessage in addition to email.Message.

* NEWS:
  Mention EmailMessage in INTERNALS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Blackbox tests for debugger breakin"""
 
18
 
 
19
import os
 
20
import signal
 
21
import subprocess
 
22
import sys
 
23
import time
 
24
 
 
25
from bzrlib.tests import TestCase, TestSkipped
 
26
 
 
27
 
 
28
class TestBreakin(TestCase):
 
29
    # FIXME: If something is broken, these tests may just hang indefinitely in
 
30
    # wait() waiting for the child to exit when it's not going to.
 
31
 
 
32
    def setUp(self):
 
33
        if sys.platform == 'win32':
 
34
            raise TestSkipped('breakin signal not tested on win32')
 
35
        super(TestBreakin, self).setUp()
 
36
 
 
37
    # port 0 means to allocate any port
 
38
    _test_process_args = ['serve', '--port', 'localhost:0']
 
39
 
 
40
    def test_breakin(self):
 
41
        # Break in to a debugger while bzr is running
 
42
        # we need to test against a command that will wait for 
 
43
        # a while -- bzr serve should do
 
44
        proc = self.start_bzr_subprocess(self._test_process_args,
 
45
                env_changes=dict(BZR_SIGQUIT_PDB=None))
 
46
        # wait for it to get started, and print the 'listening' line
 
47
        proc.stdout.readline()
 
48
        # first sigquit pops into debugger
 
49
        os.kill(proc.pid, signal.SIGQUIT)
 
50
        proc.stdin.write("q\n")
 
51
        time.sleep(.5)
 
52
        err = proc.stderr.readline()
 
53
        self.assertContainsRe(err, r'entering debugger')
 
54
 
 
55
    def test_breakin_harder(self):
 
56
        proc = self.start_bzr_subprocess(self._test_process_args,
 
57
                env_changes=dict(BZR_SIGQUIT_PDB=None))
 
58
        # wait for it to get started, and print the 'listening' line
 
59
        proc.stdout.readline()
 
60
        # break into the debugger
 
61
        os.kill(proc.pid, signal.SIGQUIT)
 
62
        # now send a second sigquit, which should cause it to exit.  That
 
63
        # won't happen until the original signal has been noticed by the
 
64
        # child and it's run its signal handler.  We don't know quite how long
 
65
        # this will take, but if it's more than 10s then it's probably not
 
66
        # going to work.
 
67
        for i in range(100):
 
68
            time.sleep(0.1)
 
69
            os.kill(proc.pid, signal.SIGQUIT)
 
70
            # note: waitpid is different on win32, but this test only runs on
 
71
            # unix
 
72
            r = os.waitpid(proc.pid, os.WNOHANG)
 
73
            if r != (0, 0):
 
74
                # high bit says if core was dumped; we don't care
 
75
                self.assertEquals(r[1] & 0x7f, signal.SIGQUIT)
 
76
                break
 
77
        else:
 
78
            self.fail("subprocess wasn't terminated by repeated SIGQUIT")
 
79
 
 
80
    def test_breakin_disabled(self):
 
81
        proc = self.start_bzr_subprocess(self._test_process_args,
 
82
                env_changes=dict(BZR_SIGQUIT_PDB='0'))
 
83
        # wait for it to get started, and print the 'listening' line
 
84
        proc.stdout.readline()
 
85
        # first hit should just kill it
 
86
        os.kill(proc.pid, signal.SIGQUIT)
 
87
        proc.wait()