~bzr-pqm/bzr/bzr.dev

2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
1
# Copyright (C) 2007 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
"""Test that we can use smart_add on all Tree implementations."""
18
19
from bzrlib import (
20
    add,
21
    errors,
22
    workingtree,
23
    )
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
24
from bzrlib.add import (
25
    AddAction,
26
    AddFromBaseAction,
27
    smart_add,
28
    smart_add_tree,
29
    )
30
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
31
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
32
33
34
class TestSmartAddTree(TestCaseWithWorkingTree):
35
36
    def test_single_file(self):
37
        tree = self.make_branch_and_tree('tree')
38
        self.build_tree(['tree/a'])
39
        add.smart_add_tree(tree, ['tree'])
40
41
        tree.lock_read()
42
        try:
43
            files = [(path, status, kind)
44
                     for path, status, kind, file_id, parent_id
45
                      in tree.list_files(include_root=True)]
46
        finally:
47
            tree.unlock()
48
        self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
49
                         files)
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
50
51
    def test_save_false(self):
52
        """Dry-run add doesn't permanently affect the tree."""
53
        wt = self.make_branch_and_tree('.')
54
        self.build_tree(['file'])
55
        smart_add_tree(wt, ['file'], save=False)
56
        # The in-memory inventory is left modified in inventory-based trees;
57
        # it may not be in dirstate trees.  Anyhow, now we reload to make sure
58
        # the on-disk version is not modified.
59
        wt = wt.bzrdir.open_workingtree()
60
        self.assertEqual(wt.path2id('file'), None)