~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-05-11 06:20:05 UTC
  • Revision ID: mbp@sourcefrog.net-20050511062005-297af3451635dae0
- Don't lose first line of command help!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
 
3
 
import os
4
 
import unittest
5
 
 
6
 
from bzrlib.selftest import InTempDir, TestBase
7
 
from bzrlib.branch import ScratchBranch, Branch
8
 
from bzrlib.errors import NotBranchError
9
 
 
10
 
 
11
 
class RenameDirs(InTempDir):
12
 
    """Test renaming directories and the files within them."""
13
 
    def runTest(self):
14
 
        from bzrlib.commit import commit
15
 
 
16
 
        b = Branch('.', init=True)
17
 
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
18
 
        b.add(['dir', 'dir/sub', 'dir/sub/file'])
19
 
 
20
 
        b.commit('create initial state')
21
 
 
22
 
        # TODO: lift out to a test helper that checks the shape of
23
 
        # an inventory
24
 
        
25
 
        revid = b.revision_history()[0]
26
 
        self.log('first revision_id is {%s}' % revid)
27
 
        
28
 
        inv = b.get_revision_inventory(revid)
29
 
        self.log('contents of inventory: %r' % inv.entries())
30
 
 
31
 
        self.check_inventory_shape(inv,
32
 
                                   ['dir', 'dir/sub', 'dir/sub/file'])
33
 
 
34
 
        b.rename_one('dir', 'newdir')
35
 
 
36
 
        self.check_inventory_shape(b.inventory,
37
 
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
38
 
 
39
 
        b.rename_one('newdir/sub', 'newdir/newsub')
40
 
        self.check_inventory_shape(b.inventory,
41
 
                                   ['newdir', 'newdir/newsub',
42
 
                                    'newdir/newsub/file'])
43
 
 
44
 
        
45
 
 
46
 
 
47
 
class BranchPathTestCase(TestBase):
48
 
    """test for branch path lookups
49
 
 
50
 
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
51
 
    job: given a path (either relative to cwd or absolute), work out
52
 
    if it is inside a branch and return the path relative to the base.
53
 
    """
54
 
 
55
 
    def runTest(self):
56
 
        from bzrlib.branch import _relpath
57
 
        import tempfile, shutil
58
 
        
59
 
        savedir = os.getcwdu()
60
 
        dtmp = tempfile.mkdtemp()
61
 
 
62
 
        def rp(p):
63
 
            return _relpath(dtmp, p)
64
 
        
65
 
        try:
66
 
            # check paths inside dtmp while standing outside it
67
 
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
68
 
 
69
 
            # root = nothing
70
 
            self.assertEqual(rp(dtmp), '')
71
 
 
72
 
            self.assertRaises(NotBranchError,
73
 
                              rp,
74
 
                              '/etc')
75
 
 
76
 
            # now some near-miss operations -- note that
77
 
            # os.path.commonprefix gets these wrong!
78
 
            self.assertRaises(NotBranchError,
79
 
                              rp,
80
 
                              dtmp.rstrip('\\/') + '2')
81
 
 
82
 
            self.assertRaises(NotBranchError,
83
 
                              rp,
84
 
                              dtmp.rstrip('\\/') + '2/foo')
85
 
 
86
 
            # now operations based on relpath of files in current
87
 
            # directory, or nearby
88
 
            os.chdir(dtmp)
89
 
 
90
 
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
91
 
 
92
 
            self.assertEqual(rp('foo'), 'foo')
93
 
 
94
 
            self.assertEqual(rp('./foo'), 'foo')
95
 
 
96
 
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
97
 
 
98
 
            self.assertRaises(NotBranchError,
99
 
                              rp, '../foo')
100
 
 
101
 
        finally:
102
 
            os.chdir(savedir)
103
 
            shutil.rmtree(dtmp)