1212
1223
result = self.run_test_runner(runner, test)
1213
1224
output_string = output.getvalue()
1214
1225
self.assertContainsRe(output_string, "--date [0-9.]+")
1215
self.assertLength(1, self._get_source_tree_calls)
1217
def test_startTestRun(self):
1218
"""run should call result.startTestRun()"""
1220
class LoggingDecorator(tests.ForwardingResult):
1221
def startTestRun(self):
1222
tests.ForwardingResult.startTestRun(self)
1223
calls.append('startTestRun')
1224
test = unittest.FunctionTestCase(lambda:None)
1226
runner = tests.TextTestRunner(stream=stream,
1227
result_decorators=[LoggingDecorator])
1228
result = self.run_test_runner(runner, test)
1229
self.assertLength(1, calls)
1231
def test_stopTestRun(self):
1232
"""run should call result.stopTestRun()"""
1234
class LoggingDecorator(tests.ForwardingResult):
1235
def stopTestRun(self):
1236
tests.ForwardingResult.stopTestRun(self)
1237
calls.append('stopTestRun')
1238
test = unittest.FunctionTestCase(lambda:None)
1240
runner = tests.TextTestRunner(stream=stream,
1241
result_decorators=[LoggingDecorator])
1242
result = self.run_test_runner(runner, test)
1243
self.assertLength(1, calls)
1226
if workingtree is not None:
1227
revision_id = workingtree.get_parent_ids()[0]
1228
self.assertEndsWith(output_string.rstrip(), revision_id)
1230
def assertLogDeleted(self, test):
1231
log = test._get_log()
1232
self.assertEqual("DELETED log file to reduce memory footprint", log)
1233
self.assertEqual('', test._log_contents)
1234
self.assertIs(None, test._log_file_name)
1236
def test_success_log_deleted(self):
1237
"""Successful tests have their log deleted"""
1239
class LogTester(tests.TestCase):
1241
def test_success(self):
1242
self.log('this will be removed\n')
1245
runner = tests.TextTestRunner(stream=sio)
1246
test = LogTester('test_success')
1247
result = self.run_test_runner(runner, test)
1249
self.assertLogDeleted(test)
1251
def test_skipped_log_deleted(self):
1252
"""Skipped tests have their log deleted"""
1254
class LogTester(tests.TestCase):
1256
def test_skipped(self):
1257
self.log('this will be removed\n')
1258
raise tests.TestSkipped()
1261
runner = tests.TextTestRunner(stream=sio)
1262
test = LogTester('test_skipped')
1263
result = self.run_test_runner(runner, test)
1265
self.assertLogDeleted(test)
1267
def test_not_aplicable_log_deleted(self):
1268
"""Not applicable tests have their log deleted"""
1270
class LogTester(tests.TestCase):
1272
def test_not_applicable(self):
1273
self.log('this will be removed\n')
1274
raise tests.TestNotApplicable()
1277
runner = tests.TextTestRunner(stream=sio)
1278
test = LogTester('test_not_applicable')
1279
result = self.run_test_runner(runner, test)
1281
self.assertLogDeleted(test)
1283
def test_known_failure_log_deleted(self):
1284
"""Know failure tests have their log deleted"""
1286
class LogTester(tests.TestCase):
1288
def test_known_failure(self):
1289
self.log('this will be removed\n')
1290
raise tests.KnownFailure()
1293
runner = tests.TextTestRunner(stream=sio)
1294
test = LogTester('test_known_failure')
1295
result = self.run_test_runner(runner, test)
1297
self.assertLogDeleted(test)
1299
def test_fail_log_kept(self):
1300
"""Failed tests have their log kept"""
1302
class LogTester(tests.TestCase):
1304
def test_fail(self):
1305
self.log('this will be kept\n')
1306
self.fail('this test fails')
1309
runner = tests.TextTestRunner(stream=sio)
1310
test = LogTester('test_fail')
1311
result = self.run_test_runner(runner, test)
1313
text = sio.getvalue()
1314
self.assertContainsRe(text, 'this will be kept')
1315
self.assertContainsRe(text, 'this test fails')
1317
log = test._get_log()
1318
self.assertContainsRe(log, 'this will be kept')
1319
self.assertEqual(log, test._log_contents)
1321
def test_error_log_kept(self):
1322
"""Tests with errors have their log kept"""
1324
class LogTester(tests.TestCase):
1326
def test_error(self):
1327
self.log('this will be kept\n')
1328
raise ValueError('random exception raised')
1331
runner = tests.TextTestRunner(stream=sio)
1332
test = LogTester('test_error')
1333
result = self.run_test_runner(runner, test)
1335
text = sio.getvalue()
1336
self.assertContainsRe(text, 'this will be kept')
1337
self.assertContainsRe(text, 'random exception raised')
1339
log = test._get_log()
1340
self.assertContainsRe(log, 'this will be kept')
1341
self.assertEqual(log, test._log_contents)
1246
1344
class SampleTestCase(tests.TestCase):
1846
1805
test_suite_factory=factory)
1847
1806
self.assertEqual([True], factory_called)
1850
"""A test suite factory."""
1851
class Test(tests.TestCase):
1858
return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")])
1860
def test_list_only(self):
1861
output = self.run_selftest(test_suite_factory=self.factory,
1863
self.assertEqual(3, len(output.readlines()))
1865
def test_list_only_filtered(self):
1866
output = self.run_selftest(test_suite_factory=self.factory,
1867
list_only=True, pattern="Test.b")
1868
self.assertEndsWith(output.getvalue(), "Test.b\n")
1869
self.assertLength(1, output.readlines())
1871
def test_list_only_excludes(self):
1872
output = self.run_selftest(test_suite_factory=self.factory,
1873
list_only=True, exclude_pattern="Test.b")
1874
self.assertNotContainsRe("Test.b", output.getvalue())
1875
self.assertLength(2, output.readlines())
1877
def test_lsprof_tests(self):
1878
self.requireFeature(test_lsprof.LSProfFeature)
1881
def __call__(test, result):
1883
def run(test, result):
1884
self.assertIsInstance(result, tests.ForwardingResult)
1885
calls.append("called")
1886
def countTestCases(self):
1888
self.run_selftest(test_suite_factory=Test, lsprof_tests=True)
1889
self.assertLength(1, calls)
1891
def test_random(self):
1892
# test randomising by listing a number of tests.
1893
output_123 = self.run_selftest(test_suite_factory=self.factory,
1894
list_only=True, random_seed="123")
1895
output_234 = self.run_selftest(test_suite_factory=self.factory,
1896
list_only=True, random_seed="234")
1897
self.assertNotEqual(output_123, output_234)
1898
# "Randominzing test order..\n\n
1899
self.assertLength(5, output_123.readlines())
1900
self.assertLength(5, output_234.readlines())
1902
def test_random_reuse_is_same_order(self):
1903
# test randomising by listing a number of tests.
1904
expected = self.run_selftest(test_suite_factory=self.factory,
1905
list_only=True, random_seed="123")
1906
repeated = self.run_selftest(test_suite_factory=self.factory,
1907
list_only=True, random_seed="123")
1908
self.assertEqual(expected.getvalue(), repeated.getvalue())
1910
def test_runner_class(self):
1911
self.requireFeature(features.subunit)
1912
from subunit import ProtocolTestCase
1913
stream = self.run_selftest(runner_class=tests.SubUnitBzrRunner,
1914
test_suite_factory=self.factory)
1915
test = ProtocolTestCase(stream)
1916
result = unittest.TestResult()
1918
self.assertEqual(3, result.testsRun)
1920
def test_starting_with_single_argument(self):
1921
output = self.run_selftest(test_suite_factory=self.factory,
1922
starting_with=['bzrlib.tests.test_selftest.Test.a'],
1924
self.assertEqual('bzrlib.tests.test_selftest.Test.a\n',
1927
def test_starting_with_multiple_argument(self):
1928
output = self.run_selftest(test_suite_factory=self.factory,
1929
starting_with=['bzrlib.tests.test_selftest.Test.a',
1930
'bzrlib.tests.test_selftest.Test.b'],
1932
self.assertEqual('bzrlib.tests.test_selftest.Test.a\n'
1933
'bzrlib.tests.test_selftest.Test.b\n',
1936
def check_transport_set(self, transport_server):
1937
captured_transport = []
1938
def seen_transport(a_transport):
1939
captured_transport.append(a_transport)
1940
class Capture(tests.TestCase):
1942
seen_transport(bzrlib.tests.default_transport)
1944
return TestUtil.TestSuite([Capture("a")])
1945
self.run_selftest(transport=transport_server, test_suite_factory=factory)
1946
self.assertEqual(transport_server, captured_transport[0])
1948
def test_transport_sftp(self):
1949
self.requireFeature(features.paramiko)
1950
self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1952
def test_transport_memory(self):
1953
self.check_transport_set(memory.MemoryServer)
1956
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
1957
# Does IO: reads test.list
1959
def test_load_list(self):
1960
# Provide a list with one test - this test.
1961
test_id_line = '%s\n' % self.id()
1962
self.build_tree_contents([('test.list', test_id_line)])
1963
# And generate a list of the tests in the suite.
1964
stream = self.run_selftest(load_list='test.list', list_only=True)
1965
self.assertEqual(test_id_line, stream.getvalue())
1967
def test_load_unknown(self):
1968
# Provide a list with one test - this test.
1969
# And generate a list of the tests in the suite.
1970
err = self.assertRaises(errors.NoSuchFile, self.run_selftest,
1971
load_list='missing file name', list_only=True)
1974
class TestRunBzr(tests.TestCase):
1979
def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,
1981
"""Override _run_bzr_core to test how it is invoked by run_bzr.
1983
Attempts to run bzr from inside this class don't actually run it.
1985
We test how run_bzr actually invokes bzr in another location. Here we
1986
only need to test that it passes the right parameters to run_bzr.
1988
self.argv = list(argv)
1989
self.retcode = retcode
1990
self.encoding = encoding
1992
self.working_dir = working_dir
1993
return self.retcode, self.out, self.err
1995
def test_run_bzr_error(self):
1996
self.out = "It sure does!\n"
1997
out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=34)
1998
self.assertEqual(['rocks'], self.argv)
1999
self.assertEqual(34, self.retcode)
2000
self.assertEqual('It sure does!\n', out)
2001
self.assertEquals(out, self.out)
2002
self.assertEqual('', err)
2003
self.assertEquals(err, self.err)
2005
def test_run_bzr_error_regexes(self):
2007
self.err = "bzr: ERROR: foobarbaz is not versioned"
2008
out, err = self.run_bzr_error(
2009
["bzr: ERROR: foobarbaz is not versioned"],
2010
['file-id', 'foobarbaz'])
2012
def test_encoding(self):
2013
"""Test that run_bzr passes encoding to _run_bzr_core"""
2014
self.run_bzr('foo bar')
2015
self.assertEqual(None, self.encoding)
2016
self.assertEqual(['foo', 'bar'], self.argv)
2018
self.run_bzr('foo bar', encoding='baz')
2019
self.assertEqual('baz', self.encoding)
2020
self.assertEqual(['foo', 'bar'], self.argv)
2022
def test_retcode(self):
2023
"""Test that run_bzr passes retcode to _run_bzr_core"""
2024
# Default is retcode == 0
2025
self.run_bzr('foo bar')
2026
self.assertEqual(0, self.retcode)
2027
self.assertEqual(['foo', 'bar'], self.argv)
2029
self.run_bzr('foo bar', retcode=1)
2030
self.assertEqual(1, self.retcode)
2031
self.assertEqual(['foo', 'bar'], self.argv)
2033
self.run_bzr('foo bar', retcode=None)
2034
self.assertEqual(None, self.retcode)
2035
self.assertEqual(['foo', 'bar'], self.argv)
2037
self.run_bzr(['foo', 'bar'], retcode=3)
2038
self.assertEqual(3, self.retcode)
2039
self.assertEqual(['foo', 'bar'], self.argv)
2041
def test_stdin(self):
2042
# test that the stdin keyword to run_bzr is passed through to
2043
# _run_bzr_core as-is. We do this by overriding
2044
# _run_bzr_core in this class, and then calling run_bzr,
2045
# which is a convenience function for _run_bzr_core, so
2047
self.run_bzr('foo bar', stdin='gam')
2048
self.assertEqual('gam', self.stdin)
2049
self.assertEqual(['foo', 'bar'], self.argv)
2051
self.run_bzr('foo bar', stdin='zippy')
2052
self.assertEqual('zippy', self.stdin)
2053
self.assertEqual(['foo', 'bar'], self.argv)
2055
def test_working_dir(self):
2056
"""Test that run_bzr passes working_dir to _run_bzr_core"""
2057
self.run_bzr('foo bar')
2058
self.assertEqual(None, self.working_dir)
2059
self.assertEqual(['foo', 'bar'], self.argv)
2061
self.run_bzr('foo bar', working_dir='baz')
2062
self.assertEqual('baz', self.working_dir)
2063
self.assertEqual(['foo', 'bar'], self.argv)
2065
def test_reject_extra_keyword_arguments(self):
2066
self.assertRaises(TypeError, self.run_bzr, "foo bar",
2067
error_regex=['error message'])
2070
class TestRunBzrCaptured(tests.TestCaseWithTransport):
2071
# Does IO when testing the working_dir parameter.
2073
def apply_redirected(self, stdin=None, stdout=None, stderr=None,
2074
a_callable=None, *args, **kwargs):
2076
self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
2077
self.factory = bzrlib.ui.ui_factory
2078
self.working_dir = osutils.getcwd()
2079
stdout.write('foo\n')
2080
stderr.write('bar\n')
2083
def test_stdin(self):
2084
# test that the stdin keyword to _run_bzr_core is passed through to
2085
# apply_redirected as a StringIO. We do this by overriding
2086
# apply_redirected in this class, and then calling _run_bzr_core,
2087
# which calls apply_redirected.
2088
self.run_bzr(['foo', 'bar'], stdin='gam')
2089
self.assertEqual('gam', self.stdin.read())
2090
self.assertTrue(self.stdin is self.factory_stdin)
2091
self.run_bzr(['foo', 'bar'], stdin='zippy')
2092
self.assertEqual('zippy', self.stdin.read())
2093
self.assertTrue(self.stdin is self.factory_stdin)
2095
def test_ui_factory(self):
2096
# each invocation of self.run_bzr should get its
2097
# own UI factory, which is an instance of TestUIFactory,
2098
# with stdin, stdout and stderr attached to the stdin,
2099
# stdout and stderr of the invoked run_bzr
2100
current_factory = bzrlib.ui.ui_factory
2101
self.run_bzr(['foo'])
2102
self.failIf(current_factory is self.factory)
2103
self.assertNotEqual(sys.stdout, self.factory.stdout)
2104
self.assertNotEqual(sys.stderr, self.factory.stderr)
2105
self.assertEqual('foo\n', self.factory.stdout.getvalue())
2106
self.assertEqual('bar\n', self.factory.stderr.getvalue())
2107
self.assertIsInstance(self.factory, tests.TestUIFactory)
2109
def test_working_dir(self):
2110
self.build_tree(['one/', 'two/'])
2111
cwd = osutils.getcwd()
2113
# Default is to work in the current directory
2114
self.run_bzr(['foo', 'bar'])
2115
self.assertEqual(cwd, self.working_dir)
2117
self.run_bzr(['foo', 'bar'], working_dir=None)
2118
self.assertEqual(cwd, self.working_dir)
2120
# The function should be run in the alternative directory
2121
# but afterwards the current working dir shouldn't be changed
2122
self.run_bzr(['foo', 'bar'], working_dir='one')
2123
self.assertNotEqual(cwd, self.working_dir)
2124
self.assertEndsWith(self.working_dir, 'one')
2125
self.assertEqual(cwd, osutils.getcwd())
2127
self.run_bzr(['foo', 'bar'], working_dir='two')
2128
self.assertNotEqual(cwd, self.working_dir)
2129
self.assertEndsWith(self.working_dir, 'two')
2130
self.assertEqual(cwd, osutils.getcwd())
2133
class StubProcess(object):
2134
"""A stub process for testing run_bzr_subprocess."""
2136
def __init__(self, out="", err="", retcode=0):
2139
self.returncode = retcode
2141
def communicate(self):
2142
return self.out, self.err
2145
class TestWithFakedStartBzrSubprocess(tests.TestCaseWithTransport):
2146
"""Base class for tests testing how we might run bzr."""
2149
tests.TestCaseWithTransport.setUp(self)
2150
self.subprocess_calls = []
2152
def start_bzr_subprocess(self, process_args, env_changes=None,
2153
skip_if_plan_to_signal=False,
2155
allow_plugins=False):
2156
"""capture what run_bzr_subprocess tries to do."""
2157
self.subprocess_calls.append({'process_args':process_args,
2158
'env_changes':env_changes,
2159
'skip_if_plan_to_signal':skip_if_plan_to_signal,
2160
'working_dir':working_dir, 'allow_plugins':allow_plugins})
2161
return self.next_subprocess
2164
class TestRunBzrSubprocess(TestWithFakedStartBzrSubprocess):
2166
def assertRunBzrSubprocess(self, expected_args, process, *args, **kwargs):
2167
"""Run run_bzr_subprocess with args and kwargs using a stubbed process.
2169
Inside TestRunBzrSubprocessCommands we use a stub start_bzr_subprocess
2170
that will return static results. This assertion method populates those
2171
results and also checks the arguments run_bzr_subprocess generates.
2173
self.next_subprocess = process
2175
result = self.run_bzr_subprocess(*args, **kwargs)
2177
self.next_subprocess = None
2178
for key, expected in expected_args.iteritems():
2179
self.assertEqual(expected, self.subprocess_calls[-1][key])
1809
class TestKnownFailure(tests.TestCase):
1811
def test_known_failure(self):
1812
"""Check that KnownFailure is defined appropriately."""
1813
# a KnownFailure is an assertion error for compatability with unaware
1815
self.assertIsInstance(tests.KnownFailure(""), AssertionError)
1817
def test_expect_failure(self):
1819
self.expectFailure("Doomed to failure", self.assertTrue, False)
1820
except tests.KnownFailure, e:
1821
self.assertEqual('Doomed to failure', e.args[0])
1823
self.expectFailure("Doomed to failure", self.assertTrue, True)
1824
except AssertionError, e:
1825
self.assertEqual('Unexpected success. Should have failed:'
1826
' Doomed to failure', e.args[0])
2182
self.next_subprocess = None
2183
for key, expected in expected_args.iteritems():
2184
self.assertEqual(expected, self.subprocess_calls[-1][key])
2187
def test_run_bzr_subprocess(self):
2188
"""The run_bzr_helper_external command behaves nicely."""
2189
self.assertRunBzrSubprocess({'process_args':['--version']},
2190
StubProcess(), '--version')
2191
self.assertRunBzrSubprocess({'process_args':['--version']},
2192
StubProcess(), ['--version'])
2193
# retcode=None disables retcode checking
2194
result = self.assertRunBzrSubprocess({},
2195
StubProcess(retcode=3), '--version', retcode=None)
2196
result = self.assertRunBzrSubprocess({},
2197
StubProcess(out="is free software"), '--version')
2198
self.assertContainsRe(result[0], 'is free software')
2199
# Running a subcommand that is missing errors
2200
self.assertRaises(AssertionError, self.assertRunBzrSubprocess,
2201
{'process_args':['--versionn']}, StubProcess(retcode=3),
2203
# Unless it is told to expect the error from the subprocess
2204
result = self.assertRunBzrSubprocess({},
2205
StubProcess(retcode=3), '--versionn', retcode=3)
2206
# Or to ignore retcode checking
2207
result = self.assertRunBzrSubprocess({},
2208
StubProcess(err="unknown command", retcode=3), '--versionn',
2210
self.assertContainsRe(result[1], 'unknown command')
2212
def test_env_change_passes_through(self):
2213
self.assertRunBzrSubprocess(
2214
{'env_changes':{'new':'value', 'changed':'newvalue', 'deleted':None}},
2216
env_changes={'new':'value', 'changed':'newvalue', 'deleted':None})
2218
def test_no_working_dir_passed_as_None(self):
2219
self.assertRunBzrSubprocess({'working_dir': None}, StubProcess(), '')
2221
def test_no_working_dir_passed_through(self):
2222
self.assertRunBzrSubprocess({'working_dir': 'dir'}, StubProcess(), '',
2225
def test_run_bzr_subprocess_no_plugins(self):
2226
self.assertRunBzrSubprocess({'allow_plugins': False},
2229
def test_allow_plugins(self):
2230
self.assertRunBzrSubprocess({'allow_plugins': True},
2231
StubProcess(), '', allow_plugins=True)
2234
class TestFinishBzrSubprocess(TestWithFakedStartBzrSubprocess):
2236
def test_finish_bzr_subprocess_with_error(self):
2237
"""finish_bzr_subprocess allows specification of the desired exit code.
2239
process = StubProcess(err="unknown command", retcode=3)
2240
result = self.finish_bzr_subprocess(process, retcode=3)
2241
self.assertEqual('', result[0])
2242
self.assertContainsRe(result[1], 'unknown command')
2244
def test_finish_bzr_subprocess_ignoring_retcode(self):
2245
"""finish_bzr_subprocess allows the exit code to be ignored."""
2246
process = StubProcess(err="unknown command", retcode=3)
2247
result = self.finish_bzr_subprocess(process, retcode=None)
2248
self.assertEqual('', result[0])
2249
self.assertContainsRe(result[1], 'unknown command')
2251
def test_finish_subprocess_with_unexpected_retcode(self):
2252
"""finish_bzr_subprocess raises self.failureException if the retcode is
2253
not the expected one.
2255
process = StubProcess(err="unknown command", retcode=3)
2256
self.assertRaises(self.failureException, self.finish_bzr_subprocess,
2260
class _DontSpawnProcess(Exception):
2261
"""A simple exception which just allows us to skip unnecessary steps"""
2264
class TestStartBzrSubProcess(tests.TestCase):
2266
def check_popen_state(self):
2267
"""Replace to make assertions when popen is called."""
2269
def _popen(self, *args, **kwargs):
2270
"""Record the command that is run, so that we can ensure it is correct"""
2271
self.check_popen_state()
2272
self._popen_args = args
2273
self._popen_kwargs = kwargs
2274
raise _DontSpawnProcess()
2276
def test_run_bzr_subprocess_no_plugins(self):
2277
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [])
2278
command = self._popen_args[0]
2279
self.assertEqual(sys.executable, command[0])
2280
self.assertEqual(self.get_bzr_path(), command[1])
2281
self.assertEqual(['--no-plugins'], command[2:])
2283
def test_allow_plugins(self):
2284
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2286
command = self._popen_args[0]
2287
self.assertEqual([], command[2:])
2289
def test_set_env(self):
2290
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2292
def check_environment():
2293
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2294
self.check_popen_state = check_environment
2295
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2296
env_changes={'EXISTANT_ENV_VAR':'set variable'})
2297
# not set in theparent
2298
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2300
def test_run_bzr_subprocess_env_del(self):
2301
"""run_bzr_subprocess can remove environment variables too."""
2302
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2303
def check_environment():
2304
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2305
os.environ['EXISTANT_ENV_VAR'] = 'set variable'
2306
self.check_popen_state = check_environment
2307
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2308
env_changes={'EXISTANT_ENV_VAR':None})
2309
# Still set in parent
2310
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2311
del os.environ['EXISTANT_ENV_VAR']
2313
def test_env_del_missing(self):
2314
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ)
2315
def check_environment():
2316
self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
2317
self.check_popen_state = check_environment
2318
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2319
env_changes={'NON_EXISTANT_ENV_VAR':None})
2321
def test_working_dir(self):
2322
"""Test that we can specify the working dir for the child"""
2323
orig_getcwd = osutils.getcwd
2324
orig_chdir = os.chdir
2332
osutils.getcwd = getcwd
2334
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2337
osutils.getcwd = orig_getcwd
2339
os.chdir = orig_chdir
2340
self.assertEqual(['foo', 'current'], chdirs)
2343
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2344
"""Tests that really need to do things with an external bzr."""
2346
def test_start_and_stop_bzr_subprocess_send_signal(self):
2347
"""finish_bzr_subprocess raises self.failureException if the retcode is
2348
not the expected one.
2350
self.disable_missing_extensions_warning()
2351
process = self.start_bzr_subprocess(['wait-until-signalled'],
2352
skip_if_plan_to_signal=True)
2353
self.assertEqual('running\n', process.stdout.readline())
2354
result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT,
2356
self.assertEqual('', result[0])
2357
self.assertEqual('bzr: interrupted\n', result[1])
1828
self.fail('Assertion not raised')
2360
1831
class TestFeature(tests.TestCase):