~bzr-pqm/bzr/bzr.dev

963 by Martin Pool
- add the start of a test for inventory file-id matching
1
# Copyright (C) 2005 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
from bzrlib.selftest import TestBase
18
19
from bzrlib.inventory import Inventory, InventoryEntry
20
969 by Martin Pool
- Add less-sucky is_within_any
21
963 by Martin Pool
- add the start of a test for inventory file-id matching
22
class TestIsWithin(TestBase):
23
    def runTest(self):
968 by Martin Pool
- add some passing tests for is_inside_any
24
        from bzrlib.osutils import is_inside_any
25
        
26
        for dirs, fn in [(['src', 'doc'], 'src/foo.c'),
27
                         (['src'], 'src/foo.c'),
28
                         (['src'], 'src'),
29
                         ]:
30
            self.assert_(is_inside_any(dirs, fn))
31
            
969 by Martin Pool
- Add less-sucky is_within_any
32
        for dirs, fn in [(['src'], 'srccontrol'),
33
                         (['src'], 'srccontrol/foo')]:
34
            self.assertFalse(is_inside_any(dirs, fn))
35
            
36
            
968 by Martin Pool
- add some passing tests for is_inside_any
37
            
38
class TestInventoryIds(TestBase):
39
    def runTest(self):
963 by Martin Pool
- add the start of a test for inventory file-id matching
40
        """Test detection of files within selected directories."""
41
        inv = Inventory()
42
        
43
        for args in [('src', 'directory', 'src-id'), 
44
                     ('doc', 'directory', 'doc-id'), 
45
                     ('src/hello.c', 'file'),
46
                     ('src/bye.c', 'file', 'bye-id'),
47
                     ('Makefile', 'file')]:
48
            inv.add_path(*args)
49
            
50
        self.assertEqual(inv.path2id('src'), 'src-id')
51
        self.assertEqual(inv.path2id('src/bye.c'), 'bye-id')
52
        
53
        self.assert_('src-id' in inv)