~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_unversion.py

  • Committer: Robert Collins
  • Date: 2006-09-08 00:19:48 UTC
  • mfrom: (1992 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1993.
  • Revision ID: robertc@robertcollins.net-20060908001948-87b1b268cec30ede
Merge bzr.dev and undeprecated WorkingTree.last_revision as per review feedback.

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
"""Tests of the WorkingTree.unversion API."""
 
18
 
 
19
from bzrlib import errors
 
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
21
 
 
22
 
 
23
class TestUnversion(TestCaseWithWorkingTree):
 
24
 
 
25
    def test_unversion_requires_write_lock(self):
 
26
        """WT.unversion([]) in a read lock raises ReadOnlyError."""
 
27
        tree = self.make_branch_and_tree('.')
 
28
        tree.lock_read()
 
29
        self.assertRaises(errors.ReadOnlyError, tree.unversion, [])
 
30
        tree.unlock()
 
31
 
 
32
    def test_unversion_missing_file(self):
 
33
        """WT.unversion(['missing-id']) raises NoSuchId."""
 
34
        tree = self.make_branch_and_tree('.')
 
35
        self.assertRaises(errors.NoSuchId, tree.unversion, ['missing-id'])
 
36
 
 
37
    def test_unversion_several_files(self):
 
38
        """After unversioning several files, they should not be versioned."""
 
39
        tree = self.make_branch_and_tree('.')
 
40
        self.build_tree(['a', 'b', 'c'])
 
41
        tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
 
42
        # within a lock unversion should take effect
 
43
        tree.lock_write()
 
44
        tree.unversion(['a-id', 'b-id'])
 
45
        self.assertFalse(tree.has_id('a-id'))
 
46
        self.assertFalse(tree.has_id('b-id'))
 
47
        self.assertTrue(tree.has_id('c-id'))
 
48
        self.assertTrue(tree.has_filename('a'))
 
49
        self.assertTrue(tree.has_filename('b'))
 
50
        self.assertTrue(tree.has_filename('c'))
 
51
        tree.unlock()
 
52
        # the changes should have persisted to disk - reopen the workingtree
 
53
        # to be sure.
 
54
        tree = tree.bzrdir.open_workingtree()
 
55
        self.assertFalse(tree.has_id('a-id'))
 
56
        self.assertFalse(tree.has_id('b-id'))
 
57
        self.assertTrue(tree.has_id('c-id'))
 
58
        self.assertTrue(tree.has_filename('a'))
 
59
        self.assertTrue(tree.has_filename('b'))
 
60
        self.assertTrue(tree.has_filename('c'))
 
61
        
 
62
    def test_unversion_subtree(self):
 
63
        """Unversioning the root of a subtree unversions the entire subtree."""
 
64
        tree = self.make_branch_and_tree('.')
 
65
        self.build_tree(['a/', 'a/b', 'c'])
 
66
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
 
67
        # within a lock unversion should take effect
 
68
        tree.lock_write()
 
69
        tree.unversion(['a-id'])
 
70
        self.assertFalse(tree.has_id('a-id'))
 
71
        self.assertFalse(tree.has_id('b-id'))
 
72
        self.assertTrue(tree.has_id('c-id'))
 
73
        self.assertTrue(tree.has_filename('a'))
 
74
        self.assertTrue(tree.has_filename('a/b'))
 
75
        self.assertTrue(tree.has_filename('c'))
 
76
        tree.unlock()