~ubuntu-branches/ubuntu/trusty/bzr-xmloutput/trusty

« back to all changes in this revision

Viewing changes to .pc/02_elementtree/tests/test_version_xml.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-02-21 11:30:46 UTC
  • Revision ID: package-import@ubuntu.com-20120221113046-n854cxkvrn6upq61
Tags: 0.8.8+bzr160-2
* Add patches to improve compatibility with newer versions of bzr:
 + 01_no_inventory: Don't rely on inventories being available
 + 02_elementtree: Use correct location of elementtree. Closes: #660728
 + 03_info_controldir: Fix support for 'bzr xmlinfo' in empty control
   directories.
 + 04_no_revision_history: Avoid using deprecated `Branch.revision_history`
   call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
"""Black-box tests for bzr version."""
 
18
 
 
19
import sys
 
20
 
 
21
import bzrlib
 
22
from bzrlib import osutils, trace
 
23
from bzrlib.tests import (
 
24
    probe_unicode_in_user_encoding,
 
25
    TestCaseInTempDir,
 
26
    TestSkipped,
 
27
    )
 
28
 
 
29
from bzrlib.xml_serializer import elementtree as elementtree
 
30
fromstring = elementtree.ElementTree.fromstring
 
31
 
 
32
from bzrlib.plugins.xmloutput import versionxml
 
33
 
 
34
 
 
35
class BaseVersionXMLTestCase(TestCaseInTempDir):
 
36
    """Base versionxml testcase."""
 
37
 
 
38
    def setUp(self):
 
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
 
51
 
 
52
    def tearDown(self):
 
53
        # restore the patched function.
 
54
        versionxml._show_source_tree = self.old_show_source_tree
 
55
        TestCaseInTempDir.tearDown(self)
 
56
 
 
57
 
 
58
class TestVersionXML(BaseVersionXMLTestCase):
 
59
 
 
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')))
 
71
        else:
 
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')))
 
75
 
 
76
 
 
77
class TestVersionXMLUnicodeOutput(BaseVersionXMLTestCase):
 
78
 
 
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'
 
89
        try:
 
90
            out = self.run_bzr(args)[0]
 
91
        finally:
 
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')))
 
96
 
 
97
    def test_command(self):
 
98
        self._check("xmlversion")
 
99
 
 
100
    def test_unicode_bzr_home(self):
 
101
        uni_val, str_val = probe_unicode_in_user_encoding()
 
102
        if uni_val is None:
 
103
            raise TestSkipped('Cannot find a unicode character that works in'
 
104
                              ' encoding %s' % \
 
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)
 
112
 
 
113
 
 
114