1
# Copyright (C) 2005 Canonical Limited
2
# Authors: Robert Collins <robert.collins@canonical.com>
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.
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.
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
18
from bzrlib.selftest.TestUtil import TestLoader, TestSuite
19
from bzrlib.selftest import TestCaseInTempDir
25
from baz_import import import_version, revision_id
26
from bzrlib.branch import find_branch
31
return TestLoader().loadTestsFromName(__name__)
34
class TestBazImport(TestCaseInTempDir):
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))
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"
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))
56
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
57
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
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)
65
os.environ['HOME'] = self._oldhome
67
def test_import_empty(self):
68
import_version('output', pybaz.Version('demo@DONOTUSE/c--import--0'))
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')
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)
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")
89
def test_empty_tagged(self):
90
import_version('output', pybaz.Version(self._empty_tag))
92
# two commits, no files, revision identifiers of
93
# 'demo@DONOTUSE_c--import--0--base-0' and
95
branch = find_branch('output', find_root=False)
96
self.assertEqual(branch.revision_history(),
97
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
99
rev = branch.get_revision(self._empty_tag_bzr)
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)
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)