/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Daniel Silverstone
  • Date: 2006-11-11 13:04:54 UTC
  • mto: This revision was merged to the branch mainline in revision 2135.
  • Revision ID: dsilvers@digital-scurf.org-20061111130454-12fc35cbbf0a331f
Refactor the remove-tree stuff after review from J-A-M

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2006 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
16
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
16
 
18
17
 
19
 
"""Black-box tests for bzr remove-tree.
20
 
"""
 
18
"""Black-box tests for bzr remove-tree."""
21
19
 
22
20
import os
23
21
 
24
22
from bzrlib.tests.blackbox import ExternalBase
25
23
 
 
24
 
26
25
class TestRemoveTree(ExternalBase):
27
26
 
28
 
    def _present(self, f):
29
 
        self.assertEquals(os.path.exists(f), True)
30
 
 
31
 
    def _absent(self, f):
32
 
        self.assertEquals(os.path.exists(f), False)
33
 
 
34
 
 
35
 
    def test_remove_tree(self):
36
 
 
37
 
        def bzr(*args, **kwargs):
38
 
            return self.run_bzr(*args, **kwargs)[0]
39
 
 
40
 
        os.mkdir('branch1')
 
27
    def setUp(self):
 
28
        super(TestRemoveTree, self).setUp()
 
29
        self.tree = self.make_branch_and_tree('branch1')
 
30
        self.build_tree(['branch1/foo'])
 
31
        self.tree.add('foo')
 
32
        self.tree.commit('1')
 
33
        self.failUnlessExists('branch1/foo')
 
34
 
 
35
    # Success modes
 
36
 
 
37
    def test_remove_tree_original_branch(self):
41
38
        os.chdir('branch1')
42
 
        bzr('init')
43
 
        f=open('foo','wb')
44
 
        f.write("foo\n")
45
 
        f.close()
46
 
        bzr('add', 'foo')
47
 
 
48
 
        bzr('commit', '-m', '1')
49
 
 
50
 
        os.chdir("..")
51
 
 
52
 
        self._present("branch1/foo")
53
 
        bzr('branch', 'branch1', 'branch2')
54
 
        self._present("branch2/foo")
55
 
        bzr('checkout', 'branch1', 'branch3')
56
 
        self._present("branch3/foo")
57
 
        bzr('checkout', '--lightweight', 'branch1', 'branch4')
58
 
        self._present("branch4/foo")
59
 
 
60
 
        # branch1 == branch
61
 
        # branch2 == branch of branch1
62
 
        # branch3 == checkout of branch1
63
 
        # branch4 == lightweight checkout of branch1
64
 
 
65
 
        # bzr remove-tree (CWD)
66
 
        os.chdir("branch1")
67
 
        bzr('remove-tree')
68
 
        os.chdir("..")
69
 
        self._absent("branch1/foo")
70
 
 
71
 
        # bzr remove-tree (path)
72
 
        bzr('remove-tree', 'branch2')
73
 
        self._absent("branch2/foo")
74
 
 
75
 
        # bzr remove-tree (checkout)
76
 
        bzr('remove-tree', 'branch3')
77
 
        self._absent("branch3/foo")
78
 
 
79
 
        # bzr remove-tree (lightweight checkout, refuse)
80
 
        bzr('remove-tree', 'branch4', retcode=3)
81
 
        self._present("branch4/foo")
 
39
        self.run_bzr('remove-tree')
 
40
        self.failIfExists('foo')
 
41
    
 
42
    def test_remove_tree_original_branch_explicit(self):
 
43
        self.run_bzr('remove-tree', 'branch1')
 
44
        self.failIfExists('branch1/foo')
 
45
 
 
46
    def test_remove_tree_sprouted_branch(self):
 
47
        self.tree.bzrdir.sprout('branch2')
 
48
        self.failUnlessExists('branch2/foo')
 
49
        os.chdir('branch2')
 
50
        self.run_bzr('remove-tree')
 
51
        self.failIfExists('foo')
 
52
    
 
53
    def test_remove_tree_sprouted_branch_explicit(self):
 
54
        self.tree.bzrdir.sprout('branch2')
 
55
        self.failUnlessExists('branch2/foo')
 
56
        self.run_bzr('remove-tree', 'branch2')
 
57
        self.failIfExists('branch2/foo')
 
58
 
 
59
    def test_remove_tree_checkout(self):
 
60
        self.tree.branch.create_checkout('branch2', lightweight=False)
 
61
        self.failUnlessExists('branch2/foo')
 
62
        os.chdir('branch2')
 
63
        self.run_bzr('remove-tree')
 
64
        self.failIfExists('foo')
 
65
        os.chdir('..')
 
66
        self.failUnlessExists('branch1/foo')
 
67
    
 
68
    def test_remove_tree_checkout_explicit(self):
 
69
        self.tree.branch.create_checkout('branch2', lightweight=False)
 
70
        self.failUnlessExists('branch2/foo')
 
71
        self.run_bzr('remove-tree', 'branch2')
 
72
        self.failIfExists('branch2/foo')
 
73
        self.failUnlessExists('branch1/foo')
 
74
 
 
75
    # Failure modes
 
76
 
 
77
    def test_remove_tree_lightweight_checkout(self):
 
78
        self.tree.branch.create_checkout('branch2', lightweight=True)
 
79
        self.failUnlessExists('branch2/foo')
 
80
        os.chdir('branch2')
 
81
        output = self.run_bzr_error(
 
82
            ["Cannot remove working tree from lightweight checkout"],
 
83
            'remove-tree', retcode=3)
 
84
        self.failUnlessExists('foo')
 
85
        os.chdir('..')
 
86
        self.failUnlessExists('branch1/foo')
 
87
    
 
88
    def test_remove_tree_lightweight_checkout_explicit(self):
 
89
        self.tree.branch.create_checkout('branch2', lightweight=True)
 
90
        self.failUnlessExists('branch2/foo')
 
91
        output = self.run_bzr(
 
92
            ["Cannot remove working tree from lightweight checkout"],
 
93
            'remove-tree', 'branch2', retcode=3)
 
94
        self.failUnlessExists('branch2/foo')
 
95
        self.failUnlessExists('branch1/foo')
 
96
 
 
97
    def test_remove_tree_empty_dir(self):
 
98
        os.mkdir('branch2')
 
99
        os.chdir('branch2')
 
100
        output = self.run_bzr(["Not a branch"],
 
101
                              'remove-tree', retcode=3)
 
102
 
 
103
    def test_remove_tree_repeatedly(self):
 
104
        self.run_bzr('remove-tree', 'branch1')
 
105
        self.failIfExists('branch1/foo')
 
106
        output = self.run_bzr_error(["No working tree to remove"],
 
107
                                    'remove-tree', 'branch1', retcode=3)
 
108
 
 
109
    def test_remove_tree_remote_path(self):
 
110
        # TODO: I can't think of a way to implement this...
 
111
        pass