~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

  • Committer: Aaron Bentley
  • Date: 2006-04-07 22:46:52 UTC
  • mfrom: (1645 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: aaron.bentley@utoronto.ca-20060407224652-4925bc3735b926f8
Merged latest bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
import unittest
3
3
 
4
 
from bzrlib.tests import TestCaseInTempDir, TestCase
 
4
from bzrlib.tests import TestCaseWithTransport, TestCase
5
5
from bzrlib.branch import ScratchBranch, Branch
6
6
from bzrlib.errors import PathNotChild
7
 
 
8
 
 
9
 
class TestBranch(TestCaseInTempDir):
10
 
 
11
 
    def test_no_changes(self):
12
 
        from bzrlib.errors import PointlessCommit
13
 
        
14
 
        b = Branch.initialize(u'.')
15
 
 
16
 
        self.build_tree(['hello.txt'])
17
 
 
18
 
        self.assertRaises(PointlessCommit,
19
 
                          b.working_tree().commit,
20
 
                          'commit without adding',
21
 
                          allow_pointless=False)
22
 
 
23
 
        b.working_tree().commit('commit pointless tree',
24
 
                 allow_pointless=True)
25
 
 
26
 
        b.working_tree().add('hello.txt')
27
 
        
28
 
        b.working_tree().commit('commit first added file',
29
 
                 allow_pointless=False)
30
 
        
31
 
        self.assertRaises(PointlessCommit,
32
 
                          b.working_tree().commit,
33
 
                          'commit after adding file',
34
 
                          allow_pointless=False)
35
 
        
36
 
        b.working_tree().commit('commit pointless revision with one file',
37
 
                 allow_pointless=True)
38
 
 
39
 
 
40
 
class MoreTests(TestCaseInTempDir):
41
 
 
42
 
    def test_rename_dirs(self):
43
 
        """Test renaming directories and the files within them."""
44
 
        b = Branch.initialize(u'.')
45
 
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
46
 
        b.working_tree().add(['dir', 'dir/sub', 'dir/sub/file'])
47
 
 
48
 
        b.working_tree().commit('create initial state')
49
 
 
50
 
        # TODO: lift out to a test helper that checks the shape of
51
 
        # an inventory
52
 
        
53
 
        revid = b.revision_history()[0]
54
 
        self.log('first revision_id is {%s}' % revid)
55
 
        
56
 
        inv = b.get_revision_inventory(revid)
57
 
        self.log('contents of inventory: %r' % inv.entries())
58
 
 
59
 
        self.check_inventory_shape(inv,
60
 
                                   ['dir', 'dir/sub', 'dir/sub/file'])
61
 
 
62
 
        b.working_tree().rename_one('dir', 'newdir')
63
 
 
64
 
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
65
 
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
66
 
 
67
 
        b.working_tree().rename_one('newdir/sub', 'newdir/newsub')
68
 
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
69
 
                                   ['newdir', 'newdir/newsub',
70
 
                                    'newdir/newsub/file'])
 
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
 
8
 
 
9
 
 
10
class MoreTests(TestCaseWithTransport):
71
11
 
72
12
    def test_relpath(self):
73
13
        """test for branch path lookups
76
16
        job: given a path (either relative to cwd or absolute), work out
77
17
        if it is inside a branch and return the path relative to the base.
78
18
        """
79
 
        from bzrlib.osutils import relpath
80
19
        import tempfile, shutil
81
20
        
82
21
        savedir = os.getcwdu()
83
22
        dtmp = tempfile.mkdtemp()
84
23
        # On Mac OSX, /tmp actually expands to /private/tmp
85
 
        dtmp = os.path.realpath(dtmp)
 
24
        dtmp = realpath(dtmp)
86
25
 
87
26
        def rp(p):
88
27
            return relpath(dtmp, p)
89
28
        
90
29
        try:
91
30
            # check paths inside dtmp while standing outside it
92
 
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
 
31
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
93
32
 
94
33
            # root = nothing
95
34
            self.assertEqual(rp(dtmp), '')
112
51
            # directory, or nearby
113
52
            os.chdir(dtmp)
114
53
 
115
 
            FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
116
 
            self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
 
54
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
117
55
 
118
56
            self.assertEqual(rp('foo'), 'foo')
119
57
 
120
58
            self.assertEqual(rp('./foo'), 'foo')
121
59
 
122
 
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
 
60
            self.assertEqual(rp(abspath('foo')), 'foo')
123
61
 
124
62
            self.assertRaises(PathNotChild,
125
63
                              rp, '../foo')