~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests.py

  • Committer: Michael Ellerman
  • Date: 2005-10-25 14:00:28 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-20051025140028-78a0a8a4cf86cf97
Remove x bit from diffstat.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
import os
4
 
 
5
 
import bzrlib.tests
6
 
 
7
 
 
8
 
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
 
3
import bzrlib.selftest
 
4
 
 
5
class ShelfTests(bzrlib.selftest.TestCaseInTempDir):
9
6
    ORIGINAL = '\n\nhello test world\n\n'
10
7
    MODIFIED = '\n\ngoodbye test world\n\n'
11
8
    DIFF_HEADER = "=== modified file 'test_file'\n"
12
 
    DIFF_1 = """--- test_file\t
13
 
+++ test_file\t
 
9
    DIFF = """--- test_file
 
10
+++ test_file
14
11
@@ -1,4 +1,4 @@
15
12
 
16
13
 
18
15
+goodbye test world
19
16
 
20
17
"""
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
18
    def test_shelf(self):
31
19
        from bzrlib.branch import Branch
32
 
        from bzrlib.workingtree import WorkingTree
33
20
        b = Branch.initialize('.')
34
 
        tree = WorkingTree(b.base, b)
35
21
 
36
22
        # Create a test file and commit it
37
23
        file('test_file', 'w').write(self.ORIGINAL)
38
 
        tree.add('test_file')
39
 
        tree.commit(message='add test_file')
 
24
        b.add('test_file')
 
25
        b.commit(message='add test_file')
40
26
 
41
27
        # Modify the test file
42
28
        file('test_file', 'w').write(self.MODIFIED)
43
29
 
44
30
        # Check the diff is right
45
 
        self.assertEqual(self.capture('diff', retcode=1),
46
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
 
31
        self.assertEqual(self.capture('diff'),
 
32
            self.DIFF_HEADER + self.DIFF + '\n')
47
33
 
48
34
        # Shelve the changes
49
 
        self.run_bzr('shelve', '--all', retcode=1)
 
35
        self.run_bzr('shelve', '--all', retcode=True)
50
36
 
51
37
        # Make sure there is no diff anymore
52
38
        self.assertEqual(self.capture('diff'), '')
56
42
 
57
43
        # Check the shelf is right
58
44
        shelf = file('.bzr-shelf').read()
59
 
        self.assertEqual(shelf, self.DIFF_1)
 
45
        self.assertEqual(shelf, self.DIFF)
60
46
 
61
47
        # Unshelve
62
 
        self.run_bzr('unshelve', retcode=1)
 
48
        self.run_bzr('unshelve', retcode=True)
63
49
 
64
50
        # Check the diff is right again
65
 
        self.assertEqual(self.capture('diff', retcode=1),
66
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
 
51
        self.assertEqual(self.capture('diff'),
 
52
            self.DIFF_HEADER + self.DIFF + '\n')
67
53
 
68
54
        # Make sure the file is back the way it should be
69
55
        self.assertEqual(file('test_file').read(), self.MODIFIED)
70
56
 
71
57
    def test_shelf_nothing_to_shelve(self):
 
58
        import os.path
72
59
        from bzrlib.branch import Branch
73
 
        from bzrlib.workingtree import WorkingTree
74
60
        b = Branch.initialize('.')
75
 
        tree = WorkingTree(b.base, b)
76
61
 
77
62
        # Create a test file and commit it
78
63
        file('test_file', 'w').write(self.ORIGINAL)
79
 
        tree.add('test_file')
80
 
        tree.commit(message='add test_file')
 
64
        b.add('test_file')
 
65
        b.commit(message='add test_file')
81
66
 
82
67
        # Shelve the changes
83
 
        self.run_bzr('shelve', '--all')
 
68
        self.run_bzr('shelve', '--all', retcode=True)
84
69
 
85
70
        if os.path.exists('.bzr-shelf'):
86
71
            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('..')