bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
1185.49.22
by John Arbash Meinel
 Added get_password to the UIFactory, using it inside of sftp.py  | 
1  | 
# Copyright (C) 2005 by 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  | 
"""Tests for the bzrlib ui
 | 
|
18  | 
"""
 | 
|
19  | 
||
20  | 
import os  | 
|
| 
1534.5.6
by Robert Collins
 split out converter logic into per-format objects.  | 
21  | 
from StringIO import StringIO  | 
| 
1185.49.22
by John Arbash Meinel
 Added get_password to the UIFactory, using it inside of sftp.py  | 
22  | 
import sys  | 
23  | 
||
| 
1534.5.6
by Robert Collins
 split out converter logic into per-format objects.  | 
24  | 
from bzrlib.progress import TTYProgressBar  | 
| 
1185.49.22
by John Arbash Meinel
 Added get_password to the UIFactory, using it inside of sftp.py  | 
25  | 
from bzrlib.tests import TestCase  | 
26  | 
from bzrlib.ui import SilentUIFactory  | 
|
27  | 
from bzrlib.ui.text import TextUIFactory  | 
|
28  | 
||
29  | 
class UITests(TestCase):  | 
|
30  | 
||
31  | 
def test_silent_factory(self):  | 
|
32  | 
||
33  | 
ui = SilentUIFactory()  | 
|
34  | 
pb = ui.progress_bar()  | 
|
35  | 
        # TODO: Test that there is no output from SilentUIFactory
 | 
|
36  | 
||
37  | 
self.assertEquals(ui.get_password(), None)  | 
|
38  | 
self.assertEquals(ui.get_password(u'Hello There \u1234 %(user)s',  | 
|
39  | 
user=u'some\u1234')  | 
|
40  | 
, None)  | 
|
41  | 
||
42  | 
def test_text_factory(self):  | 
|
43  | 
ui = TextUIFactory()  | 
|
44  | 
pb = ui.progress_bar()  | 
|
45  | 
        # TODO: Test the output from TextUIFactory, perhaps by overriding sys.stdout
 | 
|
46  | 
||
47  | 
        # Unfortunately we can't actually test the ui.get_password() because 
 | 
|
48  | 
        # that would actually prompt the user for a password during the test suite
 | 
|
49  | 
        # This has been tested manually with both LANG=en_US.utf-8 and LANG=C
 | 
|
50  | 
        # print
 | 
|
51  | 
        # self.assertEquals(ui.get_password(u"%(user)s please type 'bogus'",
 | 
|
52  | 
        #                                   user=u'some\u1234')
 | 
|
53  | 
        #                  , 'bogus')
 | 
|
54  | 
||
| 
1534.5.6
by Robert Collins
 split out converter logic into per-format objects.  | 
55  | 
|
56  | 
def test_progress_note(self):  | 
|
57  | 
stderr = StringIO()  | 
|
58  | 
stdout = StringIO()  | 
|
59  | 
ui = TextUIFactory()  | 
|
60  | 
pb = TTYProgressBar(to_file=stderr, to_messages_file=stdout)  | 
|
61  | 
result = pb.note('t')  | 
|
62  | 
self.assertEqual(None, result)  | 
|
63  | 
self.assertEqual("t\n", stdout.getvalue())  | 
|
64  | 
self.assertEqual("\r \r", stderr.getvalue())  |