/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.54.76 by Vincent Ladeuil
Fix the broken test.
1
# Copyright (C) 2007-2010 Canonical Ltd
0.54.61 by Jeff Licquia
Assign copyright to Canonical.
2
#
0.54.40 by Jeff Licquia
Move the tests to their own module.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
0.54.61 by Jeff Licquia
Assign copyright to Canonical.
6
# (at your option) any later version.
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
7
#
0.54.40 by Jeff Licquia
Move the tests to their own module.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
12
#
0.54.40 by Jeff Licquia
Move the tests to their own module.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.54.40 by Jeff Licquia
Move the tests to their own module.
16
0.54.56 by Jeff Licquia
Fix some pylint complaints.
17
"Test suite for the bzr bisect plugin."
18
7479.2.1 by Jelmer Vernooij
Drop python2 support.
19
from io import StringIO
0.54.40 by Jeff Licquia
Move the tests to their own module.
20
import os
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
21
import shutil
0.54.78 by Jelmer Vernooij
Merge several improvements from Gustaf:
22
6656.2.5 by Jelmer Vernooij
Fix import.
23
from ..controldir import ControlDir
6625.4.1 by Jelmer Vernooij
Merge bisect.
24
from .. import bisect
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
25
from . import (
0.62.1 by Jelmer Vernooij
Lazy load plugin.
26
    TestCaseWithTransport,
0.54.78 by Jelmer Vernooij
Merge several improvements from Gustaf:
27
    TestSkipped,
28
    )
0.54.52 by Jeff Licquia
PEP 8 fixes.
29
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
30
0.62.1 by Jelmer Vernooij
Lazy load plugin.
31
class BisectTestCase(TestCaseWithTransport):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
32
    """Test harness specific to the bisect plugin."""
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
33
0.54.40 by Jeff Licquia
Move the tests to their own module.
34
    def assertRevno(self, rev):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
35
        """Make sure we're at the right revision."""
0.54.40 by Jeff Licquia
Move the tests to their own module.
36
0.54.52 by Jeff Licquia
PEP 8 fixes.
37
        rev_contents = {1: "one", 1.1: "one dot one", 1.2: "one dot two",
38
                        1.3: "one dot three", 2: "two", 3: "three",
39
                        4: "four", 5: "five"}
0.54.40 by Jeff Licquia
Move the tests to their own module.
40
6656.1.1 by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers
41
        with open("test_file") as f:
42
            content = f.read().strip()
0.54.50 by Jeff Licquia
Better diagnostics when an assertRevno() call fails.
43
        if content != rev_contents[rev]:
6656.1.3 by Martin
Now this really is the biggest of the big
44
            rev_ids = dict((rev_contents[k], k) for k in rev_contents)
0.54.50 by Jeff Licquia
Better diagnostics when an assertRevno() call fails.
45
            found_rev = rev_ids[content]
46
            raise AssertionError("expected rev %0.1f, found rev %0.1f"
47
                                 % (rev, found_rev))
0.54.40 by Jeff Licquia
Move the tests to their own module.
48
49
    def setUp(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
50
        """Set up tests."""
0.54.40 by Jeff Licquia
Move the tests to their own module.
51
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
52
        # These tests assume a branch with five revisions, and
53
        # a branch from version 1 containing three revisions
54
        # merged at version 2.
0.54.40 by Jeff Licquia
Move the tests to their own module.
55
0.62.1 by Jelmer Vernooij
Lazy load plugin.
56
        TestCaseWithTransport.setUp(self)
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
57
0.54.40 by Jeff Licquia
Move the tests to their own module.
58
        self.tree = self.make_branch_and_tree(".")
59
0.54.56 by Jeff Licquia
Fix some pylint complaints.
60
        test_file = open("test_file", "w")
61
        test_file.write("one")
62
        test_file.close()
0.54.52 by Jeff Licquia
PEP 8 fixes.
63
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(),
64
                                                     'test_file')))
0.60.1 by Gustaf Thorslund
Added test cases for running a test script:
65
        test_file_append = open("test_file_append", "a")
66
        test_file_append.write("one\n")
67
        test_file_append.close()
68
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(),
69
                                                     'test_file_append')))
7143.15.2 by Jelmer Vernooij
Run autopep8.
70
        self.tree.commit(message="add test files")
0.54.40 by Jeff Licquia
Move the tests to their own module.
71
6667.2.1 by Jelmer Vernooij
Some cleanup; s/BzrDir/ControlDir/, remove some unused imports.
72
        ControlDir.open(".").sprout("../temp-clone")
73
        clone_bzrdir = ControlDir.open("../temp-clone")
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
74
        clone_tree = clone_bzrdir.open_workingtree()
75
        for content in ["one dot one", "one dot two", "one dot three"]:
0.54.56 by Jeff Licquia
Fix some pylint complaints.
76
            test_file = open("../temp-clone/test_file", "w")
77
            test_file.write(content)
78
            test_file.close()
0.60.1 by Gustaf Thorslund
Added test cases for running a test script:
79
            test_file_append = open("../temp-clone/test_file_append", "a")
80
            test_file_append.write(content + "\n")
81
            test_file_append.close()
7143.15.2 by Jelmer Vernooij
Run autopep8.
82
            clone_tree.commit(message="make branch test change")
0.54.49 by Jeff Licquia
Add subtree and harness tests.
83
            saved_subtree_revid = clone_tree.branch.last_revision()
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
84
85
        self.tree.merge_from_branch(clone_tree.branch)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
86
        test_file = open("test_file", "w")
87
        test_file.write("two")
88
        test_file.close()
0.60.1 by Gustaf Thorslund
Added test cases for running a test script:
89
        test_file_append = open("test_file_append", "a")
90
        test_file_append.write("two\n")
91
        test_file_append.close()
7143.15.2 by Jelmer Vernooij
Run autopep8.
92
        self.tree.commit(message="merge external branch")
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
93
        shutil.rmtree("../temp-clone")
94
0.54.49 by Jeff Licquia
Add subtree and harness tests.
95
        self.subtree_rev = saved_subtree_revid
96
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
97
        file_contents = ["three", "four", "five"]
0.54.40 by Jeff Licquia
Move the tests to their own module.
98
        for content in file_contents:
0.54.56 by Jeff Licquia
Fix some pylint complaints.
99
            test_file = open("test_file", "w")
100
            test_file.write(content)
101
            test_file.close()
0.60.1 by Gustaf Thorslund
Added test cases for running a test script:
102
            test_file_append = open("test_file_append", "a")
103
            test_file_append.write(content + "\n")
104
            test_file_append.close()
7143.15.2 by Jelmer Vernooij
Run autopep8.
105
            self.tree.commit(message="make test change")
0.54.40 by Jeff Licquia
Move the tests to their own module.
106
0.54.52 by Jeff Licquia
PEP 8 fixes.
107
0.54.49 by Jeff Licquia
Add subtree and harness tests.
108
class BisectHarnessTests(BisectTestCase):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
109
    """Tests for the harness itself."""
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
110
0.54.49 by Jeff Licquia
Add subtree and harness tests.
111
    def testLastRev(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
112
        """Test that the last revision is correct."""
0.54.52 by Jeff Licquia
PEP 8 fixes.
113
        repo = self.tree.branch.repository
114
        top_revtree = repo.revision_tree(self.tree.last_revision())
0.54.49 by Jeff Licquia
Add subtree and harness tests.
115
        top_revtree.lock_read()
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
116
        top_file = top_revtree.get_file("test_file")
0.54.49 by Jeff Licquia
Add subtree and harness tests.
117
        test_content = top_file.read().strip()
118
        top_file.close()
119
        top_revtree.unlock()
7027.3.1 by Jelmer Vernooij
Fix bisect.
120
        self.assertEqual(test_content, b"five")
0.54.49 by Jeff Licquia
Add subtree and harness tests.
121
122
    def testSubtreeRev(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
123
        """Test that the last revision in a subtree is correct."""
0.54.52 by Jeff Licquia
PEP 8 fixes.
124
        repo = self.tree.branch.repository
125
        sub_revtree = repo.revision_tree(self.subtree_rev)
0.54.49 by Jeff Licquia
Add subtree and harness tests.
126
        sub_revtree.lock_read()
7027.3.1 by Jelmer Vernooij
Fix bisect.
127
        with sub_revtree.get_file("test_file") as sub_file:
128
            test_content = sub_file.read().strip()
0.54.49 by Jeff Licquia
Add subtree and harness tests.
129
        sub_revtree.unlock()
7027.3.1 by Jelmer Vernooij
Fix bisect.
130
        self.assertEqual(test_content, b"one dot three")
0.54.49 by Jeff Licquia
Add subtree and harness tests.
131
0.54.52 by Jeff Licquia
PEP 8 fixes.
132
0.54.40 by Jeff Licquia
Move the tests to their own module.
133
class BisectCurrentUnitTests(BisectTestCase):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
134
    """Test the BisectCurrent class."""
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
135
0.54.40 by Jeff Licquia
Move the tests to their own module.
136
    def testShowLog(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
137
        """Test that the log can be shown."""
0.54.40 by Jeff Licquia
Move the tests to their own module.
138
        # Not a very good test; just makes sure the code doesn't fail,
139
        # not that the output makes any sense.
0.54.72 by James Westby
Start to remove the use of sys.stdout.
140
        sio = StringIO()
6835 by Jelmer Vernooij
Merge lp:~jelmer/brz/268573-outf
141
        bisect.BisectCurrent(self.tree.controldir).show_rev_log(outf=sio)
0.54.40 by Jeff Licquia
Move the tests to their own module.
142
0.54.49 by Jeff Licquia
Add subtree and harness tests.
143
    def testShowLogSubtree(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
144
        """Test that a subtree's log can be shown."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
145
        current = bisect.BisectCurrent(self.tree.controldir)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
146
        current.switch(self.subtree_rev)
0.54.72 by James Westby
Start to remove the use of sys.stdout.
147
        sio = StringIO()
6835 by Jelmer Vernooij
Merge lp:~jelmer/brz/268573-outf
148
        current.show_rev_log(outf=sio)
0.54.49 by Jeff Licquia
Add subtree and harness tests.
149
0.54.40 by Jeff Licquia
Move the tests to their own module.
150
    def testSwitchVersions(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
151
        """Test switching versions."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
152
        current = bisect.BisectCurrent(self.tree.controldir)
0.54.40 by Jeff Licquia
Move the tests to their own module.
153
        self.assertRevno(5)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
154
        current.switch(4)
0.54.40 by Jeff Licquia
Move the tests to their own module.
155
        self.assertRevno(4)
156
157
    def testReset(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
158
        """Test resetting the working tree to a non-bisected state."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
159
        current = bisect.BisectCurrent(self.tree.controldir)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
160
        current.switch(4)
161
        current.reset()
0.54.40 by Jeff Licquia
Move the tests to their own module.
162
        self.assertRevno(5)
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
163
        self.assertFalse(os.path.exists(
164
            os.path.join('.bzr', bisect.BISECT_REV_PATH)))
0.54.40 by Jeff Licquia
Move the tests to their own module.
165
0.54.43 by Jeff Licquia
Add non-functioning is_merge_point() method to BisectCurrent.
166
    def testIsMergePoint(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
167
        """Test merge point detection."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
168
        current = bisect.BisectCurrent(self.tree.controldir)
0.54.43 by Jeff Licquia
Add non-functioning is_merge_point() method to BisectCurrent.
169
        self.assertRevno(5)
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
170
        self.assertFalse(current.is_merge_point())
0.54.56 by Jeff Licquia
Fix some pylint complaints.
171
        current.switch(2)
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
172
        self.assertTrue(current.is_merge_point())
0.54.43 by Jeff Licquia
Add non-functioning is_merge_point() method to BisectCurrent.
173
0.54.52 by Jeff Licquia
PEP 8 fixes.
174
0.54.40 by Jeff Licquia
Move the tests to their own module.
175
class BisectLogUnitTests(BisectTestCase):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
176
    """Test the BisectLog class."""
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
177
0.54.40 by Jeff Licquia
Move the tests to their own module.
178
    def testCreateBlank(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
179
        """Test creation of new log."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
180
        bisect_log = bisect.BisectLog(self.tree.controldir)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
181
        bisect_log.save()
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
182
        self.assertTrue(
183
            os.path.exists(os.path.join('.bzr', bisect.BISECT_INFO_PATH)))
0.54.40 by Jeff Licquia
Move the tests to their own module.
184
185
    def testLoad(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
186
        """Test loading a log."""
7143.15.2 by Jelmer Vernooij
Run autopep8.
187
        preloaded_log = open(os.path.join(
188
            '.bzr', bisect.BISECT_INFO_PATH), "w")
0.54.56 by Jeff Licquia
Fix some pylint complaints.
189
        preloaded_log.write("rev1 yes\nrev2 no\nrev3 yes\n")
190
        preloaded_log.close()
0.54.40 by Jeff Licquia
Move the tests to their own module.
191
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
192
        bisect_log = bisect.BisectLog(self.tree.controldir)
6656.2.1 by Jelmer Vernooij
Integrate bisect command into core.
193
        self.assertEqual(len(bisect_log._items), 3)
7027.3.1 by Jelmer Vernooij
Fix bisect.
194
        self.assertEqual(bisect_log._items[0], (b"rev1", "yes"))
195
        self.assertEqual(bisect_log._items[1], (b"rev2", "no"))
196
        self.assertEqual(bisect_log._items[2], (b"rev3", "yes"))
0.54.40 by Jeff Licquia
Move the tests to their own module.
197
198
    def testSave(self):
0.60.4 by Gustaf Thorslund
Fixed " -> """ for docstrings. Added some docstrings. Also converted some #-comment into a docstring.
199
        """Test saving the log."""
6681.2.2 by Jelmer Vernooij
Use controldir API in bisect.
200
        bisect_log = bisect.BisectLog(self.tree.controldir)
7143.15.2 by Jelmer Vernooij
Run autopep8.
201
        bisect_log._items = [
202
            (b"rev1", "yes"), (b"rev2", "no"), (b"rev3", "yes")]
0.54.56 by Jeff Licquia
Fix some pylint complaints.
203
        bisect_log.save()
0.54.40 by Jeff Licquia
Move the tests to their own module.
204
7027.3.1 by Jelmer Vernooij
Fix bisect.
205
        with open(os.path.join('.bzr', bisect.BISECT_INFO_PATH), 'rb') as logfile:
206
            self.assertEqual(logfile.read(), b"rev1 yes\nrev2 no\nrev3 yes\n")