0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
1 |
#!/usr/bin/python
|
2 |
||
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
3 |
import bzrlib.tests |
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
4 |
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
5 |
class ShelfTests(bzrlib.tests.TestCaseInTempDir): |
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
6 |
ORIGINAL = '\n\nhello test world\n\n' |
7 |
MODIFIED = '\n\ngoodbye test world\n\n' |
|
8 |
DIFF_HEADER = "=== modified file 'test_file'\n" |
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
9 |
DIFF_1 = """--- test_file\t |
10 |
+++ test_file\t |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
11 |
@@ -1,4 +1,4 @@
|
12 |
|
|
13 |
|
|
14 |
-hello test world
|
|
15 |
+goodbye test world
|
|
16 |
|
|
17 |
"""
|
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
18 |
DIFF_2 = """--- test_file\t |
19 |
+++ test_file\t |
|
0.1.40
by Michael Ellerman
Update test with revision to actually test the shelf worked properly. |
20 |
@@ -1,4 +1,4 @@
|
21 |
|
|
22 |
|
|
23 |
-goodbye test world
|
|
24 |
+hello test world
|
|
25 |
|
|
26 |
"""
|
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
27 |
def test_shelf(self): |
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
28 |
self.__test_loop(1) |
29 |
||
30 |
def test_shelf_multi(self): |
|
31 |
self.__test_loop(10) |
|
32 |
||
33 |
def __test_loop(self, count): |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
34 |
from bzrlib.branch import Branch |
35 |
b = Branch.initialize('.') |
|
36 |
||
37 |
# Create a test file and commit it
|
|
38 |
file('test_file', 'w').write(self.ORIGINAL) |
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
39 |
b.working_tree().add('test_file') |
40 |
b.working_tree().commit(message='add test_file') |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
41 |
|
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
42 |
while count > 0: |
43 |
count -= 1 |
|
44 |
||
45 |
# Modify the test file
|
|
46 |
file('test_file', 'w').write(self.MODIFIED) |
|
47 |
||
48 |
# Check the diff is right
|
|
49 |
self.assertEqual(self.capture('diff', retcode=1), |
|
50 |
self.DIFF_HEADER + self.DIFF_1 + '\n') |
|
51 |
||
52 |
# Shelve the changes
|
|
53 |
self.run_bzr('shelve', '--all', retcode=True) |
|
54 |
||
55 |
# Make sure there is no diff anymore
|
|
56 |
self.assertEqual(self.capture('diff', retcode=0), '') |
|
57 |
||
58 |
# Make sure the file is actually back the way it was
|
|
59 |
self.assertEqual(file('test_file').read(), self.ORIGINAL) |
|
60 |
||
61 |
# Check the shelf is right
|
|
62 |
shelf = b._transport.get('.bzr/x-shelf/default/00').read() |
|
63 |
self.assertEqual(shelf, self.DIFF_1) |
|
64 |
||
65 |
# Unshelve
|
|
66 |
self.run_bzr('unshelve', retcode=True) |
|
67 |
||
68 |
# Check the diff is right again
|
|
69 |
self.assertEqual(self.capture('diff', retcode=1), |
|
70 |
self.DIFF_HEADER + self.DIFF_1 + '\n') |
|
71 |
||
72 |
# Make sure the file is back the way it should be
|
|
73 |
self.assertEqual(file('test_file').read(), self.MODIFIED) |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
74 |
|
75 |
def test_shelf_nothing_to_shelve(self): |
|
76 |
import os.path |
|
77 |
from bzrlib.branch import Branch |
|
78 |
b = Branch.initialize('.') |
|
79 |
||
80 |
# Create a test file and commit it
|
|
81 |
file('test_file', 'w').write(self.ORIGINAL) |
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
82 |
b.working_tree().add('test_file') |
83 |
b.working_tree().commit(message='add test_file') |
|
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
84 |
|
85 |
# Shelve the changes
|
|
86 |
self.run_bzr('shelve', '--all', retcode=True) |
|
87 |
||
0.1.42
by Michael Ellerman
Add tests for new shelf layout. |
88 |
if b._transport.has('.bzr/x-shelf/default/00'): |
0.1.29
by Michael Ellerman
Add basic tests for shelve --all, and unshelve. |
89 |
self.fail("Shelf exists, but it shouldn't") |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
90 |
|
91 |
def test_shelf_with_revision(self): |
|
92 |
from bzrlib.branch import Branch |
|
93 |
b = Branch.initialize('.') |
|
94 |
||
95 |
# Create a test file and commit it
|
|
96 |
file('test_file', 'w').write(self.ORIGINAL) |
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
97 |
b.working_tree().add('test_file') |
98 |
b.working_tree().commit(message='add test_file') |
|
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
99 |
|
100 |
# Modify the test file and commit it
|
|
101 |
file('test_file', 'w').write(self.MODIFIED) |
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
102 |
b.working_tree().commit(message='update test_file') |
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
103 |
|
104 |
# Shelve the changes
|
|
105 |
self.run_bzr('shelve', '-r', '1', '--all', retcode=True) |
|
106 |
||
0.1.40
by Michael Ellerman
Update test with revision to actually test the shelf worked properly. |
107 |
# Check the diff is right
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
108 |
self.assertEqual(self.capture('diff', retcode=1), |
0.1.40
by Michael Ellerman
Update test with revision to actually test the shelf worked properly. |
109 |
self.DIFF_HEADER + self.DIFF_2 + '\n') |
110 |
||
111 |
# Make sure the file is the way it should be
|
|
112 |
self.assertEqual(file('test_file').read(), self.ORIGINAL) |
|
113 |
||
114 |
# Unshelve
|
|
115 |
self.run_bzr('unshelve', retcode=True) |
|
116 |
||
117 |
# Make sure the file is back the way it should be
|
|
118 |
self.assertEqual(file('test_file').read(), self.MODIFIED) |
|
119 |
||
0.1.37
by Michael Ellerman
Add (failing) tests of revision argument for shelve. |
120 |
def test_shelf_with_two_revisions(self): |
121 |
from bzrlib.branch import Branch |
|
122 |
b = Branch.initialize('.') |
|
123 |
||
124 |
cmd = 'shelve -r 1..2' |
|
125 |
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None) |
|
126 |
||
127 |
self.assertEqual(stderr.split('\n')[0], |
|
0.1.41
by Michael Ellerman
Update tests for changes in bzr: |
128 |
'bzr: ERROR: bzrlib.errors.BzrCommandError: shelve only ' \
|
129 |
'accepts a single revision parameter.') |