~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests.py

  • Committer: Michael Ellerman
  • Date: 2005-11-27 00:51:41 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-20051127005141-3f22bf8da12129a0
Update tests for changes in bzr:
 - add() and commit() now sit in working_tree, not branch.
 - diff returns 1 if there are changes in the tree.
 - diff filenames have \t appended to them for some reason.
 - Exceptions look a little different on stderr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
import bzrlib.selftest
 
3
import bzrlib.tests
4
4
 
5
 
class ShelfTests(bzrlib.selftest.TestCaseInTempDir):
 
5
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
6
6
    ORIGINAL = '\n\nhello test world\n\n'
7
7
    MODIFIED = '\n\ngoodbye test world\n\n'
8
8
    DIFF_HEADER = "=== modified file 'test_file'\n"
9
 
    DIFF_1 = """--- test_file
10
 
+++ test_file
 
9
    DIFF_1 = """--- test_file\t
 
10
+++ test_file\t
11
11
@@ -1,4 +1,4 @@
12
12
 
13
13
 
15
15
+goodbye test world
16
16
 
17
17
"""
18
 
    DIFF_2 = """--- test_file
19
 
+++ test_file
 
18
    DIFF_2 = """--- test_file\t
 
19
+++ test_file\t
20
20
@@ -1,4 +1,4 @@
21
21
 
22
22
 
30
30
 
31
31
        # Create a test file and commit it
32
32
        file('test_file', 'w').write(self.ORIGINAL)
33
 
        b.add('test_file')
34
 
        b.commit(message='add test_file')
 
33
        b.working_tree().add('test_file')
 
34
        b.working_tree().commit(message='add test_file')
35
35
 
36
36
        # Modify the test file
37
37
        file('test_file', 'w').write(self.MODIFIED)
38
38
 
39
39
        # Check the diff is right
40
 
        self.assertEqual(self.capture('diff'),
 
40
        self.assertEqual(self.capture('diff', retcode=1),
41
41
            self.DIFF_HEADER + self.DIFF_1 + '\n')
42
42
 
43
43
        # Shelve the changes
44
44
        self.run_bzr('shelve', '--all', retcode=True)
45
45
 
46
46
        # Make sure there is no diff anymore
47
 
        self.assertEqual(self.capture('diff'), '')
 
47
        self.assertEqual(self.capture('diff', retcode=0), '')
48
48
 
49
49
        # Make sure the file is actually back the way it was
50
50
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
57
57
        self.run_bzr('unshelve', retcode=True)
58
58
 
59
59
        # Check the diff is right again
60
 
        self.assertEqual(self.capture('diff'),
 
60
        self.assertEqual(self.capture('diff', retcode=1),
61
61
            self.DIFF_HEADER + self.DIFF_1 + '\n')
62
62
 
63
63
        # Make sure the file is back the way it should be
70
70
 
71
71
        # Create a test file and commit it
72
72
        file('test_file', 'w').write(self.ORIGINAL)
73
 
        b.add('test_file')
74
 
        b.commit(message='add test_file')
 
73
        b.working_tree().add('test_file')
 
74
        b.working_tree().commit(message='add test_file')
75
75
 
76
76
        # Shelve the changes
77
77
        self.run_bzr('shelve', '--all', retcode=True)
85
85
 
86
86
        # Create a test file and commit it
87
87
        file('test_file', 'w').write(self.ORIGINAL)
88
 
        b.add('test_file')
89
 
        b.commit(message='add test_file')
 
88
        b.working_tree().add('test_file')
 
89
        b.working_tree().commit(message='add test_file')
90
90
 
91
91
        # Modify the test file and commit it
92
92
        file('test_file', 'w').write(self.MODIFIED)
93
 
        b.commit(message='update test_file')
 
93
        b.working_tree().commit(message='update test_file')
94
94
 
95
95
        # Shelve the changes
96
96
        self.run_bzr('shelve', '-r', '1', '--all', retcode=True)
97
97
 
98
98
        # Check the diff is right
99
 
        self.assertEqual(self.capture('diff'),
 
99
        self.assertEqual(self.capture('diff', retcode=1),
100
100
            self.DIFF_HEADER + self.DIFF_2 + '\n')
101
101
 
102
102
        # Make sure the file is the way it should be
116
116
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)
117
117
 
118
118
        self.assertEqual(stderr.split('\n')[0],
119
 
            'bzr: ERROR: shelve only accepts a single revision parameter.')
 
119
            'bzr: ERROR: bzrlib.errors.BzrCommandError: shelve only ' \
 
120
                'accepts a single revision parameter.')