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
113
|
# Copyright (C) 2007, 2008 Canonical Ltd
#
# 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
"""Black-box tests for bzr version."""
import os
import sys
import bzrlib
from bzrlib import osutils, trace
from bzrlib.tests import (
probe_unicode_in_user_encoding,
TestCase,
TestCaseInTempDir,
TestSkipped,
)
class TestVersion(TestCase):
def test_version(self):
out = self.run_bzr("version")[0]
self.assertTrue(len(out) > 0)
# must occur once; could be more if it matches a file path
first = out.splitlines()[0]
self.assertEqualDiff(first,
"Bazaar (bzr) %s" % bzrlib.__version__)
self.assertContainsRe(out, r"(?m)^ Python interpreter:")
self.assertContainsRe(out, r"(?m)^ Python standard library:")
self.assertContainsRe(out, r"(?m)^ bzrlib:")
self.assertContainsRe(out, r"(?m)^ Bazaar configuration:")
self.assertContainsRe(out, r'(?m)^ Bazaar log file:.*\.bzr\.log')
def test_version_short(self):
out = self.run_bzr(["version", "--short"])[0]
self.assertEqualDiff(out, bzrlib.version_string + '\n')
class TestVersionUnicodeOutput(TestCaseInTempDir):
def _check(self, args):
# Even though trace._bzr_log_filename variable
# is used only to keep actual log filename
# and changing this variable in selftest
# don't change main .bzr.log location,
# and therefore pretty safe,
# but we run these tests in separate temp dir
# with relative unicoded path
old_trace_file = trace._bzr_log_filename
trace._bzr_log_filename = u'\u1234/.bzr.log'
try:
out = self.run_bzr(args)[0]
finally:
trace._bzr_log_filename = old_trace_file
self.assertTrue(len(out) > 0)
self.assertContainsRe(out, r'(?m)^ Bazaar log file:.*bzr\.log')
def test_command(self):
self._check("version")
def test_flag(self):
self._check("--version")
def test_unicode_bzr_home(self):
uni_val, str_val = probe_unicode_in_user_encoding()
if uni_val is None:
raise TestSkipped('Cannot find a unicode character that works in'
' encoding %s' % (bzrlib.user_encoding,))
osutils.set_or_unset_env('BZR_HOME', str_val)
out = self.run_bzr("version")[0]
self.assertTrue(len(out) > 0)
self.assertContainsRe(out, r"(?m)^ Bazaar configuration: " + str_val)
class TestVersionBzrLogLocation(TestCaseInTempDir):
def test_simple(self):
bzr_log = 'my.bzr.log'
osutils.set_or_unset_env('BZR_LOG', bzr_log)
default_log = os.path.join(os.environ['BZR_HOME'], '.bzr.log')
self.failIfExists([default_log, bzr_log])
out = self.run_bzr_subprocess('version')[0]
self.assertTrue(len(out) > 0)
self.assertContainsRe(out, r"(?m)^ Bazaar log file: " + bzr_log)
self.failIfExists(default_log)
self.failUnlessExists(bzr_log)
def test_dev_null(self):
if sys.platform == 'win32':
bzr_log = 'NUL'
else:
bzr_log = '/dev/null'
osutils.set_or_unset_env('BZR_LOG', bzr_log)
default_log = os.path.join(os.environ['BZR_HOME'], '.bzr.log')
self.failIfExists(default_log)
out = self.run_bzr_subprocess('version')[0]
self.assertTrue(len(out) > 0)
self.assertContainsRe(out, r"(?m)^ Bazaar log file: " + bzr_log)
self.failIfExists(default_log)
|