~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests.py

  • Committer: Michael Ellerman
  • Date: 2005-11-28 06:24:55 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-20051128062455-9da2ff70dd70e65c
Add tests for new shelf layout.

Shelves are now named .bzr/x-shelf/default/0x where x increases.

Also add a test for doing shelve/unshelve multiple times.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
"""
27
27
    def test_shelf(self):
 
28
        self.__test_loop(1)
 
29
 
 
30
    def test_shelf_multi(self):
 
31
        self.__test_loop(10)
 
32
 
 
33
    def __test_loop(self, count):
28
34
        from bzrlib.branch import Branch
29
35
        b = Branch.initialize('.')
30
36
 
33
39
        b.working_tree().add('test_file')
34
40
        b.working_tree().commit(message='add test_file')
35
41
 
36
 
        # Modify the test file
37
 
        file('test_file', 'w').write(self.MODIFIED)
38
 
 
39
 
        # Check the diff is right
40
 
        self.assertEqual(self.capture('diff', retcode=1),
41
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
42
 
 
43
 
        # Shelve the changes
44
 
        self.run_bzr('shelve', '--all', retcode=True)
45
 
 
46
 
        # Make sure there is no diff anymore
47
 
        self.assertEqual(self.capture('diff', retcode=0), '')
48
 
 
49
 
        # Make sure the file is actually back the way it was
50
 
        self.assertEqual(file('test_file').read(), self.ORIGINAL)
51
 
 
52
 
        # Check the shelf is right
53
 
        shelf = file('.bzr-shelf').read()
54
 
        self.assertEqual(shelf, self.DIFF_1)
55
 
 
56
 
        # Unshelve
57
 
        self.run_bzr('unshelve', retcode=True)
58
 
 
59
 
        # Check the diff is right again
60
 
        self.assertEqual(self.capture('diff', retcode=1),
61
 
            self.DIFF_HEADER + self.DIFF_1 + '\n')
62
 
 
63
 
        # Make sure the file is back the way it should be
64
 
        self.assertEqual(file('test_file').read(), self.MODIFIED)
 
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', '--all', 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)
65
74
 
66
75
    def test_shelf_nothing_to_shelve(self):
67
76
        import os.path
76
85
        # Shelve the changes
77
86
        self.run_bzr('shelve', '--all', retcode=True)
78
87
 
79
 
        if os.path.exists('.bzr-shelf'):
 
88
        if b._transport.has('.bzr/x-shelf/default/00'):
80
89
            self.fail("Shelf exists, but it shouldn't")
81
90
 
82
91
    def test_shelf_with_revision(self):