~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 01:41:52 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129014152-f5ede8888bcebc48
HunkSelector was broken if you did a "done" followed by "status/invert" etc.
Fixup to make pychecker happy.

Show diffs side-by-side

added added

removed removed

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