~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-06-24 11:07:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050624110710-166c735534683ada
- start of simple test for unknown-file reporting

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
1
3
import os
2
4
import unittest
3
5
 
4
 
from bzrlib.selftest import TestCaseInTempDir, TestCase
 
6
from bzrlib.selftest import InTempDir, TestBase
5
7
from bzrlib.branch import ScratchBranch, Branch
6
8
from bzrlib.errors import NotBranchError, NotVersionedError
7
9
 
8
10
 
9
 
class TestBranch(TestCaseInTempDir):
10
 
 
11
 
    def test_unknowns(self):
12
 
        b = Branch.initialize('.')
 
11
class Unknowns(InTempDir):
 
12
    def runTest(self):
 
13
        b = Branch('.', init=True)
13
14
 
14
15
        self.build_tree(['hello.txt',
15
16
                         'hello.txt~'])
17
18
        self.assertEquals(list(b.unknowns()),
18
19
                          ['hello.txt'])
19
20
 
20
 
    def test_no_changes(self):
21
 
        from bzrlib.errors import PointlessCommit
22
 
        
23
 
        b = Branch.initialize('.')
24
 
 
25
 
        self.build_tree(['hello.txt'])
26
 
 
27
 
        self.assertRaises(PointlessCommit,
28
 
                          b.commit,
29
 
                          'commit without adding',
30
 
                          allow_pointless=False)
31
 
 
32
 
        b.commit('commit pointless tree',
33
 
                 allow_pointless=True)
34
 
 
35
 
        b.add('hello.txt')
36
 
        
37
 
        b.commit('commit first added file',
38
 
                 allow_pointless=False)
39
 
        
40
 
        self.assertRaises(PointlessCommit,
41
 
                          b.commit,
42
 
                          'commit after adding file',
43
 
                          allow_pointless=False)
44
 
        
45
 
        b.commit('commit pointless revision with one file',
46
 
                 allow_pointless=True)
47
 
 
48
 
 
49
 
class MoreTests(TestCaseInTempDir):
50
 
 
51
 
    def test_revert(self):
52
 
        """Test selected-file revert"""
53
 
        b = Branch.initialize('.')
 
21
 
 
22
class Revert(InTempDir):
 
23
    """Test selected-file revert"""
 
24
    def runTest(self):
 
25
        b = Branch('.', init=True)
54
26
 
55
27
        self.build_tree(['hello.txt'])
56
28
        file('hello.txt', 'w').write('initial hello')
68
40
        # revert file modified since last revision
69
41
        b.revert(['hello.txt'])
70
42
        self.check_file_contents('hello.txt', 'initial hello')
71
 
        self.check_file_contents('hello.txt~', 'new hello')
72
43
 
73
 
        # reverting again clobbers the backup
 
44
        # reverting again causes no change
74
45
        b.revert(['hello.txt'])
75
46
        self.check_file_contents('hello.txt', 'initial hello')
76
 
        self.check_file_contents('hello.txt~', 'initial hello')
77
 
 
78
 
    def test_rename_dirs(self):
79
 
        """Test renaming directories and the files within them."""
80
 
        b = Branch.initialize('.')
 
47
 
 
48
 
 
49
 
 
50
class RenameDirs(InTempDir):
 
51
    """Test renaming directories and the files within them."""
 
52
    def runTest(self):
 
53
        b = Branch('.', init=True)
81
54
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
82
55
        b.add(['dir', 'dir/sub', 'dir/sub/file'])
83
56
 
105
78
                                   ['newdir', 'newdir/newsub',
106
79
                                    'newdir/newsub/file'])
107
80
 
108
 
    def test_relpath(self):
109
 
        """test for branch path lookups
110
 
    
111
 
        bzrlib.osutils._relpath do a simple but subtle
112
 
        job: given a path (either relative to cwd or absolute), work out
113
 
        if it is inside a branch and return the path relative to the base.
114
 
        """
115
 
        from bzrlib.osutils import relpath
 
81
        
 
82
 
 
83
 
 
84
class BranchPathTestCase(TestBase):
 
85
    """test for branch path lookups
 
86
 
 
87
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
 
88
    job: given a path (either relative to cwd or absolute), work out
 
89
    if it is inside a branch and return the path relative to the base.
 
90
    """
 
91
 
 
92
    def runTest(self):
 
93
        from bzrlib.branch import _relpath
116
94
        import tempfile, shutil
117
95
        
118
96
        savedir = os.getcwdu()
119
97
        dtmp = tempfile.mkdtemp()
120
 
        # On Mac OSX, /tmp actually expands to /private/tmp
121
 
        dtmp = os.path.realpath(dtmp)
122
98
 
123
99
        def rp(p):
124
 
            return relpath(dtmp, p)
 
100
            return _relpath(dtmp, p)
125
101
        
126
102
        try:
127
103
            # check paths inside dtmp while standing outside it
148
124
            # directory, or nearby
149
125
            os.chdir(dtmp)
150
126
 
151
 
            FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
152
 
            self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
 
127
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
153
128
 
154
129
            self.assertEqual(rp('foo'), 'foo')
155
130