~abentley/bzrtools/bzrtools.dev

147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
1
# Copyright (C) 2005 Canonical Limited
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
#
4
#    This program is free software; you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public License as published by
6
#    the Free Software Foundation; either version 2 of the License, or
7
#    (at your option) any later version.
8
#
9
#    This program is distributed in the hope that it will be useful,
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#    GNU General Public License for more details.
13
#
14
#    You should have received a copy of the GNU General Public License
15
#    along with this program; if not, write to the Free Software
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
from bzrlib.selftest.TestUtil import TestLoader, TestSuite
19
from bzrlib.selftest import TestCaseInTempDir
20
try:
21
    import pybaz
22
except ImportError:
23
    pybaz = None
24
import os
25
from baz_import import import_version, revision_id
26
from bzrlib.branch import find_branch
27
28
def test_suite():
29
    if pybaz is None:
30
        return TestSuite()
31
    return TestLoader().loadTestsFromName(__name__)
32
    
33
34
class TestBazImport(TestCaseInTempDir):
35
36
    def setUp(self):
37
        TestCaseInTempDir.setUp(self)
38
        self._homedir = os.path.join(os.getcwdu(), 'home')
39
        self._oldhome = os.environ['HOME']
40
        os.mkdir(self._homedir)
41
        os.environ['HOME'] = self._homedir
42
        self._archiveroot = os.path.join(os.getcwdu(), 'archive')
43
        self._archive = pybaz.make_archive('demo@DONOTUSE', str(self._archiveroot))
44
        os.mkdir('tree')
45
        pybaz.set_my_id("Test User<test@example.org>")
46
        tree = pybaz.init_tree('tree', 'demo@DONOTUSE/c--import--0')
47
        msg = tree.log_message()
48
        msg["summary"] = "I am importing now"
49
        tree.import_(msg)
50
51
        self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
52
        self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
53
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
54
            pybaz.Version(self._empty_tag))
55
56
        self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
57
        self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag 
58
                                                 + '--patch-1')
59
        pybaz.Revision(self._empty_tag + '--base-0').make_continuation(
60
            pybaz.Version(self._empty_merged_tag))
61
        tree = pybaz.Revision(self._empty_merged_tag).get('tree-empty-merged')
62
        tree.star_merge(self._empty_tag)
63
64
    def tearDown(self):
65
        os.environ['HOME'] = self._oldhome
66
        
67
    def test_import_empty(self):
68
        import_version('output', pybaz.Version('demo@DONOTUSE/c--import--0'))
69
        # expected results:
70
        # one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
71
        branch = find_branch('output', find_root=False)
72
        self.assertEqual(branch.revision_history(),
73
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
74
        rev = branch.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
75
        # and again.
76
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
77
        branch2 = find_branch('output2', find_root=False)
78
        self.assertEqual(branch.revision_history(), branch2.revision_history())
79
        rev2 = branch2.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
80
        # they must be the same
81
        self.assertEqual(rev, rev2)
82
83
        # and we should get some expected values:
84
        self.assertEqual(rev.committer, "Test User<test@example.org>")
85
        self.assertEqual(rev.message, "I am importing now")
86
        self.assertEqual(rev.revision_id,
87
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
88
89
    def test_empty_tagged(self):
90
        import_version('output', pybaz.Version(self._empty_tag))
91
        # expected results:
92
        # two commits, no files, revision identifiers of 
93
        # 'demo@DONOTUSE_c--import--0--base-0' and
94
        # self._empty_tag_bzr
95
        branch = find_branch('output', find_root=False)
96
        self.assertEqual(branch.revision_history(),
97
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
98
                          self._empty_tag_bzr])
99
        rev = branch.get_revision(self._empty_tag_bzr)
100
        # and again.
101
        import_version('output2', pybaz.Version(self._empty_tag))
102
        branch2 = find_branch('output2', find_root=False)
103
        self.assertEqual(branch.revision_history(), branch2.revision_history())
104
        rev2 = branch2.get_revision(self._empty_tag_bzr)
105
        # they must be the same
106
        self.assertEqual(rev, rev2)
107
108
        # and we should get some expected values:
109
        self.assertEqual(rev.committer, "Test User<test@example.org>")
110
        self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
111
        self.assertEqual(rev.revision_id, self._empty_tag_bzr)
112