1224
1209
result = self.run_test_runner(runner, test)
1225
1210
output_string = output.getvalue()
1226
1211
self.assertContainsRe(output_string, "--date [0-9.]+")
1227
if workingtree is not None:
1228
revision_id = workingtree.get_parent_ids()[0]
1229
self.assertEndsWith(output_string.rstrip(), revision_id)
1231
def assertLogDeleted(self, test):
1232
log = test._get_log()
1233
self.assertEqual("DELETED log file to reduce memory footprint", log)
1234
self.assertEqual('', test._log_contents)
1235
self.assertIs(None, test._log_file_name)
1237
def test_success_log_deleted(self):
1238
"""Successful tests have their log deleted"""
1240
class LogTester(tests.TestCase):
1242
def test_success(self):
1243
self.log('this will be removed\n')
1246
runner = tests.TextTestRunner(stream=sio)
1247
test = LogTester('test_success')
1248
result = self.run_test_runner(runner, test)
1250
self.assertLogDeleted(test)
1252
def test_skipped_log_deleted(self):
1253
"""Skipped tests have their log deleted"""
1255
class LogTester(tests.TestCase):
1257
def test_skipped(self):
1258
self.log('this will be removed\n')
1259
raise tests.TestSkipped()
1262
runner = tests.TextTestRunner(stream=sio)
1263
test = LogTester('test_skipped')
1264
result = self.run_test_runner(runner, test)
1266
self.assertLogDeleted(test)
1268
def test_not_aplicable_log_deleted(self):
1269
"""Not applicable tests have their log deleted"""
1271
class LogTester(tests.TestCase):
1273
def test_not_applicable(self):
1274
self.log('this will be removed\n')
1275
raise tests.TestNotApplicable()
1278
runner = tests.TextTestRunner(stream=sio)
1279
test = LogTester('test_not_applicable')
1280
result = self.run_test_runner(runner, test)
1282
self.assertLogDeleted(test)
1284
def test_known_failure_log_deleted(self):
1285
"""Know failure tests have their log deleted"""
1287
class LogTester(tests.TestCase):
1289
def test_known_failure(self):
1290
self.log('this will be removed\n')
1291
raise tests.KnownFailure()
1294
runner = tests.TextTestRunner(stream=sio)
1295
test = LogTester('test_known_failure')
1296
result = self.run_test_runner(runner, test)
1298
self.assertLogDeleted(test)
1300
def test_fail_log_kept(self):
1301
"""Failed tests have their log kept"""
1303
class LogTester(tests.TestCase):
1305
def test_fail(self):
1306
self.log('this will be kept\n')
1307
self.fail('this test fails')
1310
runner = tests.TextTestRunner(stream=sio)
1311
test = LogTester('test_fail')
1312
result = self.run_test_runner(runner, test)
1314
text = sio.getvalue()
1315
self.assertContainsRe(text, 'this will be kept')
1316
self.assertContainsRe(text, 'this test fails')
1318
log = test._get_log()
1319
self.assertContainsRe(log, 'this will be kept')
1320
self.assertEqual(log, test._log_contents)
1322
def test_error_log_kept(self):
1323
"""Tests with errors have their log kept"""
1325
class LogTester(tests.TestCase):
1327
def test_error(self):
1328
self.log('this will be kept\n')
1329
raise ValueError('random exception raised')
1332
runner = tests.TextTestRunner(stream=sio)
1333
test = LogTester('test_error')
1334
result = self.run_test_runner(runner, test)
1336
text = sio.getvalue()
1337
self.assertContainsRe(text, 'this will be kept')
1338
self.assertContainsRe(text, 'random exception raised')
1340
log = test._get_log()
1341
self.assertContainsRe(log, 'this will be kept')
1342
self.assertEqual(log, test._log_contents)
1212
self.assertLength(1, self._get_source_tree_calls)
1214
def test_startTestRun(self):
1215
"""run should call result.startTestRun()"""
1217
class LoggingDecorator(tests.ForwardingResult):
1218
def startTestRun(self):
1219
tests.ForwardingResult.startTestRun(self)
1220
calls.append('startTestRun')
1221
test = unittest.FunctionTestCase(lambda:None)
1223
runner = tests.TextTestRunner(stream=stream,
1224
result_decorators=[LoggingDecorator])
1225
result = self.run_test_runner(runner, test)
1226
self.assertLength(1, calls)
1228
def test_stopTestRun(self):
1229
"""run should call result.stopTestRun()"""
1231
class LoggingDecorator(tests.ForwardingResult):
1232
def stopTestRun(self):
1233
tests.ForwardingResult.stopTestRun(self)
1234
calls.append('stopTestRun')
1235
test = unittest.FunctionTestCase(lambda:None)
1237
runner = tests.TextTestRunner(stream=stream,
1238
result_decorators=[LoggingDecorator])
1239
result = self.run_test_runner(runner, test)
1240
self.assertLength(1, calls)
1345
1243
class SampleTestCase(tests.TestCase):
1813
1843
test_suite_factory=factory)
1814
1844
self.assertEqual([True], factory_called)
1817
class TestKnownFailure(tests.TestCase):
1819
def test_known_failure(self):
1820
"""Check that KnownFailure is defined appropriately."""
1821
# a KnownFailure is an assertion error for compatability with unaware
1823
self.assertIsInstance(tests.KnownFailure(""), AssertionError)
1825
def test_expect_failure(self):
1827
self.expectFailure("Doomed to failure", self.assertTrue, False)
1828
except tests.KnownFailure, e:
1829
self.assertEqual('Doomed to failure', e.args[0])
1831
self.expectFailure("Doomed to failure", self.assertTrue, True)
1832
except AssertionError, e:
1833
self.assertEqual('Unexpected success. Should have failed:'
1834
' Doomed to failure', e.args[0])
1847
"""A test suite factory."""
1848
class Test(tests.TestCase):
1855
return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")])
1857
def test_list_only(self):
1858
output = self.run_selftest(test_suite_factory=self.factory,
1860
self.assertEqual(3, len(output.readlines()))
1862
def test_list_only_filtered(self):
1863
output = self.run_selftest(test_suite_factory=self.factory,
1864
list_only=True, pattern="Test.b")
1865
self.assertEndsWith(output.getvalue(), "Test.b\n")
1866
self.assertLength(1, output.readlines())
1868
def test_list_only_excludes(self):
1869
output = self.run_selftest(test_suite_factory=self.factory,
1870
list_only=True, exclude_pattern="Test.b")
1871
self.assertNotContainsRe("Test.b", output.getvalue())
1872
self.assertLength(2, output.readlines())
1874
def test_lsprof_tests(self):
1875
self.requireFeature(test_lsprof.LSProfFeature)
1878
def __call__(test, result):
1880
def run(test, result):
1881
self.assertIsInstance(result, tests.ForwardingResult)
1882
calls.append("called")
1883
def countTestCases(self):
1885
self.run_selftest(test_suite_factory=Test, lsprof_tests=True)
1886
self.assertLength(1, calls)
1888
def test_random(self):
1889
# test randomising by listing a number of tests.
1890
output_123 = self.run_selftest(test_suite_factory=self.factory,
1891
list_only=True, random_seed="123")
1892
output_234 = self.run_selftest(test_suite_factory=self.factory,
1893
list_only=True, random_seed="234")
1894
self.assertNotEqual(output_123, output_234)
1895
# "Randominzing test order..\n\n
1896
self.assertLength(5, output_123.readlines())
1897
self.assertLength(5, output_234.readlines())
1899
def test_random_reuse_is_same_order(self):
1900
# test randomising by listing a number of tests.
1901
expected = self.run_selftest(test_suite_factory=self.factory,
1902
list_only=True, random_seed="123")
1903
repeated = self.run_selftest(test_suite_factory=self.factory,
1904
list_only=True, random_seed="123")
1905
self.assertEqual(expected.getvalue(), repeated.getvalue())
1907
def test_runner_class(self):
1908
self.requireFeature(features.subunit)
1909
from subunit import ProtocolTestCase
1910
stream = self.run_selftest(runner_class=tests.SubUnitBzrRunner,
1911
test_suite_factory=self.factory)
1912
test = ProtocolTestCase(stream)
1913
result = unittest.TestResult()
1915
self.assertEqual(3, result.testsRun)
1917
def test_starting_with_single_argument(self):
1918
output = self.run_selftest(test_suite_factory=self.factory,
1919
starting_with=['bzrlib.tests.test_selftest.Test.a'],
1921
self.assertEqual('bzrlib.tests.test_selftest.Test.a\n',
1924
def test_starting_with_multiple_argument(self):
1925
output = self.run_selftest(test_suite_factory=self.factory,
1926
starting_with=['bzrlib.tests.test_selftest.Test.a',
1927
'bzrlib.tests.test_selftest.Test.b'],
1929
self.assertEqual('bzrlib.tests.test_selftest.Test.a\n'
1930
'bzrlib.tests.test_selftest.Test.b\n',
1933
def check_transport_set(self, transport_server):
1934
captured_transport = []
1935
def seen_transport(a_transport):
1936
captured_transport.append(a_transport)
1937
class Capture(tests.TestCase):
1939
seen_transport(bzrlib.tests.default_transport)
1941
return TestUtil.TestSuite([Capture("a")])
1942
self.run_selftest(transport=transport_server, test_suite_factory=factory)
1943
self.assertEqual(transport_server, captured_transport[0])
1945
def test_transport_sftp(self):
1946
self.requireFeature(features.paramiko)
1947
from bzrlib.tests import stub_sftp
1948
self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1950
def test_transport_memory(self):
1951
self.check_transport_set(memory.MemoryServer)
1954
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
1955
# Does IO: reads test.list
1957
def test_load_list(self):
1958
# Provide a list with one test - this test.
1959
test_id_line = '%s\n' % self.id()
1960
self.build_tree_contents([('test.list', test_id_line)])
1961
# And generate a list of the tests in the suite.
1962
stream = self.run_selftest(load_list='test.list', list_only=True)
1963
self.assertEqual(test_id_line, stream.getvalue())
1965
def test_load_unknown(self):
1966
# Provide a list with one test - this test.
1967
# And generate a list of the tests in the suite.
1968
err = self.assertRaises(errors.NoSuchFile, self.run_selftest,
1969
load_list='missing file name', list_only=True)
1972
class TestRunBzr(tests.TestCase):
1977
def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,
1979
"""Override _run_bzr_core to test how it is invoked by run_bzr.
1981
Attempts to run bzr from inside this class don't actually run it.
1983
We test how run_bzr actually invokes bzr in another location. Here we
1984
only need to test that it passes the right parameters to run_bzr.
1986
self.argv = list(argv)
1987
self.retcode = retcode
1988
self.encoding = encoding
1990
self.working_dir = working_dir
1991
return self.retcode, self.out, self.err
1993
def test_run_bzr_error(self):
1994
self.out = "It sure does!\n"
1995
out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=34)
1996
self.assertEqual(['rocks'], self.argv)
1997
self.assertEqual(34, self.retcode)
1998
self.assertEqual('It sure does!\n', out)
1999
self.assertEquals(out, self.out)
2000
self.assertEqual('', err)
2001
self.assertEquals(err, self.err)
2003
def test_run_bzr_error_regexes(self):
2005
self.err = "bzr: ERROR: foobarbaz is not versioned"
2006
out, err = self.run_bzr_error(
2007
["bzr: ERROR: foobarbaz is not versioned"],
2008
['file-id', 'foobarbaz'])
2010
def test_encoding(self):
2011
"""Test that run_bzr passes encoding to _run_bzr_core"""
2012
self.run_bzr('foo bar')
2013
self.assertEqual(None, self.encoding)
2014
self.assertEqual(['foo', 'bar'], self.argv)
2016
self.run_bzr('foo bar', encoding='baz')
2017
self.assertEqual('baz', self.encoding)
2018
self.assertEqual(['foo', 'bar'], self.argv)
2020
def test_retcode(self):
2021
"""Test that run_bzr passes retcode to _run_bzr_core"""
2022
# Default is retcode == 0
2023
self.run_bzr('foo bar')
2024
self.assertEqual(0, self.retcode)
2025
self.assertEqual(['foo', 'bar'], self.argv)
2027
self.run_bzr('foo bar', retcode=1)
2028
self.assertEqual(1, self.retcode)
2029
self.assertEqual(['foo', 'bar'], self.argv)
2031
self.run_bzr('foo bar', retcode=None)
2032
self.assertEqual(None, self.retcode)
2033
self.assertEqual(['foo', 'bar'], self.argv)
2035
self.run_bzr(['foo', 'bar'], retcode=3)
2036
self.assertEqual(3, self.retcode)
2037
self.assertEqual(['foo', 'bar'], self.argv)
2039
def test_stdin(self):
2040
# test that the stdin keyword to run_bzr is passed through to
2041
# _run_bzr_core as-is. We do this by overriding
2042
# _run_bzr_core in this class, and then calling run_bzr,
2043
# which is a convenience function for _run_bzr_core, so
2045
self.run_bzr('foo bar', stdin='gam')
2046
self.assertEqual('gam', self.stdin)
2047
self.assertEqual(['foo', 'bar'], self.argv)
2049
self.run_bzr('foo bar', stdin='zippy')
2050
self.assertEqual('zippy', self.stdin)
2051
self.assertEqual(['foo', 'bar'], self.argv)
2053
def test_working_dir(self):
2054
"""Test that run_bzr passes working_dir to _run_bzr_core"""
2055
self.run_bzr('foo bar')
2056
self.assertEqual(None, self.working_dir)
2057
self.assertEqual(['foo', 'bar'], self.argv)
2059
self.run_bzr('foo bar', working_dir='baz')
2060
self.assertEqual('baz', self.working_dir)
2061
self.assertEqual(['foo', 'bar'], self.argv)
2063
def test_reject_extra_keyword_arguments(self):
2064
self.assertRaises(TypeError, self.run_bzr, "foo bar",
2065
error_regex=['error message'])
2068
class TestRunBzrCaptured(tests.TestCaseWithTransport):
2069
# Does IO when testing the working_dir parameter.
2071
def apply_redirected(self, stdin=None, stdout=None, stderr=None,
2072
a_callable=None, *args, **kwargs):
2074
self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
2075
self.factory = bzrlib.ui.ui_factory
2076
self.working_dir = osutils.getcwd()
2077
stdout.write('foo\n')
2078
stderr.write('bar\n')
2081
def test_stdin(self):
2082
# test that the stdin keyword to _run_bzr_core is passed through to
2083
# apply_redirected as a StringIO. We do this by overriding
2084
# apply_redirected in this class, and then calling _run_bzr_core,
2085
# which calls apply_redirected.
2086
self.run_bzr(['foo', 'bar'], stdin='gam')
2087
self.assertEqual('gam', self.stdin.read())
2088
self.assertTrue(self.stdin is self.factory_stdin)
2089
self.run_bzr(['foo', 'bar'], stdin='zippy')
2090
self.assertEqual('zippy', self.stdin.read())
2091
self.assertTrue(self.stdin is self.factory_stdin)
2093
def test_ui_factory(self):
2094
# each invocation of self.run_bzr should get its
2095
# own UI factory, which is an instance of TestUIFactory,
2096
# with stdin, stdout and stderr attached to the stdin,
2097
# stdout and stderr of the invoked run_bzr
2098
current_factory = bzrlib.ui.ui_factory
2099
self.run_bzr(['foo'])
2100
self.failIf(current_factory is self.factory)
2101
self.assertNotEqual(sys.stdout, self.factory.stdout)
2102
self.assertNotEqual(sys.stderr, self.factory.stderr)
2103
self.assertEqual('foo\n', self.factory.stdout.getvalue())
2104
self.assertEqual('bar\n', self.factory.stderr.getvalue())
2105
self.assertIsInstance(self.factory, tests.TestUIFactory)
2107
def test_working_dir(self):
2108
self.build_tree(['one/', 'two/'])
2109
cwd = osutils.getcwd()
2111
# Default is to work in the current directory
2112
self.run_bzr(['foo', 'bar'])
2113
self.assertEqual(cwd, self.working_dir)
2115
self.run_bzr(['foo', 'bar'], working_dir=None)
2116
self.assertEqual(cwd, self.working_dir)
2118
# The function should be run in the alternative directory
2119
# but afterwards the current working dir shouldn't be changed
2120
self.run_bzr(['foo', 'bar'], working_dir='one')
2121
self.assertNotEqual(cwd, self.working_dir)
2122
self.assertEndsWith(self.working_dir, 'one')
2123
self.assertEqual(cwd, osutils.getcwd())
2125
self.run_bzr(['foo', 'bar'], working_dir='two')
2126
self.assertNotEqual(cwd, self.working_dir)
2127
self.assertEndsWith(self.working_dir, 'two')
2128
self.assertEqual(cwd, osutils.getcwd())
2131
class StubProcess(object):
2132
"""A stub process for testing run_bzr_subprocess."""
2134
def __init__(self, out="", err="", retcode=0):
2137
self.returncode = retcode
2139
def communicate(self):
2140
return self.out, self.err
2143
class TestWithFakedStartBzrSubprocess(tests.TestCaseWithTransport):
2144
"""Base class for tests testing how we might run bzr."""
2147
tests.TestCaseWithTransport.setUp(self)
2148
self.subprocess_calls = []
2150
def start_bzr_subprocess(self, process_args, env_changes=None,
2151
skip_if_plan_to_signal=False,
2153
allow_plugins=False):
2154
"""capture what run_bzr_subprocess tries to do."""
2155
self.subprocess_calls.append({'process_args':process_args,
2156
'env_changes':env_changes,
2157
'skip_if_plan_to_signal':skip_if_plan_to_signal,
2158
'working_dir':working_dir, 'allow_plugins':allow_plugins})
2159
return self.next_subprocess
2162
class TestRunBzrSubprocess(TestWithFakedStartBzrSubprocess):
2164
def assertRunBzrSubprocess(self, expected_args, process, *args, **kwargs):
2165
"""Run run_bzr_subprocess with args and kwargs using a stubbed process.
2167
Inside TestRunBzrSubprocessCommands we use a stub start_bzr_subprocess
2168
that will return static results. This assertion method populates those
2169
results and also checks the arguments run_bzr_subprocess generates.
2171
self.next_subprocess = process
2173
result = self.run_bzr_subprocess(*args, **kwargs)
2175
self.next_subprocess = None
2176
for key, expected in expected_args.iteritems():
2177
self.assertEqual(expected, self.subprocess_calls[-1][key])
1836
self.fail('Assertion not raised')
2180
self.next_subprocess = None
2181
for key, expected in expected_args.iteritems():
2182
self.assertEqual(expected, self.subprocess_calls[-1][key])
2185
def test_run_bzr_subprocess(self):
2186
"""The run_bzr_helper_external command behaves nicely."""
2187
self.assertRunBzrSubprocess({'process_args':['--version']},
2188
StubProcess(), '--version')
2189
self.assertRunBzrSubprocess({'process_args':['--version']},
2190
StubProcess(), ['--version'])
2191
# retcode=None disables retcode checking
2192
result = self.assertRunBzrSubprocess({},
2193
StubProcess(retcode=3), '--version', retcode=None)
2194
result = self.assertRunBzrSubprocess({},
2195
StubProcess(out="is free software"), '--version')
2196
self.assertContainsRe(result[0], 'is free software')
2197
# Running a subcommand that is missing errors
2198
self.assertRaises(AssertionError, self.assertRunBzrSubprocess,
2199
{'process_args':['--versionn']}, StubProcess(retcode=3),
2201
# Unless it is told to expect the error from the subprocess
2202
result = self.assertRunBzrSubprocess({},
2203
StubProcess(retcode=3), '--versionn', retcode=3)
2204
# Or to ignore retcode checking
2205
result = self.assertRunBzrSubprocess({},
2206
StubProcess(err="unknown command", retcode=3), '--versionn',
2208
self.assertContainsRe(result[1], 'unknown command')
2210
def test_env_change_passes_through(self):
2211
self.assertRunBzrSubprocess(
2212
{'env_changes':{'new':'value', 'changed':'newvalue', 'deleted':None}},
2214
env_changes={'new':'value', 'changed':'newvalue', 'deleted':None})
2216
def test_no_working_dir_passed_as_None(self):
2217
self.assertRunBzrSubprocess({'working_dir': None}, StubProcess(), '')
2219
def test_no_working_dir_passed_through(self):
2220
self.assertRunBzrSubprocess({'working_dir': 'dir'}, StubProcess(), '',
2223
def test_run_bzr_subprocess_no_plugins(self):
2224
self.assertRunBzrSubprocess({'allow_plugins': False},
2227
def test_allow_plugins(self):
2228
self.assertRunBzrSubprocess({'allow_plugins': True},
2229
StubProcess(), '', allow_plugins=True)
2232
class TestFinishBzrSubprocess(TestWithFakedStartBzrSubprocess):
2234
def test_finish_bzr_subprocess_with_error(self):
2235
"""finish_bzr_subprocess allows specification of the desired exit code.
2237
process = StubProcess(err="unknown command", retcode=3)
2238
result = self.finish_bzr_subprocess(process, retcode=3)
2239
self.assertEqual('', result[0])
2240
self.assertContainsRe(result[1], 'unknown command')
2242
def test_finish_bzr_subprocess_ignoring_retcode(self):
2243
"""finish_bzr_subprocess allows the exit code to be ignored."""
2244
process = StubProcess(err="unknown command", retcode=3)
2245
result = self.finish_bzr_subprocess(process, retcode=None)
2246
self.assertEqual('', result[0])
2247
self.assertContainsRe(result[1], 'unknown command')
2249
def test_finish_subprocess_with_unexpected_retcode(self):
2250
"""finish_bzr_subprocess raises self.failureException if the retcode is
2251
not the expected one.
2253
process = StubProcess(err="unknown command", retcode=3)
2254
self.assertRaises(self.failureException, self.finish_bzr_subprocess,
2258
class _DontSpawnProcess(Exception):
2259
"""A simple exception which just allows us to skip unnecessary steps"""
2262
class TestStartBzrSubProcess(tests.TestCase):
2264
def check_popen_state(self):
2265
"""Replace to make assertions when popen is called."""
2267
def _popen(self, *args, **kwargs):
2268
"""Record the command that is run, so that we can ensure it is correct"""
2269
self.check_popen_state()
2270
self._popen_args = args
2271
self._popen_kwargs = kwargs
2272
raise _DontSpawnProcess()
2274
def test_run_bzr_subprocess_no_plugins(self):
2275
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [])
2276
command = self._popen_args[0]
2277
self.assertEqual(sys.executable, command[0])
2278
self.assertEqual(self.get_bzr_path(), command[1])
2279
self.assertEqual(['--no-plugins'], command[2:])
2281
def test_allow_plugins(self):
2282
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2284
command = self._popen_args[0]
2285
self.assertEqual([], command[2:])
2287
def test_set_env(self):
2288
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2290
def check_environment():
2291
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2292
self.check_popen_state = check_environment
2293
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2294
env_changes={'EXISTANT_ENV_VAR':'set variable'})
2295
# not set in theparent
2296
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2298
def test_run_bzr_subprocess_env_del(self):
2299
"""run_bzr_subprocess can remove environment variables too."""
2300
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2301
def check_environment():
2302
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2303
os.environ['EXISTANT_ENV_VAR'] = 'set variable'
2304
self.check_popen_state = check_environment
2305
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2306
env_changes={'EXISTANT_ENV_VAR':None})
2307
# Still set in parent
2308
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2309
del os.environ['EXISTANT_ENV_VAR']
2311
def test_env_del_missing(self):
2312
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ)
2313
def check_environment():
2314
self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
2315
self.check_popen_state = check_environment
2316
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2317
env_changes={'NON_EXISTANT_ENV_VAR':None})
2319
def test_working_dir(self):
2320
"""Test that we can specify the working dir for the child"""
2321
orig_getcwd = osutils.getcwd
2322
orig_chdir = os.chdir
2330
osutils.getcwd = getcwd
2332
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2335
osutils.getcwd = orig_getcwd
2337
os.chdir = orig_chdir
2338
self.assertEqual(['foo', 'current'], chdirs)
2341
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2342
"""Tests that really need to do things with an external bzr."""
2344
def test_start_and_stop_bzr_subprocess_send_signal(self):
2345
"""finish_bzr_subprocess raises self.failureException if the retcode is
2346
not the expected one.
2348
self.disable_missing_extensions_warning()
2349
process = self.start_bzr_subprocess(['wait-until-signalled'],
2350
skip_if_plan_to_signal=True)
2351
self.assertEqual('running\n', process.stdout.readline())
2352
result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT,
2354
self.assertEqual('', result[0])
2355
self.assertEqual('bzr: interrupted\n', result[1])
1839
2358
class TestFeature(tests.TestCase):