/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/test_commands.py

  • Committer: v.ladeuil+lp at free
  • Date: 2007-02-04 17:41:12 UTC
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070204174112-iv6gxzinnjddlaxj
Add tests for redirection. Preserve transport decorations.

* bzrlib/tests/test_http.py:
(TestRedirections): new tests.

* bzrlib/tests/HttpServer.py:
(HttpServer): Make server host and port public once the socket
have been established.

* bzrlib/tests/HTTPTestUtil.py:
(RedirectRequestHandler, HTTPServerRedirecting): New http test
server for redirections. Only a whole host can be redirected, so
far.

* bzrlib/errors.py:
(RedirectRequested.__init__): Add a 'qual_proto' oso that
transport decorations can be transmitted to redirected transport.
(RedirectRequested._requalify_url,
RedirectRequested.get_source_url,
RedirectRequested.get_target_url): New methods providing fully
decorated urls.

* bzrlib/bzrdir.py:
(BzrDir.open_from_transport): The redirection should preserve
transport decorations.
(BzrDirMetaFormat1): To be able to specialize bzr branches from
foreign branches, we need to register BzrDirMetaFormat1 as the
default control format (instead of BzrDirMetaFormat which is
abstract and can still be used by foreign branches).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004, 2005 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
from cStringIO import StringIO
 
18
import errno
 
19
 
 
20
from bzrlib import (
 
21
    commands,
 
22
    config,
 
23
    errors,
 
24
    )
 
25
from bzrlib.commands import display_command
 
26
from bzrlib.tests import TestCase, TestSkipped
 
27
 
 
28
 
 
29
class TestCommands(TestCase):
 
30
 
 
31
    def test_display_command(self):
 
32
        """EPIPE message is selectively suppressed"""
 
33
        def pipe_thrower():
 
34
            raise IOError(errno.EPIPE, "Bogus pipe error")
 
35
        self.assertRaises(IOError, pipe_thrower)
 
36
        @display_command
 
37
        def non_thrower():
 
38
            pipe_thrower()
 
39
        non_thrower()
 
40
        @display_command
 
41
        def other_thrower():
 
42
            raise IOError(errno.ESPIPE, "Bogus pipe error")
 
43
        self.assertRaises(IOError, other_thrower)
 
44
 
 
45
    def test_unicode_command(self):
 
46
        # This error is thrown when we can't find the command in the
 
47
        # list of available commands
 
48
        self.assertRaises(errors.BzrCommandError,
 
49
                          commands.run_bzr, [u'cmd\xb5'])
 
50
 
 
51
    def test_unicode_option(self):
 
52
        # This error is actually thrown by optparse, when it
 
53
        # can't find the given option
 
54
        import optparse
 
55
        if optparse.__version__ == "1.5.3":
 
56
            raise TestSkipped("optparse 1.5.3 can't handle unicode options")
 
57
        self.assertRaises(errors.BzrCommandError,
 
58
                          commands.run_bzr, ['log', u'--option\xb5'])
 
59
 
 
60
 
 
61
class TestGetAlias(TestCase):
 
62
 
 
63
    def _get_config(self, config_text):
 
64
        my_config = config.GlobalConfig()
 
65
        config_file = StringIO(config_text.encode('utf-8'))
 
66
        my_config._parser = my_config._get_parser(file=config_file)
 
67
        return my_config
 
68
 
 
69
    def test_simple(self):
 
70
        my_config = self._get_config("[ALIASES]\n"
 
71
            "diff=diff -r -2..-1\n")
 
72
        self.assertEqual([u'diff', u'-r', u'-2..-1'],
 
73
            commands.get_alias("diff", config=my_config))
 
74
 
 
75
    def test_single_quotes(self):
 
76
        my_config = self._get_config("[ALIASES]\n"
 
77
            "diff=diff -r -2..-1 --diff-options "
 
78
            "'--strip-trailing-cr -wp'\n")
 
79
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
 
80
                          u'--strip-trailing-cr -wp'],
 
81
                          commands.get_alias("diff", config=my_config))
 
82
 
 
83
    def test_double_quotes(self):
 
84
        my_config = self._get_config("[ALIASES]\n"
 
85
            "diff=diff -r -2..-1 --diff-options "
 
86
            "\"--strip-trailing-cr -wp\"\n")
 
87
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
 
88
                          u'--strip-trailing-cr -wp'],
 
89
                          commands.get_alias("diff", config=my_config))
 
90
 
 
91
    def test_unicode(self):
 
92
        my_config = self._get_config("[ALIASES]\n"
 
93
            u"iam=whoami 'Erik B\u00e5gfors <erik@bagfors.nu>'\n")
 
94
        self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
 
95
                          commands.get_alias("iam", config=my_config))