~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python

import bzrlib.selftest

class ShelfTests(bzrlib.selftest.TestCaseInTempDir):
    ORIGINAL = '\n\nhello test world\n\n'
    MODIFIED = '\n\ngoodbye test world\n\n'
    DIFF_HEADER = "=== modified file 'test_file'\n"
    DIFF = """--- test_file
+++ test_file
@@ -1,4 +1,4 @@
 
 
-hello test world
+goodbye test world
 
"""
    def test_shelf(self):
        from bzrlib.branch import Branch
        b = Branch.initialize('.')

        # Create a test file and commit it
        file('test_file', 'w').write(self.ORIGINAL)
        b.add('test_file')
        b.commit(message='add test_file')

        # Modify the test file
        file('test_file', 'w').write(self.MODIFIED)

        # Check the diff is right
        self.assertEqual(self.capture('diff'),
            self.DIFF_HEADER + self.DIFF + '\n')

        # Shelve the changes
        self.run_bzr('shelve', '--all', retcode=True)

        # Make sure there is no diff anymore
        self.assertEqual(self.capture('diff'), '')

        # Make sure the file is actually back the way it was
        self.assertEqual(file('test_file').read(), self.ORIGINAL)

        # Check the shelf is right
        shelf = file('.bzr-shelf').read()
        self.assertEqual(shelf, self.DIFF)

        # Unshelve
        self.run_bzr('unshelve', retcode=True)

        # Check the diff is right again
        self.assertEqual(self.capture('diff'),
            self.DIFF_HEADER + self.DIFF + '\n')

        # Make sure the file is back the way it should be
        self.assertEqual(file('test_file').read(), self.MODIFIED)

    def test_shelf_nothing_to_shelve(self):
        import os.path
        from bzrlib.branch import Branch
        b = Branch.initialize('.')

        # Create a test file and commit it
        file('test_file', 'w').write(self.ORIGINAL)
        b.add('test_file')
        b.commit(message='add test_file')

        # Shelve the changes
        self.run_bzr('shelve', '--all', retcode=True)

        if os.path.exists('.bzr-shelf'):
            self.fail("Shelf exists, but it shouldn't")