~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2015-10-23 09:05:09 UTC
  • mto: This revision was merged to the branch mainline in revision 6612.
  • Revision ID: v.ladeuil+lp@free.fr-20151023090509-rd6ecc21opzfgx8f
Add rename() and open_write_stream() as explicitly not supported via the ReadonlyTransportDecorator to give better feedback when a decorated transport is misused

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2010, 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
16
16
 
17
17
"""Black-box tests for bzr nick."""
18
18
 
19
 
import os
20
 
 
21
19
import bzrlib
22
 
from bzrlib import osutils
23
 
from bzrlib.tests import TestCaseWithTransport
24
 
 
25
 
 
26
 
class TestNick(TestCaseWithTransport):
 
20
from bzrlib import (
 
21
    branch,
 
22
    osutils,
 
23
    tests,
 
24
    )
 
25
 
 
26
 
 
27
class TestNick(tests.TestCaseWithTransport):
 
28
 
 
29
    def assertNick(self, expected, working_dir='.', explicit=None,
 
30
                   directory=None):
 
31
        cmd = ['nick']
 
32
        if directory is not None:
 
33
            cmd.extend(['--directory', directory])
 
34
        # The nick command outputs the nick on a single line
 
35
        actual = self.run_bzr(cmd, working_dir=working_dir)[0][:-1]
 
36
        self.assertEquals(expected, actual)
 
37
        if explicit is not None:
 
38
            br = branch.Branch.open(working_dir)
 
39
            conf = br.get_config()
 
40
            self.assertEquals(explicit, conf.has_explicit_nickname())
 
41
            if explicit:
 
42
                self.assertEquals(expected, conf._get_explicit_nickname())
27
43
 
28
44
    def test_nick_command(self):
29
45
        """bzr nick for viewing, setting nicknames"""
30
46
        self.make_branch_and_tree('me.dev')
31
 
        os.chdir('me.dev')
32
 
        nick = self.run_bzr('nick')[0]
33
 
        self.assertEqual('me.dev\n', nick)
 
47
        self.assertNick('me.dev', working_dir='me.dev')
34
48
        # set the nickname
35
 
        self.run_bzr("nick moo")
36
 
        nick = self.run_bzr('nick')[0]
37
 
        self.assertEqual('moo\n', nick)
 
49
        self.run_bzr("nick moo", working_dir='me.dev')
 
50
        self.assertNick('moo', working_dir='me.dev')
38
51
 
39
52
    def test_autonick_urlencoded(self):
40
53
        # https://bugs.launchpad.net/bzr/+bug/66857 -- nick was printed
41
54
        # urlencoded but shouldn't be
42
55
        self.make_branch_and_tree('!repo')
43
 
        os.chdir('!repo')
44
 
        nick = self.run_bzr('nick')[0]
45
 
        self.assertEqual('!repo\n', nick)
 
56
        self.assertNick('!repo', working_dir='!repo')
46
57
 
47
58
    def test_bound_nick(self):
48
 
        """Check that nick works well for checkouts."""
49
 
        base = self.make_branch_and_tree('base')
50
 
        child = self.make_branch_and_tree('child')
51
 
        os.chdir('child')
52
 
        self.assertEqual('child', self.run_bzr('nick')[0][:-1])
53
 
        self.assertEqual(False,
54
 
                         child.branch.get_config().has_explicit_nickname())
55
 
        self.run_bzr('bind ../base')
56
 
        self.assertEqual(base.branch.nick, self.run_bzr('nick')[0][:-1])
57
 
        self.assertEqual(False,
58
 
                         child.branch.get_config().has_explicit_nickname())
59
 
 
60
 
        self.run_bzr('unbind')
61
 
        self.run_bzr("nick explicit_nick")
62
 
        self.assertEqual("explicit_nick", self.run_bzr('nick')[0][:-1])
63
 
        self.assertEqual("explicit_nick",
64
 
                         child.branch.get_config()._get_explicit_nickname())
65
 
        self.run_bzr('bind ../base')
66
 
        self.assertEqual(base.branch.nick, self.run_bzr('nick')[0][:-1])
67
 
        self.assertEqual(base.branch.nick,
68
 
                         child.branch.get_config()._get_explicit_nickname())
 
59
        """Bind should not update implicit nick."""
 
60
        base = self.make_branch_and_tree('base')
 
61
        child = self.make_branch_and_tree('child')
 
62
        self.assertNick('child', working_dir='child', explicit=False)
 
63
 
 
64
        self.run_bzr('bind ../base', working_dir='child')
 
65
        self.assertNick(base.branch.nick, working_dir='child', explicit=False)
 
66
 
 
67
    def test_bound_nick_explicit(self):
 
68
        """Bind should update explicit nick."""
 
69
        base = self.make_branch_and_tree('base')
 
70
        child = self.make_branch_and_tree('child')
 
71
        self.run_bzr("nick explicit_nick", working_dir='child')
 
72
        self.assertNick('explicit_nick', working_dir='child', explicit=True)
 
73
        self.run_bzr('bind ../base', working_dir='child')
 
74
        self.assertNick(base.branch.nick, working_dir='child', explicit=True)
69
75
 
70
76
    def test_boundless_nick(self):
71
77
        """Nick defaults to implicit local nick when bound branch is AWOL"""
72
78
        base = self.make_branch_and_tree('base')
73
79
        child = self.make_branch_and_tree('child')
74
 
        os.chdir('child')
75
 
        self.run_bzr('bind ../base')
76
 
        self.assertEqual(base.branch.nick, self.run_bzr('nick')[0][:-1])
77
 
        self.assertEqual(False,
78
 
                         child.branch.get_config().has_explicit_nickname())
79
 
        osutils.rmtree('../base')
80
 
        self.assertEqual('child', self.run_bzr('nick')[0][:-1])
 
80
        self.run_bzr('bind ../base', working_dir='child')
 
81
        self.assertNick(base.branch.nick, working_dir='child', explicit=False)
 
82
        osutils.rmtree('base')
 
83
        self.assertNick('child', working_dir='child', explicit=False)
81
84
 
82
85
    def test_nick_directory(self):
83
86
        """Test --directory option"""
84
87
        self.make_branch_and_tree('me.dev')
85
 
        nick = self.run_bzr(['nick', '--directory=me.dev'])[0]
86
 
        self.assertEqual('me.dev\n', nick)
 
88
        self.assertNick('me.dev', directory='me.dev')
87
89
        self.run_bzr(['nick', '-d', 'me.dev', 'moo'])
88
 
        nick = self.run_bzr(['nick', '--directory', 'me.dev'])[0]
89
 
        self.assertEqual('moo\n', nick)
 
90
        self.assertNick('moo', directory='me.dev')