/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/selftest/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-06-28 03:02:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050628030231-d311e4ebcd467ef4
Merge John's import-speedup branch:

                                                                                         
  777 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:32 -0500
      revision-id: john@arbash-meinel.com-20050627032031-e82a50db3863b18e
      bzr selftest was not using the correct bzr

  776 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:22 -0500
      revision-id: john@arbash-meinel.com-20050627032021-c9f21fde989ddaee
      Add was using an old mutter

  775 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:02:33 -0500
      revision-id: john@arbash-meinel.com-20050627030233-9165cfe98fc63298
      Cleaned up to be less different

  774 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:54:53 -0500
      revision-id: john@arbash-meinel.com-20050627025452-4260d0e744edef43
      Allow BZR_PLUGIN_PATH='' to negate plugin loading.

  773 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:49:34 -0500
      revision-id: john@arbash-meinel.com-20050627024933-b7158f67b7b9eae5
      Finished the previous cleanup (allowing load_plugins to be called twice)

  772 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:45:08 -0500
      revision-id: john@arbash-meinel.com-20050627024508-723b1df510d196fc
      Work on making the tests pass. versioning.py is calling run_cmd directly, but plugins have been loaded.

  771 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:32:29 -0500
      revision-id: john@arbash-meinel.com-20050627023228-79972744d7c53e15
      Got it down a little bit more by removing import of tree and inventory.

  770 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:26:05 -0500
      revision-id: john@arbash-meinel.com-20050627022604-350b9773ef622f95
      Reducing the number of import from bzrlib/__init__.py and bzrlib/branch.py

  769 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:32:25 -0500
      revision-id: john@arbash-meinel.com-20050627013225-32dd044f10d23948
      Updated revision.py and xml.py to include SubElement.

  768 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:56 -0500
      revision-id: john@arbash-meinel.com-20050627010356-ee66919e1c377faf
      Minor typo

  767 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:13 -0500
      revision-id: john@arbash-meinel.com-20050627010312-40d024007eb85051
      Caching the import

  766 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:51:47 -0500
      revision-id: john@arbash-meinel.com-20050627005147-5281c99e48ed1834
      Created wrapper functions for lazy import of ElementTree

  765 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:46:37 -0500
      revision-id: john@arbash-meinel.com-20050627004636-bf432902004a94c5
      Removed all of the test imports of cElementTree

  764 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:43:59 -0500
      revision-id: john@arbash-meinel.com-20050627004358-d137fbe9570dd71b
      Trying to make bzr startup faster.

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, 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):
 
87
    """test for branch path lookups
 
88
 
 
89
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
 
90
    job: given a path (either relative to cwd or absolute), work out
 
91
    if it is inside a branch and return the path relative to the base.
 
92
    """
 
93
 
 
94
    def runTest(self):
 
95
        from bzrlib.branch import _relpath
 
96
        import tempfile, shutil
 
97
        
 
98
        savedir = os.getcwdu()
 
99
        dtmp = tempfile.mkdtemp()
 
100
 
 
101
        def rp(p):
 
102
            return _relpath(dtmp, p)
 
103
        
 
104
        try:
 
105
            # check paths inside dtmp while standing outside it
 
106
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
 
107
 
 
108
            # root = nothing
 
109
            self.assertEqual(rp(dtmp), '')
 
110
 
 
111
            self.assertRaises(NotBranchError,
 
112
                              rp,
 
113
                              '/etc')
 
114
 
 
115
            # now some near-miss operations -- note that
 
116
            # os.path.commonprefix gets these wrong!
 
117
            self.assertRaises(NotBranchError,
 
118
                              rp,
 
119
                              dtmp.rstrip('\\/') + '2')
 
120
 
 
121
            self.assertRaises(NotBranchError,
 
122
                              rp,
 
123
                              dtmp.rstrip('\\/') + '2/foo')
 
124
 
 
125
            # now operations based on relpath of files in current
 
126
            # directory, or nearby
 
127
            os.chdir(dtmp)
 
128
 
 
129
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
 
130
 
 
131
            self.assertEqual(rp('foo'), 'foo')
 
132
 
 
133
            self.assertEqual(rp('./foo'), 'foo')
 
134
 
 
135
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
 
136
 
 
137
            self.assertRaises(NotBranchError,
 
138
                              rp, '../foo')
 
139
 
 
140
        finally:
 
141
            os.chdir(savedir)
 
142
            shutil.rmtree(dtmp)