~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf_tests.py

  • Committer: Michael Ellerman
  • Date: 2005-10-19 09:34:33 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 246.
  • Revision ID: michael@ellerman.id.au-20051019093433-39720aedce6799e9
Upated patches.py to version from bzrtools-0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
import os
4
 
 
5
 
import bzrlib.tests
6
 
 
7
 
 
8
 
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
9
 
    ORIGINAL = '\n\nhello test world\n\n'
10
 
    MODIFIED = '\n\ngoodbye test world\n\n'
11
 
    DIFF_HEADER = "=== modified file 'test_file'\n"
12
 
    DIFF_1 = """--- test_file\t
13
 
+++ test_file\t
14
 
@@ -1,4 +1,4 @@
15
 
 
16
 
 
17
 
-hello test world
18
 
+goodbye test world
19
 
 
20
 
"""
21
 
    DIFF_2 = """--- test_file\t
22
 
+++ test_file\t
23
 
@@ -1,4 +1,4 @@
24
 
 
25
 
 
26
 
-goodbye test world
27
 
+hello test world
28
 
 
29
 
"""
30
 
    def test_shelf(self):
31
 
        from bzrlib.branch import Branch
32
 
        from bzrlib.workingtree import WorkingTree
33
 
        b = Branch.initialize('.')
34
 
        tree = WorkingTree(b.base, b)
35
 
 
36
 
        # Create a test file and commit it
37
 
        file('test_file', 'w').write(self.ORIGINAL)
38
 
        tree.add('test_file')
39
 
        tree.commit(message='add test_file')
40
 
 
41
 
        # Modify the test file
42
 
        file('test_file', 'w').write(self.MODIFIED)
43
 
 
44
 
        # Check the diff is right
45
 
        self.assertEqual(self.capture('diff', retcode=1),
46
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
47
 
 
48
 
        # Shelve the changes
49
 
        self.run_bzr('shelve', '--all', retcode=1)
50
 
 
51
 
        # Make sure there is no diff anymore
52
 
        self.assertEqual(self.capture('diff'), '')
53
 
 
54
 
        # Make sure the file is actually back the way it was
55
 
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
56
 
 
57
 
        # Check the shelf is right
58
 
        shelf = file('.bzr-shelf').read()
59
 
        self.assertEqual(shelf, self.DIFF_1)
60
 
 
61
 
        # Unshelve
62
 
        self.run_bzr('unshelve', retcode=1)
63
 
 
64
 
        # Check the diff is right again
65
 
        self.assertEqual(self.capture('diff', retcode=1),
66
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
67
 
 
68
 
        # Make sure the file is back the way it should be
69
 
        self.assertEqual(file('test_file').read(), self.MODIFIED)
70
 
 
71
 
    def test_shelf_nothing_to_shelve(self):
72
 
        from bzrlib.branch import Branch
73
 
        from bzrlib.workingtree import WorkingTree
74
 
        b = Branch.initialize('.')
75
 
        tree = WorkingTree(b.base, b)
76
 
 
77
 
        # Create a test file and commit it
78
 
        file('test_file', 'w').write(self.ORIGINAL)
79
 
        tree.add('test_file')
80
 
        tree.commit(message='add test_file')
81
 
 
82
 
        # Shelve the changes
83
 
        self.run_bzr('shelve', '--all')
84
 
 
85
 
        if os.path.exists('.bzr-shelf'):
86
 
            self.fail("Shelf exists, but it shouldn't")
87
 
 
88
 
    def test_shelf_with_revision(self):
89
 
        from bzrlib.branch import Branch
90
 
        from bzrlib.workingtree import WorkingTree
91
 
        b = Branch.initialize('.')
92
 
        tree = WorkingTree(b.base, b)
93
 
 
94
 
        # Create a test file and commit it
95
 
        file('test_file', 'w').write(self.ORIGINAL)
96
 
        tree.add('test_file')
97
 
        tree.commit(message='add test_file')
98
 
 
99
 
        # Modify the test file and commit it
100
 
        file('test_file', 'w').write(self.MODIFIED)
101
 
        tree.commit(message='update test_file')
102
 
 
103
 
        # Shelve the changes
104
 
        self.run_bzr('shelve', '-r', '1', '--all', retcode=1)
105
 
 
106
 
        # Check the diff is right
107
 
        self.assertEqual(self.capture('diff', retcode=1),
108
 
            self.DIFF_HEADER + self.DIFF_2 + '\n')
109
 
 
110
 
        # Make sure the file is the way it should be
111
 
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
112
 
 
113
 
        # Unshelve
114
 
        self.run_bzr('unshelve', retcode=1)
115
 
 
116
 
        # Make sure the file is back the way it should be
117
 
        self.assertEqual(file('test_file').read(), self.MODIFIED)
118
 
 
119
 
    def test_shelf_with_two_revisions(self):
120
 
        from bzrlib.branch import Branch
121
 
        b = Branch.initialize('.')
122
 
 
123
 
        cmd = 'shelve -r 1..2'
124
 
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
125
 
 
126
 
        self.assertEqual(stderr.split('\n')[0],
127
 
            'bzr: ERROR: bzrlib.errors.BzrCommandError: shelve only accepts a single revision parameter.')
128
 
 
129
 
    def test_shelf_with_whitespace(self):
130
 
        """Shows that bzr doesn't handle whitespace well"""
131
 
        self.run_bzr('init')
132
 
        file('file name', 'wb').write('hello')
133
 
        self.run_bzr('add')
134
 
        self.run_bzr('commit', '-m', 'added')
135
 
        file('file name', 'wb').write('goodbye')
136
 
        self.run_bzr('shelve', '--all', 'file name', retcode=1)
137
 
 
138
 
    def test_whitespace_branches(self):
139
 
        os.mkdir('name with space')
140
 
        os.chdir('name with space')
141
 
        self.run_bzr('init')
142
 
        file('filename', 'wb').write('hello')
143
 
        self.run_bzr('add')
144
 
        self.run_bzr('commit', '-m', 'added')
145
 
        file('filename', 'wb').write('goodbye')
146
 
        self.run_bzr('shelve', '--all', 'filename', retcode=1)
147
 
        os.chdir('..')