5
class ShelfTests(bzrlib.selftest.TestCaseInTempDir):
6
ORIGINAL = '\n\nhello test world\n\n'
7
MODIFIED = '\n\ngoodbye test world\n\n'
8
DIFF_HEADER = "=== modified file 'test_file'\n"
9
DIFF = """--- test_file
19
from bzrlib.branch import Branch
20
b = Branch.initialize('.')
22
# Create a test file and commit it
23
file('test_file', 'w').write(self.ORIGINAL)
25
b.commit(message='add test_file')
27
# Modify the test file
28
file('test_file', 'w').write(self.MODIFIED)
30
# Check the diff is right
31
self.assertEqual(self.capture('diff'),
32
self.DIFF_HEADER + self.DIFF + '\n')
35
self.run_bzr('shelve', '--all', retcode=True)
37
# Make sure there is no diff anymore
38
self.assertEqual(self.capture('diff'), '')
40
# Make sure the file is actually back the way it was
41
self.assertEqual(file('test_file').read(), self.ORIGINAL)
43
# Check the shelf is right
44
shelf = file('.bzr-shelf').read()
45
self.assertEqual(shelf, self.DIFF)
48
self.run_bzr('unshelve', retcode=True)
50
# Check the diff is right again
51
self.assertEqual(self.capture('diff'),
52
self.DIFF_HEADER + self.DIFF + '\n')
54
# Make sure the file is back the way it should be
55
self.assertEqual(file('test_file').read(), self.MODIFIED)
57
def test_shelf_nothing_to_shelve(self):
59
from bzrlib.branch import Branch
60
b = Branch.initialize('.')
62
# Create a test file and commit it
63
file('test_file', 'w').write(self.ORIGINAL)
65
b.commit(message='add test_file')
68
self.run_bzr('shelve', '--all', retcode=True)
70
if os.path.exists('.bzr-shelf'):
71
self.fail("Shelf exists, but it shouldn't")