~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests.py

  • Committer: Michael Ellerman
  • Date: 2006-02-21 04:42:50 UTC
  • mto: (0.1.73 shelf-tmp)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060221044250-2a03e617e42b4862
Update tests for BzrDir changes, use test helpers to save future pain.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import bzrlib.tests
4
4
import os.path
5
5
 
6
 
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
 
6
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
7
7
    ORIGINAL = '\n\nhello test world\n\n'
8
8
    MODIFIED = '\n\ngoodbye test world\n\n'
9
9
    DIFF_HEADER = "=== modified file 'test_file'\n"
32
32
        self.__test_loop(10)
33
33
 
34
34
    def __test_loop(self, count):
35
 
        from bzrlib.branch import Branch
36
 
        b = Branch.initialize('.')
37
 
 
38
 
        # Create a test file and commit it
39
 
        file('test_file', 'w').write(self.ORIGINAL)
40
 
        b.working_tree().add('test_file')
41
 
        b.working_tree().commit(message='add test_file')
 
35
        tree = self.make_branch_and_tree('.')
 
36
        self.__create_and_add_test_file(tree)
42
37
 
43
38
        while count > 0:
44
39
            count -= 1
60
55
            self.assertEqual(file('test_file').read(), self.ORIGINAL)
61
56
 
62
57
            # Check the shelf is right
63
 
            shelf = open(os.path.join(b.base, '.shelf/shelves/default/00')).read()
 
58
            shelf = open(os.path.join(tree.branch.base,
 
59
                        '.shelf/shelves/default/00')).read()
64
60
            shelf = shelf[shelf.index('\n') + 1:] # skip the message
65
61
            self.assertEqual(shelf, self.DIFF_1)
66
62
 
76
72
 
77
73
    def test_shelf_nothing_to_shelve(self):
78
74
        import os.path
79
 
        from bzrlib.branch import Branch
80
 
        b = Branch.initialize('.')
81
 
 
82
 
        # Create a test file and commit it
83
 
        file('test_file', 'w').write(self.ORIGINAL)
84
 
        b.working_tree().add('test_file')
85
 
        b.working_tree().commit(message='add test_file')
 
75
        tree = self.make_branch_and_tree('.')
 
76
        self.__create_and_add_test_file(tree)
86
77
 
87
78
        # Shelve the changes
88
79
        self.run_bzr('shelve', retcode=3)
89
80
 
90
 
        if os.path.exists(os.path.join(b.base, '.shelf/shelves/default/00')):
 
81
        if os.path.exists(os.path.join(tree.branch.base,
 
82
                '.shelf/shelves/default/00')):
91
83
            self.fail("Shelf exists, but it shouldn't")
92
84
 
 
85
    def __create_and_add_test_file(self, tree):
 
86
        self.build_tree_contents([('test_file', self.ORIGINAL)])
 
87
        tree.add('test_file')
 
88
        tree.commit(message='add test_file')
 
89
 
93
90
    def test_shelf_with_revision(self):
94
 
        from bzrlib.branch import Branch
95
 
        b = Branch.initialize('.')
 
91
        tree = self.make_branch_and_tree('.')
96
92
 
97
 
        # Create a test file and commit it
98
 
        file('test_file', 'w').write(self.ORIGINAL)
99
 
        b.working_tree().add('test_file')
100
 
        b.working_tree().commit(message='add test_file')
 
93
        self.__create_and_add_test_file(tree)
101
94
 
102
95
        # Modify the test file and commit it
103
 
        file('test_file', 'w').write(self.MODIFIED)
104
 
        b.working_tree().commit(message='update test_file')
 
96
        self.build_tree_contents([('test_file', self.MODIFIED)])
 
97
        tree.commit(message='update test_file')
105
98
 
106
99
        # Shelve the changes
107
100
        self.run_bzr('shelve', '-r', '1', retcode=0)
120
113
        self.assertEqual(file('test_file').read(), self.MODIFIED)
121
114
 
122
115
    def test_shelf_with_two_revisions(self):
123
 
        from bzrlib.branch import Branch
124
 
        b = Branch.initialize('.')
 
116
        tree = self.make_branch_and_tree('.')
125
117
 
126
118
        cmd = 'shelve -r 1..2'
127
119
        (stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)