~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ross Lagerwall
  • Date: 2012-08-07 06:32:51 UTC
  • mto: (6437.63.5 2.5)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: rosslagerwall@gmail.com-20120807063251-x9p03ghg2ws8oqjc
Add bzrlib/locale to .bzrignore

bzrlib/locale is generated with ./setup.py build_mo which is in turn called
by ./setup.py build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
 
20
20
import bzrlib
21
21
from bzrlib import (
22
 
    branch,
23
22
    config,
24
23
    errors,
25
24
    tests,
30
29
 
31
30
    def assertWhoAmI(self, expected, *cmd_args, **kwargs):
32
31
        out, err = self.run_bzr(('whoami',) + cmd_args, **kwargs)
33
 
        self.assertEqual('', err)
 
32
        self.assertEquals('', err)
34
33
        lines = out.splitlines()
35
34
        self.assertLength(1, lines)
36
 
        self.assertEqual(expected, lines[0].rstrip())
 
35
        self.assertEquals(expected, lines[0].rstrip())
37
36
 
38
37
    def test_whoami_no_args_no_conf(self):
39
38
        # this should always identify something, if only "john@localhost"
40
39
        out = self.run_bzr("whoami")[0]
41
40
        self.assertTrue(len(out) > 0)
42
 
        self.assertEqual(1, out.count('@'))
 
41
        self.assertEquals(1, out.count('@'))
43
42
 
44
43
    def test_whoami_email_no_args(self):
45
44
        out = self.run_bzr("whoami --email")[0]
46
45
        self.assertTrue(len(out) > 0)
47
 
        self.assertEqual(1, out.count('@'))
 
46
        self.assertEquals(1, out.count('@'))
48
47
 
49
48
    def test_whoami_email_arg(self):
50
49
        # whoami --email is mutually exclusive with any arguments
51
50
        out = self.run_bzr("whoami --email 'foo <foo@example.com>'", 3)[0]
52
 
        self.assertEqual("", out)
53
 
 
54
 
    def set_branch_email(self, b, email):
55
 
        b.get_config_stack().set('email', email)
 
51
        self.assertEquals("", out)
56
52
 
57
53
    def test_whoami_branch(self):
58
54
        """branch specific user identity works."""
59
55
        wt = self.make_branch_and_tree('.')
60
56
        b = bzrlib.branch.Branch.open('.')
61
 
        self.set_branch_email(b, 'Branch Identity <branch@identi.ty>')
 
57
        b.get_config_stack().set('email', 'Branch Identity <branch@identi.ty>')
62
58
        self.assertWhoAmI('Branch Identity <branch@identi.ty>')
63
59
        self.assertWhoAmI('branch@identi.ty', '--email')
64
60
 
83
79
        """
84
80
        wt = self.make_branch_and_tree('.')
85
81
        b = bzrlib.branch.Branch.open('.')
86
 
        self.set_branch_email(b, u'Branch Identity \u20ac <branch@identi.ty>')
 
82
        b.get_config_stack().set(
 
83
            'email', u'Branch Identity \u20ac ' + '<branch@identi.ty>')
87
84
        self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
88
85
                          encoding='ascii')
89
86
        self.assertWhoAmI('branch@identi.ty', '--email',
93
90
        """verify that a warning is displayed if no email is given."""
94
91
        self.make_branch_and_tree('.')
95
92
        display = self.run_bzr(['whoami', 'Branch Identity'])[1]
96
 
        self.assertEqual('"Branch Identity" does not seem to contain an '
 
93
        self.assertEquals('"Branch Identity" does not seem to contain an '
97
94
                          'email address.  This is allowed, but not '
98
95
                          'recommended.\n', display)
99
96
 
103
100
        self.overrideEnv('EMAIL', None)
104
101
        self.overrideEnv('BZR_EMAIL', None)
105
102
        # Also, make sure that it's not inferred from mailname.
106
 
        self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
 
103
        self.overrideAttr(config, '_auto_user_id',
 
104
            lambda: (None, None))
107
105
        out, err = self.run_bzr(['whoami'], 3)
108
106
        self.assertContainsRe(err, 'Unable to determine your name')
109
107
 
110
108
    def test_whoami_directory(self):
111
109
        """Test --directory option."""
112
110
        wt = self.make_branch_and_tree('subdir')
113
 
        self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
 
111
        c = wt.branch.get_config_stack()
 
112
        c.set('email', 'Branch Identity <branch@identi.ty>')
114
113
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
115
114
                          '--directory', 'subdir')
116
115
        self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
117
116
                      'Changed Identity <changed@identi.ty>'])
118
 
        # Refresh wt as 'whoami' modified it
119
 
        wt = wt.bzrdir.open_workingtree()
120
117
        c = wt.branch.get_config_stack()
121
 
        self.assertEqual('Changed Identity <changed@identi.ty>',
 
118
        self.assertEquals('Changed Identity <changed@identi.ty>',
122
119
                          c.get('email'))
123
120
 
124
121
    def test_whoami_remote_directory(self):
125
122
        """Test --directory option with a remote directory."""
126
123
        wt = self.make_branch_and_tree('subdir')
127
 
        self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
 
124
        c = wt.branch.get_config_stack()
 
125
        c.set('email', 'Branch Identity <branch@identi.ty>')
128
126
        url = self.get_readonly_url() + '/subdir'
129
127
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
130
128
                          '--directory', url)
133
131
                      'Changed Identity <changed@identi.ty>'])
134
132
        # The identity has been set in the branch config (but not the global
135
133
        # config)
136
 
        c = branch.Branch.open(url).get_config_stack()
137
 
        self.assertEqual('Changed Identity <changed@identi.ty>',
 
134
        c = wt.branch.get_config_stack()
 
135
        self.assertEquals('Changed Identity <changed@identi.ty>',
138
136
                          c.get('email'))
139
137
        # Ensuring that the value does not come from the bazaar.conf file
140
138
        # itself requires some isolation setup