~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests.py

  • Committer: Michael Ellerman
  • Date: 2005-10-19 13:14:03 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-20051019131403-1a486e7fd9daa840
Add basic tests for shelve --all, and unshelve.
Also test shelve with nothing to shelve.

Show diffs side-by-side

added added

removed removed

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