1224
1213
result = self.run_test_runner(runner, test)
1225
1214
output_string = output.getvalue()
1226
1215
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)
1216
self.assertLength(1, self._get_source_tree_calls)
1218
def test_startTestRun(self):
1219
"""run should call result.startTestRun()"""
1221
class LoggingDecorator(tests.ForwardingResult):
1222
def startTestRun(self):
1223
tests.ForwardingResult.startTestRun(self)
1224
calls.append('startTestRun')
1225
test = unittest.FunctionTestCase(lambda:None)
1227
runner = tests.TextTestRunner(stream=stream,
1228
result_decorators=[LoggingDecorator])
1229
result = self.run_test_runner(runner, test)
1230
self.assertLength(1, calls)
1232
def test_stopTestRun(self):
1233
"""run should call result.stopTestRun()"""
1235
class LoggingDecorator(tests.ForwardingResult):
1236
def stopTestRun(self):
1237
tests.ForwardingResult.stopTestRun(self)
1238
calls.append('stopTestRun')
1239
test = unittest.FunctionTestCase(lambda:None)
1241
runner = tests.TextTestRunner(stream=stream,
1242
result_decorators=[LoggingDecorator])
1243
result = self.run_test_runner(runner, test)
1244
self.assertLength(1, calls)
1345
1247
class SampleTestCase(tests.TestCase):
1813
1848
test_suite_factory=factory)
1814
1849
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])
1852
"""A test suite factory."""
1853
class Test(tests.TestCase):
1860
return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")])
1862
def test_list_only(self):
1863
output = self.run_selftest(test_suite_factory=self.factory,
1865
self.assertEqual(3, len(output.readlines()))
1867
def test_list_only_filtered(self):
1868
output = self.run_selftest(test_suite_factory=self.factory,
1869
list_only=True, pattern="Test.b")
1870
self.assertEndsWith(output.getvalue(), "Test.b\n")
1871
self.assertLength(1, output.readlines())
1873
def test_list_only_excludes(self):
1874
output = self.run_selftest(test_suite_factory=self.factory,
1875
list_only=True, exclude_pattern="Test.b")
1876
self.assertNotContainsRe("Test.b", output.getvalue())
1877
self.assertLength(2, output.readlines())
1879
def test_lsprof_tests(self):
1880
self.requireFeature(test_lsprof.LSProfFeature)
1883
def __call__(test, result):
1885
def run(test, result):
1886
self.assertIsInstance(result, tests.ForwardingResult)
1887
calls.append("called")
1888
def countTestCases(self):
1890
self.run_selftest(test_suite_factory=Test, lsprof_tests=True)
1891
self.assertLength(1, calls)
1893
def test_random(self):
1894
# test randomising by listing a number of tests.
1895
output_123 = self.run_selftest(test_suite_factory=self.factory,
1896
list_only=True, random_seed="123")
1897
output_234 = self.run_selftest(test_suite_factory=self.factory,
1898
list_only=True, random_seed="234")
1899
self.assertNotEqual(output_123, output_234)
1900
# "Randominzing test order..\n\n
1901
self.assertLength(5, output_123.readlines())
1902
self.assertLength(5, output_234.readlines())
1904
def test_random_reuse_is_same_order(self):
1905
# test randomising by listing a number of tests.
1906
expected = self.run_selftest(test_suite_factory=self.factory,
1907
list_only=True, random_seed="123")
1908
repeated = self.run_selftest(test_suite_factory=self.factory,
1909
list_only=True, random_seed="123")
1910
self.assertEqual(expected.getvalue(), repeated.getvalue())
1912
def test_runner_class(self):
1913
self.requireFeature(features.subunit)
1914
from subunit import ProtocolTestCase
1915
stream = self.run_selftest(runner_class=tests.SubUnitBzrRunner,
1916
test_suite_factory=self.factory)
1917
test = ProtocolTestCase(stream)
1918
result = unittest.TestResult()
1920
self.assertEqual(3, result.testsRun)
1922
def test_starting_with_single_argument(self):
1923
output = self.run_selftest(test_suite_factory=self.factory,
1924
starting_with=['bzrlib.tests.test_selftest.Test.a'],
1926
self.assertEqual('bzrlib.tests.test_selftest.Test.a\n',
1929
def test_starting_with_multiple_argument(self):
1930
output = self.run_selftest(test_suite_factory=self.factory,
1931
starting_with=['bzrlib.tests.test_selftest.Test.a',
1932
'bzrlib.tests.test_selftest.Test.b'],
1934
self.assertEqual('bzrlib.tests.test_selftest.Test.a\n'
1935
'bzrlib.tests.test_selftest.Test.b\n',
1938
def check_transport_set(self, transport_server):
1939
captured_transport = []
1940
def seen_transport(a_transport):
1941
captured_transport.append(a_transport)
1942
class Capture(tests.TestCase):
1944
seen_transport(bzrlib.tests.default_transport)
1946
return TestUtil.TestSuite([Capture("a")])
1947
self.run_selftest(transport=transport_server, test_suite_factory=factory)
1948
self.assertEqual(transport_server, captured_transport[0])
1950
def test_transport_sftp(self):
1951
self.requireFeature(features.paramiko)
1952
self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1954
def test_transport_memory(self):
1955
self.check_transport_set(bzrlib.transport.memory.MemoryServer)
1958
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
1959
# Does IO: reads test.list
1961
def test_load_list(self):
1962
# Provide a list with one test - this test.
1963
test_id_line = '%s\n' % self.id()
1964
self.build_tree_contents([('test.list', test_id_line)])
1965
# And generate a list of the tests in the suite.
1966
stream = self.run_selftest(load_list='test.list', list_only=True)
1967
self.assertEqual(test_id_line, stream.getvalue())
1969
def test_load_unknown(self):
1970
# Provide a list with one test - this test.
1971
# And generate a list of the tests in the suite.
1972
err = self.assertRaises(errors.NoSuchFile, self.run_selftest,
1973
load_list='missing file name', list_only=True)
1976
class TestRunBzr(tests.TestCase):
1981
def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,
1983
"""Override _run_bzr_core to test how it is invoked by run_bzr.
1985
Attempts to run bzr from inside this class don't actually run it.
1987
We test how run_bzr actually invokes bzr in another location. Here we
1988
only need to test that it passes the right parameters to run_bzr.
1990
self.argv = list(argv)
1991
self.retcode = retcode
1992
self.encoding = encoding
1994
self.working_dir = working_dir
1995
return self.retcode, self.out, self.err
1997
def test_run_bzr_error(self):
1998
self.out = "It sure does!\n"
1999
out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=34)
2000
self.assertEqual(['rocks'], self.argv)
2001
self.assertEqual(34, self.retcode)
2002
self.assertEqual('It sure does!\n', out)
2003
self.assertEquals(out, self.out)
2004
self.assertEqual('', err)
2005
self.assertEquals(err, self.err)
2007
def test_run_bzr_error_regexes(self):
2009
self.err = "bzr: ERROR: foobarbaz is not versioned"
2010
out, err = self.run_bzr_error(
2011
["bzr: ERROR: foobarbaz is not versioned"],
2012
['file-id', 'foobarbaz'])
2014
def test_encoding(self):
2015
"""Test that run_bzr passes encoding to _run_bzr_core"""
2016
self.run_bzr('foo bar')
2017
self.assertEqual(None, self.encoding)
2018
self.assertEqual(['foo', 'bar'], self.argv)
2020
self.run_bzr('foo bar', encoding='baz')
2021
self.assertEqual('baz', self.encoding)
2022
self.assertEqual(['foo', 'bar'], self.argv)
2024
def test_retcode(self):
2025
"""Test that run_bzr passes retcode to _run_bzr_core"""
2026
# Default is retcode == 0
2027
self.run_bzr('foo bar')
2028
self.assertEqual(0, self.retcode)
2029
self.assertEqual(['foo', 'bar'], self.argv)
2031
self.run_bzr('foo bar', retcode=1)
2032
self.assertEqual(1, self.retcode)
2033
self.assertEqual(['foo', 'bar'], self.argv)
2035
self.run_bzr('foo bar', retcode=None)
2036
self.assertEqual(None, self.retcode)
2037
self.assertEqual(['foo', 'bar'], self.argv)
2039
self.run_bzr(['foo', 'bar'], retcode=3)
2040
self.assertEqual(3, self.retcode)
2041
self.assertEqual(['foo', 'bar'], self.argv)
2043
def test_stdin(self):
2044
# test that the stdin keyword to run_bzr is passed through to
2045
# _run_bzr_core as-is. We do this by overriding
2046
# _run_bzr_core in this class, and then calling run_bzr,
2047
# which is a convenience function for _run_bzr_core, so
2049
self.run_bzr('foo bar', stdin='gam')
2050
self.assertEqual('gam', self.stdin)
2051
self.assertEqual(['foo', 'bar'], self.argv)
2053
self.run_bzr('foo bar', stdin='zippy')
2054
self.assertEqual('zippy', self.stdin)
2055
self.assertEqual(['foo', 'bar'], self.argv)
2057
def test_working_dir(self):
2058
"""Test that run_bzr passes working_dir to _run_bzr_core"""
2059
self.run_bzr('foo bar')
2060
self.assertEqual(None, self.working_dir)
2061
self.assertEqual(['foo', 'bar'], self.argv)
2063
self.run_bzr('foo bar', working_dir='baz')
2064
self.assertEqual('baz', self.working_dir)
2065
self.assertEqual(['foo', 'bar'], self.argv)
2067
def test_reject_extra_keyword_arguments(self):
2068
self.assertRaises(TypeError, self.run_bzr, "foo bar",
2069
error_regex=['error message'])
2072
class TestRunBzrCaptured(tests.TestCaseWithTransport):
2073
# Does IO when testing the working_dir parameter.
2075
def apply_redirected(self, stdin=None, stdout=None, stderr=None,
2076
a_callable=None, *args, **kwargs):
2078
self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
2079
self.factory = bzrlib.ui.ui_factory
2080
self.working_dir = osutils.getcwd()
2081
stdout.write('foo\n')
2082
stderr.write('bar\n')
2085
def test_stdin(self):
2086
# test that the stdin keyword to _run_bzr_core is passed through to
2087
# apply_redirected as a StringIO. We do this by overriding
2088
# apply_redirected in this class, and then calling _run_bzr_core,
2089
# which calls apply_redirected.
2090
self.run_bzr(['foo', 'bar'], stdin='gam')
2091
self.assertEqual('gam', self.stdin.read())
2092
self.assertTrue(self.stdin is self.factory_stdin)
2093
self.run_bzr(['foo', 'bar'], stdin='zippy')
2094
self.assertEqual('zippy', self.stdin.read())
2095
self.assertTrue(self.stdin is self.factory_stdin)
2097
def test_ui_factory(self):
2098
# each invocation of self.run_bzr should get its
2099
# own UI factory, which is an instance of TestUIFactory,
2100
# with stdin, stdout and stderr attached to the stdin,
2101
# stdout and stderr of the invoked run_bzr
2102
current_factory = bzrlib.ui.ui_factory
2103
self.run_bzr(['foo'])
2104
self.failIf(current_factory is self.factory)
2105
self.assertNotEqual(sys.stdout, self.factory.stdout)
2106
self.assertNotEqual(sys.stderr, self.factory.stderr)
2107
self.assertEqual('foo\n', self.factory.stdout.getvalue())
2108
self.assertEqual('bar\n', self.factory.stderr.getvalue())
2109
self.assertIsInstance(self.factory, tests.TestUIFactory)
2111
def test_working_dir(self):
2112
self.build_tree(['one/', 'two/'])
2113
cwd = osutils.getcwd()
2115
# Default is to work in the current directory
2116
self.run_bzr(['foo', 'bar'])
2117
self.assertEqual(cwd, self.working_dir)
2119
self.run_bzr(['foo', 'bar'], working_dir=None)
2120
self.assertEqual(cwd, self.working_dir)
2122
# The function should be run in the alternative directory
2123
# but afterwards the current working dir shouldn't be changed
2124
self.run_bzr(['foo', 'bar'], working_dir='one')
2125
self.assertNotEqual(cwd, self.working_dir)
2126
self.assertEndsWith(self.working_dir, 'one')
2127
self.assertEqual(cwd, osutils.getcwd())
2129
self.run_bzr(['foo', 'bar'], working_dir='two')
2130
self.assertNotEqual(cwd, self.working_dir)
2131
self.assertEndsWith(self.working_dir, 'two')
2132
self.assertEqual(cwd, osutils.getcwd())
2135
class StubProcess(object):
2136
"""A stub process for testing run_bzr_subprocess."""
2138
def __init__(self, out="", err="", retcode=0):
2141
self.returncode = retcode
2143
def communicate(self):
2144
return self.out, self.err
2147
class TestWithFakedStartBzrSubprocess(tests.TestCaseWithTransport):
2148
"""Base class for tests testing how we might run bzr."""
2151
tests.TestCaseWithTransport.setUp(self)
2152
self.subprocess_calls = []
2154
def start_bzr_subprocess(self, process_args, env_changes=None,
2155
skip_if_plan_to_signal=False,
2157
allow_plugins=False):
2158
"""capture what run_bzr_subprocess tries to do."""
2159
self.subprocess_calls.append({'process_args':process_args,
2160
'env_changes':env_changes,
2161
'skip_if_plan_to_signal':skip_if_plan_to_signal,
2162
'working_dir':working_dir, 'allow_plugins':allow_plugins})
2163
return self.next_subprocess
2166
class TestRunBzrSubprocess(TestWithFakedStartBzrSubprocess):
2168
def assertRunBzrSubprocess(self, expected_args, process, *args, **kwargs):
2169
"""Run run_bzr_subprocess with args and kwargs using a stubbed process.
2171
Inside TestRunBzrSubprocessCommands we use a stub start_bzr_subprocess
2172
that will return static results. This assertion method populates those
2173
results and also checks the arguments run_bzr_subprocess generates.
2175
self.next_subprocess = process
2177
result = self.run_bzr_subprocess(*args, **kwargs)
2179
self.next_subprocess = None
2180
for key, expected in expected_args.iteritems():
2181
self.assertEqual(expected, self.subprocess_calls[-1][key])
1836
self.fail('Assertion not raised')
2184
self.next_subprocess = None
2185
for key, expected in expected_args.iteritems():
2186
self.assertEqual(expected, self.subprocess_calls[-1][key])
2189
def test_run_bzr_subprocess(self):
2190
"""The run_bzr_helper_external command behaves nicely."""
2191
self.assertRunBzrSubprocess({'process_args':['--version']},
2192
StubProcess(), '--version')
2193
self.assertRunBzrSubprocess({'process_args':['--version']},
2194
StubProcess(), ['--version'])
2195
# retcode=None disables retcode checking
2196
result = self.assertRunBzrSubprocess({},
2197
StubProcess(retcode=3), '--version', retcode=None)
2198
result = self.assertRunBzrSubprocess({},
2199
StubProcess(out="is free software"), '--version')
2200
self.assertContainsRe(result[0], 'is free software')
2201
# Running a subcommand that is missing errors
2202
self.assertRaises(AssertionError, self.assertRunBzrSubprocess,
2203
{'process_args':['--versionn']}, StubProcess(retcode=3),
2205
# Unless it is told to expect the error from the subprocess
2206
result = self.assertRunBzrSubprocess({},
2207
StubProcess(retcode=3), '--versionn', retcode=3)
2208
# Or to ignore retcode checking
2209
result = self.assertRunBzrSubprocess({},
2210
StubProcess(err="unknown command", retcode=3), '--versionn',
2212
self.assertContainsRe(result[1], 'unknown command')
2214
def test_env_change_passes_through(self):
2215
self.assertRunBzrSubprocess(
2216
{'env_changes':{'new':'value', 'changed':'newvalue', 'deleted':None}},
2218
env_changes={'new':'value', 'changed':'newvalue', 'deleted':None})
2220
def test_no_working_dir_passed_as_None(self):
2221
self.assertRunBzrSubprocess({'working_dir': None}, StubProcess(), '')
2223
def test_no_working_dir_passed_through(self):
2224
self.assertRunBzrSubprocess({'working_dir': 'dir'}, StubProcess(), '',
2227
def test_run_bzr_subprocess_no_plugins(self):
2228
self.assertRunBzrSubprocess({'allow_plugins': False},
2231
def test_allow_plugins(self):
2232
self.assertRunBzrSubprocess({'allow_plugins': True},
2233
StubProcess(), '', allow_plugins=True)
2236
class TestFinishBzrSubprocess(TestWithFakedStartBzrSubprocess):
2238
def test_finish_bzr_subprocess_with_error(self):
2239
"""finish_bzr_subprocess allows specification of the desired exit code.
2241
process = StubProcess(err="unknown command", retcode=3)
2242
result = self.finish_bzr_subprocess(process, retcode=3)
2243
self.assertEqual('', result[0])
2244
self.assertContainsRe(result[1], 'unknown command')
2246
def test_finish_bzr_subprocess_ignoring_retcode(self):
2247
"""finish_bzr_subprocess allows the exit code to be ignored."""
2248
process = StubProcess(err="unknown command", retcode=3)
2249
result = self.finish_bzr_subprocess(process, retcode=None)
2250
self.assertEqual('', result[0])
2251
self.assertContainsRe(result[1], 'unknown command')
2253
def test_finish_subprocess_with_unexpected_retcode(self):
2254
"""finish_bzr_subprocess raises self.failureException if the retcode is
2255
not the expected one.
2257
process = StubProcess(err="unknown command", retcode=3)
2258
self.assertRaises(self.failureException, self.finish_bzr_subprocess,
2262
class _DontSpawnProcess(Exception):
2263
"""A simple exception which just allows us to skip unnecessary steps"""
2266
class TestStartBzrSubProcess(tests.TestCase):
2268
def check_popen_state(self):
2269
"""Replace to make assertions when popen is called."""
2271
def _popen(self, *args, **kwargs):
2272
"""Record the command that is run, so that we can ensure it is correct"""
2273
self.check_popen_state()
2274
self._popen_args = args
2275
self._popen_kwargs = kwargs
2276
raise _DontSpawnProcess()
2278
def test_run_bzr_subprocess_no_plugins(self):
2279
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [])
2280
command = self._popen_args[0]
2281
self.assertEqual(sys.executable, command[0])
2282
self.assertEqual(self.get_bzr_path(), command[1])
2283
self.assertEqual(['--no-plugins'], command[2:])
2285
def test_allow_plugins(self):
2286
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2288
command = self._popen_args[0]
2289
self.assertEqual([], command[2:])
2291
def test_set_env(self):
2292
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2294
def check_environment():
2295
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2296
self.check_popen_state = check_environment
2297
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2298
env_changes={'EXISTANT_ENV_VAR':'set variable'})
2299
# not set in theparent
2300
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2302
def test_run_bzr_subprocess_env_del(self):
2303
"""run_bzr_subprocess can remove environment variables too."""
2304
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2305
def check_environment():
2306
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2307
os.environ['EXISTANT_ENV_VAR'] = 'set variable'
2308
self.check_popen_state = check_environment
2309
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2310
env_changes={'EXISTANT_ENV_VAR':None})
2311
# Still set in parent
2312
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2313
del os.environ['EXISTANT_ENV_VAR']
2315
def test_env_del_missing(self):
2316
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ)
2317
def check_environment():
2318
self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
2319
self.check_popen_state = check_environment
2320
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2321
env_changes={'NON_EXISTANT_ENV_VAR':None})
2323
def test_working_dir(self):
2324
"""Test that we can specify the working dir for the child"""
2325
orig_getcwd = osutils.getcwd
2326
orig_chdir = os.chdir
2334
osutils.getcwd = getcwd
2336
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2339
osutils.getcwd = orig_getcwd
2341
os.chdir = orig_chdir
2342
self.assertEqual(['foo', 'current'], chdirs)
2345
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2346
"""Tests that really need to do things with an external bzr."""
2348
def test_start_and_stop_bzr_subprocess_send_signal(self):
2349
"""finish_bzr_subprocess raises self.failureException if the retcode is
2350
not the expected one.
2352
self.disable_missing_extensions_warning()
2353
process = self.start_bzr_subprocess(['wait-until-signalled'],
2354
skip_if_plan_to_signal=True)
2355
self.assertEqual('running\n', process.stdout.readline())
2356
result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT,
2358
self.assertEqual('', result[0])
2359
self.assertEqual('bzr: interrupted\n', result[1])
1839
2362
class TestFeature(tests.TestCase):