2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2004, 2005 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1185.12.59
by Aaron Bentley
Added command-quieting test |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1185.12.59
by Aaron Bentley
Added command-quieting test |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1185.12.59
by Aaron Bentley
Added command-quieting test |
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 |
||
2155.2.3
by Marius Kruger
* commands.py |
17 |
from cStringIO import StringIO |
1948.1.1
by John Arbash Meinel
Raise a reasonable error when a command is non-ascii |
18 |
import errno |
19 |
||
20 |
from bzrlib import ( |
|
21 |
commands, |
|
2155.2.1
by Marius Kruger
* Get command aliases to respect quoted arguments. |
22 |
config, |
1948.1.1
by John Arbash Meinel
Raise a reasonable error when a command is non-ascii |
23 |
errors, |
2425.2.1
by Robert Collins
Command objects can now declare related help topics by having _see_also |
24 |
tests, |
1948.1.1
by John Arbash Meinel
Raise a reasonable error when a command is non-ascii |
25 |
)
|
26 |
from bzrlib.commands import display_command |
|
2425.2.1
by Robert Collins
Command objects can now declare related help topics by having _see_also |
27 |
from bzrlib.tests import TestSkipped |
28 |
||
29 |
||
30 |
class TestCommands(tests.TestCase): |
|
1948.1.1
by John Arbash Meinel
Raise a reasonable error when a command is non-ascii |
31 |
|
1185.12.59
by Aaron Bentley
Added command-quieting test |
32 |
def test_display_command(self): |
1185.33.18
by Martin Pool
[patch] handle bad IOError subclass raised by urlopen |
33 |
"""EPIPE message is selectively suppressed"""
|
1185.12.59
by Aaron Bentley
Added command-quieting test |
34 |
def pipe_thrower(): |
35 |
raise IOError(errno.EPIPE, "Bogus pipe error") |
|
36 |
self.assertRaises(IOError, pipe_thrower) |
|
37 |
@display_command
|
|
38 |
def non_thrower(): |
|
39 |
pipe_thrower() |
|
40 |
non_thrower() |
|
41 |
@display_command
|
|
42 |
def other_thrower(): |
|
43 |
raise IOError(errno.ESPIPE, "Bogus pipe error") |
|
44 |
self.assertRaises(IOError, other_thrower) |
|
45 |
||
1948.1.1
by John Arbash Meinel
Raise a reasonable error when a command is non-ascii |
46 |
def test_unicode_command(self): |
1948.1.8
by John Arbash Meinel
Don't raise UnicodeCommand on request, instead just let it fall out when we get to NoSuchCommand |
47 |
# This error is thrown when we can't find the command in the
|
48 |
# list of available commands
|
|
49 |
self.assertRaises(errors.BzrCommandError, |
|
1948.1.1
by John Arbash Meinel
Raise a reasonable error when a command is non-ascii |
50 |
commands.run_bzr, [u'cmd\xb5']) |
1948.1.8
by John Arbash Meinel
Don't raise UnicodeCommand on request, instead just let it fall out when we get to NoSuchCommand |
51 |
|
52 |
def test_unicode_option(self): |
|
53 |
# This error is actually thrown by optparse, when it
|
|
54 |
# can't find the given option
|
|
1913.2.4
by Martin Pool
python2.5 apparently has trouble with unicode options |
55 |
import optparse |
56 |
if optparse.__version__ == "1.5.3": |
|
57 |
raise TestSkipped("optparse 1.5.3 can't handle unicode options") |
|
1948.1.8
by John Arbash Meinel
Don't raise UnicodeCommand on request, instead just let it fall out when we get to NoSuchCommand |
58 |
self.assertRaises(errors.BzrCommandError, |
59 |
commands.run_bzr, ['log', u'--option\xb5']) |
|
60 |
||
2155.2.3
by Marius Kruger
* commands.py |
61 |
|
2425.2.1
by Robert Collins
Command objects can now declare related help topics by having _see_also |
62 |
class TestGetAlias(tests.TestCase): |
2155.2.3
by Marius Kruger
* commands.py |
63 |
|
64 |
def _get_config(self, config_text): |
|
2155.2.1
by Marius Kruger
* Get command aliases to respect quoted arguments. |
65 |
my_config = config.GlobalConfig() |
66 |
config_file = StringIO(config_text.encode('utf-8')) |
|
67 |
my_config._parser = my_config._get_parser(file=config_file) |
|
68 |
return my_config |
|
69 |
||
70 |
def test_simple(self): |
|
2155.2.3
by Marius Kruger
* commands.py |
71 |
my_config = self._get_config("[ALIASES]\n" |
2155.2.1
by Marius Kruger
* Get command aliases to respect quoted arguments. |
72 |
"diff=diff -r -2..-1\n") |
73 |
self.assertEqual([u'diff', u'-r', u'-2..-1'], |
|
74 |
commands.get_alias("diff", config=my_config)) |
|
75 |
||
76 |
def test_single_quotes(self): |
|
2155.2.3
by Marius Kruger
* commands.py |
77 |
my_config = self._get_config("[ALIASES]\n" |
2155.2.1
by Marius Kruger
* Get command aliases to respect quoted arguments. |
78 |
"diff=diff -r -2..-1 --diff-options "
|
79 |
"'--strip-trailing-cr -wp'\n") |
|
80 |
self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options', |
|
81 |
u'--strip-trailing-cr -wp'], |
|
82 |
commands.get_alias("diff", config=my_config)) |
|
83 |
||
84 |
def test_double_quotes(self): |
|
2155.2.3
by Marius Kruger
* commands.py |
85 |
my_config = self._get_config("[ALIASES]\n" |
2155.2.1
by Marius Kruger
* Get command aliases to respect quoted arguments. |
86 |
"diff=diff -r -2..-1 --diff-options "
|
87 |
"\"--strip-trailing-cr -wp\"\n") |
|
88 |
self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options', |
|
89 |
u'--strip-trailing-cr -wp'], |
|
90 |
commands.get_alias("diff", config=my_config)) |
|
91 |
||
92 |
def test_unicode(self): |
|
2155.2.3
by Marius Kruger
* commands.py |
93 |
my_config = self._get_config("[ALIASES]\n" |
2155.2.1
by Marius Kruger
* Get command aliases to respect quoted arguments. |
94 |
u"iam=whoami 'Erik B\u00e5gfors <erik@bagfors.nu>'\n") |
95 |
self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'], |
|
96 |
commands.get_alias("iam", config=my_config)) |
|
2425.2.1
by Robert Collins
Command objects can now declare related help topics by having _see_also |
97 |
|
98 |
||
99 |
class TestSeeAlso(tests.TestCase): |
|
100 |
"""Tests for the see also functional of Command."""
|
|
101 |
||
102 |
def test_default_subclass_no_see_also(self): |
|
103 |
class ACommand(commands.Command): |
|
104 |
"""A sample command."""
|
|
105 |
command = ACommand() |
|
106 |
self.assertEqual([], command.get_see_also()) |
|
107 |
||
108 |
def test__see_also(self): |
|
109 |
"""When _see_also is defined, it sets the result of get_see_also()."""
|
|
110 |
class ACommand(commands.Command): |
|
111 |
_see_also = ['bar', 'foo'] |
|
112 |
command = ACommand() |
|
113 |
self.assertEqual(['bar', 'foo'], command.get_see_also()) |
|
114 |
||
115 |
def test_deduplication(self): |
|
116 |
"""Duplicates in _see_also are stripped out."""
|
|
117 |
class ACommand(commands.Command): |
|
118 |
_see_also = ['foo', 'foo'] |
|
119 |
command = ACommand() |
|
120 |
self.assertEqual(['foo'], command.get_see_also()) |
|
121 |
||
122 |
def test_sorted(self): |
|
123 |
"""_see_also is sorted by get_see_also."""
|
|
124 |
class ACommand(commands.Command): |
|
125 |
_see_also = ['foo', 'bar'] |
|
126 |
command = ACommand() |
|
127 |
self.assertEqual(['bar', 'foo'], command.get_see_also()) |
|
2432.1.21
by Robert Collins
Teach Command.get_help_text to show additional help cross references when supplied. |
128 |
|
129 |
def test_additional_terms(self): |
|
130 |
"""Additional terms can be supplied and are deduped and sorted."""
|
|
131 |
class ACommand(commands.Command): |
|
132 |
_see_also = ['foo', 'bar'] |
|
133 |
command = ACommand() |
|
134 |
self.assertEqual(['bar', 'foo', 'gam'], |
|
135 |
command.get_see_also(['gam', 'bar', 'gam'])) |
|
136 |