~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Deprecate compare_trees and move its body to InterTree.changes_from.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 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
 
 
18
"""Black-box tests for bzr whoami."""
 
19
 
 
20
import os
 
21
 
 
22
import bzrlib
 
23
from bzrlib.branch import Branch
 
24
from bzrlib.tests.blackbox import ExternalBase
 
25
 
 
26
 
 
27
class TestWhoami(ExternalBase):
 
28
 
 
29
    def test_whoami(self):
 
30
        # this should always identify something, if only "john@localhost"
 
31
        out = self.run_bzr("whoami")[0]
 
32
        self.assertTrue(len(out) > 0)
 
33
        self.assertEquals(1, out.count('@'))
 
34
 
 
35
        out = self.run_bzr("whoami", "--email")[0]
 
36
        self.assertTrue(len(out) > 0)
 
37
        self.assertEquals(1, out.count('@'))
 
38
        
 
39
    def test_whoami_branch(self):
 
40
        """branch specific user identity works."""
 
41
        wt = self.make_branch_and_tree('.')
 
42
        b = bzrlib.branch.Branch.open('.')
 
43
        b.get_config().set_user_option('email',
 
44
                                       'Branch Identity <branch@identi.ty>')
 
45
        bzr_email = os.environ.get('BZREMAIL')
 
46
        if bzr_email is not None:
 
47
            del os.environ['BZREMAIL']
 
48
        try:
 
49
            whoami = self.run_bzr("whoami")[0]
 
50
            self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
 
51
            whoami_email = self.run_bzr("whoami", "--email")[0]
 
52
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
53
 
 
54
            # Verify that the environment variable overrides the value 
 
55
            # in the file
 
56
            os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
 
57
            whoami = self.run_bzr("whoami")[0]
 
58
            self.assertEquals('Different ID <other@environ.ment>\n', whoami)
 
59
            whoami_email = self.run_bzr("whoami", "--email")[0]
 
60
            self.assertEquals('other@environ.ment\n', whoami_email)
 
61
        finally:
 
62
            if bzr_email is not None:
 
63
                os.environ['BZREMAIL'] = bzr_email
 
64
 
 
65
    def test_whoami_utf8(self):
 
66
        """verify that an identity can be in utf-8."""
 
67
        wt = self.make_branch_and_tree('.')
 
68
        self.run_bzr('whoami', u'Branch Identity \u20ac <branch@identi.ty>',
 
69
                     encoding='utf-8')
 
70
        bzr_email = os.environ.get('BZREMAIL')
 
71
        if bzr_email is not None:
 
72
            del os.environ['BZREMAIL']
 
73
        try:
 
74
            whoami = self.run_bzr("whoami", encoding='utf-8')[0]
 
75
            self.assertEquals('Branch Identity \xe2\x82\xac ' +
 
76
                              '<branch@identi.ty>\n', whoami)
 
77
            whoami_email = self.run_bzr("whoami", "--email",
 
78
                                        encoding='utf-8')[0]
 
79
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
80
        finally:
 
81
            if bzr_email is not None:
 
82
                os.environ['BZREMAIL'] = bzr_email
 
83
 
 
84
    def test_whoami_ascii(self):
 
85
        """
 
86
        verify that whoami doesn't totally break when in utf-8, using an ascii
 
87
        encoding.
 
88
        """
 
89
        wt = self.make_branch_and_tree('.')
 
90
        b = bzrlib.branch.Branch.open('.')
 
91
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
 
92
                                       '<branch@identi.ty>')
 
93
        bzr_email = os.environ.get('BZREMAIL')
 
94
        if bzr_email is not None:
 
95
            del os.environ['BZREMAIL']
 
96
        try:
 
97
            whoami = self.run_bzr("whoami", encoding='ascii')[0]
 
98
            self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
 
99
            whoami_email = self.run_bzr("whoami", "--email",
 
100
                                        encoding='ascii')[0]
 
101
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
102
        finally:
 
103
            if bzr_email is not None:
 
104
                os.environ['BZREMAIL'] = bzr_email
 
105
 
 
106
    def test_warning(self):
 
107
        """verify that a warning is displayed if no email is given."""
 
108
        self.make_branch_and_tree('.')
 
109
        display = self.run_bzr('whoami', 'Branch Identity')[1]
 
110
        self.assertEquals('"Branch Identity" does not seem to contain an '
 
111
                          'email address.  This is allowed, but not '
 
112
                          'recommended.\n', display)