~abentley/bzrtools/bzrtools.dev

291 by Aaron Bentley
Adjusted to selftest -> tests change
1
from bzrlib.tests.blackbox import ExternalBase
241 by Aaron Bentley
Added blackbox tests for bzrtools
2
from unittest import makeSuite
3
import os.path
4
class TestBzrTools(ExternalBase):
5
    @staticmethod
6
    def touch(filename):
7
        file(filename, 'wb').write('')
8
9
    def test_clean_tree(self):
10
        self.runbzr('init')
11
        self.touch('name')
12
        self.touch('name~')
13
        assert os.path.lexists('name~')
14
        self.touch('name.pyc')
15
        self.runbzr('clean-tree')
16
        assert os.path.lexists('name~')
17
        assert not os.path.lexists('name')
265 by Aaron Bentley
Fixed spelling of detritus
18
        self.runbzr('clean-tree --detritus')
241 by Aaron Bentley
Added blackbox tests for bzrtools
19
        assert not os.path.lexists('name~')
20
        assert os.path.lexists('name.pyc')
21
        self.runbzr('clean-tree --ignored')
22
        assert not os.path.lexists('name.pyc')
23
24
    def test_shelve(self):
25
        self.runbzr('init')
26
        self.runbzr('commit -m uc --unchanged')
338 by Aaron Bentley
Fixed shelf test case
27
        self.runbzr('shelve -r 1 -m foo --all', retcode=3)
28
        file('foo', 'wb').write('foo')
325.1.2 by Aaron Bentley
Merge shelf v2
29
        self.runbzr('add foo')
30
        self.runbzr('commit -m foo')
338 by Aaron Bentley
Fixed shelf test case
31
        self.runbzr('shelve -r 1 -m foo --all', retcode=0)
241 by Aaron Bentley
Added blackbox tests for bzrtools
32
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
33
    def test_fetch_ghosts(self):
34
        self.runbzr('init')
286.1.1 by Aaron Bentley
Updates to match API changes
35
        self.runbzr('fetch-ghosts .')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
36
37
    def test_patch(self):
38
        self.runbzr('init')
39
        file('myfile', 'wb').write('hello')
40
        self.runbzr('add')
41
        self.runbzr('commit -m hello')
42
        file('myfile', 'wb').write('goodbye')
271 by Aaron Bentley
Cherry-picked Robert's diff and push fixes
43
        file('mypatch', 'wb').write(self.runbzr('diff', retcode=1, backtick=1))
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
44
        self.runbzr('revert')
45
        assert file('myfile', 'rb').read() == 'hello'
46
        self.runbzr('patch mypatch')
47
        assert file('myfile', 'rb').read() == 'goodbye'
48
308 by Aaron Bentley
got branch-history under test
49
    def test_branch_history(self):
50
        self.runbzr('init')
51
        file('myfile', 'wb').write('hello')
52
        self.runbzr('add')
53
        self.runbzr('commit -m hello')
54
        self.runbzr('branch-history')
55
309 by Aaron Bentley
Fixed graph-ancestry
56
    def test_branch_history(self):
57
        self.runbzr('init')
58
        file('myfile', 'wb').write('hello')
59
        self.runbzr('add')
60
        self.runbzr('commit -m hello')
61
        self.runbzr('graph-ancestry . graph.dot')
62
        self.runbzr('branch . my_branch')
63
        self.runbzr('graph-ancestry . graph.dot --merge-branch my_branch')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
64
310 by Aaron Bentley
Fixed fetch-ghosts
65
    def test_fetch_ghosts(self):
66
        self.runbzr('init')
67
        file('myfile', 'wb').write('hello')
68
        self.runbzr('add')
69
        self.runbzr('commit -m hello')
70
        self.runbzr('branch . my_branch')
71
        self.runbzr('fetch-ghosts my_branch')
72
345 by Aaron Bentley
Added zap command
73
    def test_zap(self):
74
        self.runbzr('init source')
75
        self.runbzr('checkout --lightweight source checkout')
76
        self.runbzr('zap checkout')
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
77
        self.assertIs(False, os.path.exists('checkout'))
78
        self.assertIs(True, os.path.exists('source'))
79
80
    def test_zap_branch(self):
81
        self.runbzr('init source')
82
        self.runbzr('checkout --lightweight source checkout')
83
        self.runbzr('zap --branch checkout')
84
        self.assertIs(False, os.path.exists('checkout'))
85
        self.assertIs(False, os.path.exists('source'))
345 by Aaron Bentley
Added zap command
86
352 by Aaron Bentley
Added branches subcommand
87
    def test_branches(self):
88
        self.runbzr('init source')
89
        self.runbzr('init source/subsource')
90
        self.runbzr('checkout --lightweight source checkout')
91
        self.runbzr('init checkout/subcheckout')
92
        self.runbzr('init checkout/.bzr/subcheckout')
93
        out = self.capture('branches')
94
        lines = out.split('\n')
95
        self.assertIs(True, 'source' in lines)
96
        self.assertIs(True, 'source/subsource' in lines)
97
        self.assertIs(True, 'checkout/subcheckout' in lines)
98
        self.assertIs(True, 'checkout' not in lines)
99
        self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
345 by Aaron Bentley
Added zap command
100
377 by Aaron Bentley
Got import command working
101
    def test_import_upstream(self):
102
        self.runbzr('init source')
103
        os.mkdir('source/src')
104
        f = file('source/src/myfile', 'wb')
105
        f.write('hello?')
106
        f.close()
107
        os.chdir('source')
108
        self.runbzr('add')
109
        self.runbzr('commit -m hello')
110
        self.runbzr('export ../source-0.1.tar.gz')
384 by Aaron Bentley
Implement bzip support
111
        self.runbzr('export ../source-0.1.tar.bz2')
380 by Aaron Bentley
Got import working decently
112
        self.runbzr('init ../import')
377 by Aaron Bentley
Got import command working
113
        os.chdir('../import')
114
        self.runbzr('import ../source-0.1.tar.gz')
380 by Aaron Bentley
Got import working decently
115
        self.failUnlessExists('src/myfile')
378 by Aaron Bentley
Check for modified files
116
        result = self.runbzr('import ../source-0.1.tar.gz', retcode=3)[1]
117
        self.assertContainsRe(result, 'Working tree has uncommitted changes')
380 by Aaron Bentley
Got import working decently
118
        self.runbzr('commit -m commit')
119
        self.runbzr('import ../source-0.1.tar.gz')
120
        os.chdir('..')
121
        self.runbzr('init import2')
122
        self.runbzr('import source-0.1.tar.gz import2')
123
        self.failUnlessExists('import2/src/myfile')
124
        self.runbzr('import source-0.1.tar.gz import3')
125
        self.failUnlessExists('import3/src/myfile')
384 by Aaron Bentley
Implement bzip support
126
        self.runbzr('import source-0.1.tar.bz2 import4')
127
        self.failUnlessExists('import4/src/myfile')
377 by Aaron Bentley
Got import command working
128
392.1.3 by Aaron Bentley
Add tests for shove
129
    def test_shove(self):
130
        self.runbzr('init source')
131
        f = file('source/file', 'wb')
132
        f.write('hello\n')
133
        f.close()
134
        self.runbzr('add source/file')
135
        self.runbzr('commit source -m foo')
136
        self.runbzr('branch source target1')
137
        self.runbzr('branch source target2')
138
        f = file('source/file', 'wb')
139
        f.write('goodbye\n')
140
        f.close()
141
        self.runbzr('shove target1 source')
142
        f = file('target1/file', 'rb')
143
        self.assertEqual(f.read(), 'goodbye\n')
144
        f.close()
145
        os.chdir('source')
146
        self.runbzr('shove target2', retcode=3)
147
        self.runbzr('shove ../target2')
148
        f = file('../target2/file', 'rb')
149
        self.assertEqual(f.read(), 'goodbye\n')
150
        f.close()
377 by Aaron Bentley
Got import command working
151
241 by Aaron Bentley
Added blackbox tests for bzrtools
152
def test_suite():
153
    return makeSuite(TestBzrTools)