1
# Copyright (C) 2007 Canonical Ltd
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
6
# (at your option) any later version.
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.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Black-box tests for bzr version."""
22
from bzrlib import osutils, trace
23
from bzrlib.tests import (
24
probe_unicode_in_user_encoding,
29
from bzrlib.xml_serializer import elementtree as elementtree
30
fromstring = elementtree.ElementTree.fromstring
32
from bzrlib.plugins.xmloutput import versionxml
35
class BaseVersionXMLTestCase(TestCaseInTempDir):
36
"""Base versionxml testcase."""
39
TestCaseInTempDir.setUp(self)
40
# versionxml tries to call bzrlib.version._get_bzr_source_tree(), which
41
# tries an open_containing within the bzr installation. This will cause
42
# a test isolation failure. You might hope that you could avoid this
43
# with TestCase.permit_source_tree_branch_repo(), but this does not
44
# work when running against a bzr installation that has no source tree,
45
# as in this case, the open_containing operation needs to recurse
46
# upwards to the filesystem root before it knows that it is finished.
47
# Therefore we just stub out the relevant function so that it does not
48
# call the problem method.
49
self.old_show_source_tree = versionxml._show_source_tree
50
versionxml._show_source_tree = lambda _: None
53
# restore the patched function.
54
versionxml._show_source_tree = self.old_show_source_tree
55
TestCaseInTempDir.tearDown(self)
58
class TestVersionXML(BaseVersionXMLTestCase):
60
def test_version(self):
61
out = self.run_bzr("xmlversion")[0]
62
versionElem = fromstring(out)
63
self.assertTrue(len(out) > 0)
64
self.assertEquals(1, len(versionElem.findall('bazaar/version')))
65
self.assertEquals(1, len(versionElem.findall('bazaar/bzrlib')))
66
self.assertEquals(1, len(versionElem.findall('bazaar/configuration')))
67
self.assertEquals(1, len(versionElem.findall('bazaar/log_file')))
68
self.assertEquals(1, len(versionElem.findall('bazaar/copyright')))
69
if sys.platform == "win32":
70
self.assertEquals(1, len(versionElem.findall('python/dll')))
72
self.assertEquals(1, len(versionElem.findall('python/executable')))
73
self.assertEquals(1, len(versionElem.findall('python/version')))
74
self.assertEquals(1, len(versionElem.findall('python/standard_library')))
77
class TestVersionXMLUnicodeOutput(BaseVersionXMLTestCase):
79
def _check(self, args):
80
# Even though trace._bzr_log_filename variable
81
# is used only to keep actual log filename
82
# and changing this variable in selftest
83
# don't change main .bzr.log location,
84
# and therefore pretty safe,
85
# but we run these tests in separate temp dir
86
# with relative unicoded path
87
old_trace_file = trace._bzr_log_filename
88
trace._bzr_log_filename = u'\u1234/.bzr.log'
90
out = self.run_bzr(args)[0]
92
trace._bzr_log_filename = old_trace_file
93
versionElem = fromstring(out)
94
self.assertTrue(len(out) > 0)
95
self.assertEquals(1, len(versionElem.findall('bazaar/log_file')))
97
def test_command(self):
98
self._check("xmlversion")
100
def test_unicode_bzr_home(self):
101
uni_val, str_val = probe_unicode_in_user_encoding()
103
raise TestSkipped('Cannot find a unicode character that works in'
105
bzrlib.osutils.get_user_encoding())
106
osutils.set_or_unset_env('BZR_HOME', str_val)
107
out = self.run_bzr("xmlversion")[0]
108
self.assertTrue(len(out) > 0)
109
versionElem = fromstring(out)
110
self.assertEquals(1, len(versionElem.findall('bazaar/configuration')))
111
self.assertContainsRe(out, r"<configuration>" + str_val)