~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright (C) 2005 Canonical Limited
#   Authors: Robert Collins <robert.collins@canonical.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

from bzrlib.selftest.TestUtil import TestLoader, TestSuite
from bzrlib.selftest import TestCaseInTempDir
try:
    import pybaz
except ImportError:
    pybaz = None
import os
from baz_import import import_version, revision_id
from bzrlib.branch import find_branch

def test_suite():
    if pybaz is None:
        return TestSuite()
    return TestLoader().loadTestsFromName(__name__)
    

class TestBazImport(TestCaseInTempDir):

    def setUp(self):
        TestCaseInTempDir.setUp(self)
        self._homedir = os.path.join(os.getcwdu(), 'home')
        self._oldhome = os.environ['HOME']
        os.mkdir(self._homedir)
        os.environ['HOME'] = self._homedir
        self._archiveroot = os.path.join(os.getcwdu(), 'archive')
        self._archive = pybaz.make_archive('demo@DONOTUSE', str(self._archiveroot))
        os.mkdir('tree')
        pybaz.set_my_id("Test User<test@example.org>")
        tree = pybaz.init_tree('tree', 'demo@DONOTUSE/c--import--0')
        msg = tree.log_message()
        msg["summary"] = "I am importing now"
        tree.import_(msg)

        self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
        self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
            pybaz.Version(self._empty_tag))

        self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
        self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag 
                                                 + '--patch-1')
        pybaz.Revision(self._empty_tag + '--base-0').make_continuation(
            pybaz.Version(self._empty_merged_tag))
        tree = pybaz.Revision(self._empty_merged_tag).get('tree-empty-merged')
        tree.star_merge(self._empty_tag)

    def tearDown(self):
        os.environ['HOME'] = self._oldhome
        
    def test_import_empty(self):
        import_version('output', pybaz.Version('demo@DONOTUSE/c--import--0'))
        # expected results:
        # one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
        branch = find_branch('output', find_root=False)
        self.assertEqual(branch.revision_history(),
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
        rev = branch.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
        # and again.
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
        branch2 = find_branch('output2', find_root=False)
        self.assertEqual(branch.revision_history(), branch2.revision_history())
        rev2 = branch2.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
        # they must be the same
        self.assertEqual(rev, rev2)

        # and we should get some expected values:
        self.assertEqual(rev.committer, "Test User<test@example.org>")
        self.assertEqual(rev.message, "I am importing now")
        self.assertEqual(rev.revision_id,
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")

    def test_empty_tagged(self):
        import_version('output', pybaz.Version(self._empty_tag))
        # expected results:
        # two commits, no files, revision identifiers of 
        # 'demo@DONOTUSE_c--import--0--base-0' and
        # self._empty_tag_bzr
        branch = find_branch('output', find_root=False)
        self.assertEqual(branch.revision_history(),
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
                          self._empty_tag_bzr])
        rev = branch.get_revision(self._empty_tag_bzr)
        # and again.
        import_version('output2', pybaz.Version(self._empty_tag))
        branch2 = find_branch('output2', find_root=False)
        self.assertEqual(branch.revision_history(), branch2.revision_history())
        rev2 = branch2.get_revision(self._empty_tag_bzr)
        # they must be the same
        self.assertEqual(rev, rev2)

        # and we should get some expected values:
        self.assertEqual(rev.committer, "Test User<test@example.org>")
        self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
        self.assertEqual(rev.revision_id, self._empty_tag_bzr)