~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
2027.4.1 by John Arbash Meinel
Factor the 'bzr inventory' tests out of tests_too_much
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
"""Black-box tests for 'bzr inventory'."""
18
2027.4.3 by John Arbash Meinel
Change how 'bzr inventory' finds paths
19
import os
20
2027.4.1 by John Arbash Meinel
Factor the 'bzr inventory' tests out of tests_too_much
21
from bzrlib.tests import TestCaseWithTransport
22
23
24
class TestInventory(TestCaseWithTransport):
25
26
    def setUp(self):
27
        TestCaseWithTransport.setUp(self)
28
29
        tree = self.make_branch_and_tree('.')
30
        self.build_tree(['a', 'b/', 'b/c'])
31
32
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
33
        tree.commit('init', rev_id='one')
2027.4.3 by John Arbash Meinel
Change how 'bzr inventory' finds paths
34
        self.tree = tree
2027.4.1 by John Arbash Meinel
Factor the 'bzr inventory' tests out of tests_too_much
35
36
    def assertInventoryEqual(self, expected, *args, **kwargs):
37
        """Test that the output of 'bzr inventory' is as expected.
38
39
        Any arguments supplied will be passed to run_bzr.
40
        """
41
        out, err = self.run_bzr('inventory', *args, **kwargs)
42
        self.assertEqual(expected, out)
43
        self.assertEqual('', err)
44
        
45
    def test_inventory(self):
46
        self.assertInventoryEqual('a\nb\nb/c\n')
47
48
    def test_inventory_kind(self):
49
        self.assertInventoryEqual('a\nb/c\n', '--kind', 'file')
50
        self.assertInventoryEqual('b\n', '--kind', 'directory')
51
52
    def test_inventory_show_ids(self):
53
        expected = ''.join(('%-50s %s\n' % (path, file_id))
54
                                for path, file_id in
55
                                [('a', 'a-id'),
56
                                 ('b', 'b-id'),
57
                                 ('b/c', 'c-id')
58
                                ]
59
                          )
60
        self.assertInventoryEqual(expected, '--show-ids')
2027.4.2 by John Arbash Meinel
Fix bug #3631, allow 'bzr inventory filename'
61
62
    def test_inventory_specific_files(self):
63
        self.assertInventoryEqual('a\n', 'a')
64
        self.assertInventoryEqual('b\nb/c\n', 'b', 'b/c')
2027.4.3 by John Arbash Meinel
Change how 'bzr inventory' finds paths
65
        # 'bzr inventory' recurses into subdirectories
66
        self.assertInventoryEqual('b\nb/c\n', 'b')
2027.4.2 by John Arbash Meinel
Fix bug #3631, allow 'bzr inventory filename'
67
2027.4.3 by John Arbash Meinel
Change how 'bzr inventory' finds paths
68
    def test_inventory_mixed(self):
2027.4.2 by John Arbash Meinel
Fix bug #3631, allow 'bzr inventory filename'
69
        """Test that we get expected results when mixing parameters"""
70
        a_line = '%-50s %s\n' % ('a', 'a-id')
71
        b_line = '%-50s %s\n' % ('b', 'b-id')
72
        c_line = '%-50s %s\n' % ('b/c', 'c-id')
73
74
        self.assertInventoryEqual('', '--kind', 'directory', 'a')
75
        self.assertInventoryEqual(a_line + c_line, '--kind', 'file',
76
                                                   '--show-ids')
77
        self.assertInventoryEqual(c_line, '--kind', 'file', '--show-ids',
78
                                          'b', 'b/c')
2027.4.3 by John Arbash Meinel
Change how 'bzr inventory' finds paths
79
80
    def test_in_subdir(self):
81
        os.chdir('b')
82
        # TODO: jam 20060922 Maybe inventory should return the paths as
83
        #       relative to '.', rather than relative to root
84
85
        # a plain 'inventory' returns all files
86
        self.assertInventoryEqual('a\nb\nb/c\n')
87
        # But passing '.' will only return paths underneath here
88
        self.assertInventoryEqual('b\nb/c\n', '.')
89
90
91
    def test_inventory_revision(self):
92
        self.build_tree(['b/d', 'e'])
93
        self.tree.add(['b/d', 'e'], ['d-id', 'e-id'])
94
        self.tree.commit('add files')
95
96
        self.tree.rename_one('b/d', 'd')
97
        self.tree.commit('rename b/d => d')
98
99
        # Passing just -r returns the inventory of that revision
100
        self.assertInventoryEqual('a\nb\nb/c\n', '-r', '1')
101
        self.assertInventoryEqual('a\nb\nb/c\nb/d\ne\n', '-r', '2')
102
103
        # Passing a path will lookup the path in the old and current locations
104
        self.assertInventoryEqual('b/d\n', '-r', '2', 'b/d')
105
        self.assertInventoryEqual('b/d\n', '-r', '2', 'd')
2027.4.4 by John Arbash Meinel
more tests for 'bzr inventory' including errors and nesting
106
107
        self.tree.rename_one('e', 'b/e')
108
        self.tree.commit('rename e => b/e')
109
110
        # When supplying just a directory paths that are now,
111
        # or used to be, in that directory are shown
112
        self.assertInventoryEqual('b\nb/c\nb/d\ne\n', '-r', '2', 'b')
113
114
    def test_missing_file(self):
115
        self.run_bzr_error([r'Path\(s\) are not versioned: no-such-file'],
116
                           'inventory', 'no-such-file')