~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-07-04 07:33:32 UTC
  • Revision ID: mbp@sourcefrog.net-20050704073332-48c024b7b80671b6
- New validate_revision_id function

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/python
2
2
 
3
 
from bzrlib.branch import ScratchBranch
4
 
from bzrlib.errors import NotBranchError
5
 
from unittest import TestCase
6
 
import os, unittest
7
 
 
8
 
class BranchPathTestCase(TestCase):
 
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, NotVersionedError
 
9
 
 
10
 
 
11
class Unknowns(InTempDir):
 
12
    def runTest(self):
 
13
        b = Branch('.', init=True)
 
14
 
 
15
        self.build_tree(['hello.txt',
 
16
                         'hello.txt~'])
 
17
 
 
18
        self.assertEquals(list(b.unknowns()),
 
19
                          ['hello.txt'])
 
20
 
 
21
 
 
22
class Revert(InTempDir):
 
23
    """Test selected-file revert"""
 
24
    def runTest(self):
 
25
        b = Branch('.', init=True)
 
26
 
 
27
        self.build_tree(['hello.txt'])
 
28
        file('hello.txt', 'w').write('initial hello')
 
29
 
 
30
        self.assertRaises(NotVersionedError,
 
31
                          b.revert, ['hello.txt'])
 
32
        
 
33
        b.add(['hello.txt'])
 
34
        b.commit('create initial hello.txt')
 
35
 
 
36
        self.check_file_contents('hello.txt', 'initial hello')
 
37
        file('hello.txt', 'w').write('new hello')
 
38
        self.check_file_contents('hello.txt', 'new hello')
 
39
 
 
40
        # revert file modified since last revision
 
41
        b.revert(['hello.txt'])
 
42
        self.check_file_contents('hello.txt', 'initial hello')
 
43
        self.check_file_contents('hello.txt~', 'new hello')
 
44
 
 
45
        # reverting again clobbers the backup
 
46
        b.revert(['hello.txt'])
 
47
        self.check_file_contents('hello.txt', 'initial hello')
 
48
        self.check_file_contents('hello.txt~', 'initial hello')
 
49
 
 
50
 
 
51
 
 
52
class RenameDirs(InTempDir):
 
53
    """Test renaming directories and the files within them."""
 
54
    def runTest(self):
 
55
        b = Branch('.', init=True)
 
56
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
 
57
        b.add(['dir', 'dir/sub', 'dir/sub/file'])
 
58
 
 
59
        b.commit('create initial state')
 
60
 
 
61
        # TODO: lift out to a test helper that checks the shape of
 
62
        # an inventory
 
63
        
 
64
        revid = b.revision_history()[0]
 
65
        self.log('first revision_id is {%s}' % revid)
 
66
        
 
67
        inv = b.get_revision_inventory(revid)
 
68
        self.log('contents of inventory: %r' % inv.entries())
 
69
 
 
70
        self.check_inventory_shape(inv,
 
71
                                   ['dir', 'dir/sub', 'dir/sub/file'])
 
72
 
 
73
        b.rename_one('dir', 'newdir')
 
74
 
 
75
        self.check_inventory_shape(b.inventory,
 
76
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
 
77
 
 
78
        b.rename_one('newdir/sub', 'newdir/newsub')
 
79
        self.check_inventory_shape(b.inventory,
 
80
                                   ['newdir', 'newdir/newsub',
 
81
                                    'newdir/newsub/file'])
 
82
 
 
83
        
 
84
 
 
85
 
 
86
class BranchPathTestCase(TestBase):
9
87
    """test for branch path lookups
10
88
 
11
89
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
12
90
    job: given a path (either relative to cwd or absolute), work out
13
91
    if it is inside a branch and return the path relative to the base.
14
92
    """
15
 
    
 
93
 
16
94
    def runTest(self):
17
95
        from bzrlib.branch import _relpath
18
96
        import tempfile, shutil
62
140
        finally:
63
141
            os.chdir(savedir)
64
142
            shutil.rmtree(dtmp)
65
 
 
66
 
                              
67
 
if __name__ == '__main__':
68
 
    unittest.main()
69