1212
1224
result = self.run_test_runner(runner, test)
1213
1225
output_string = output.getvalue()
1214
1226
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)
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)
1246
1345
class SampleTestCase(tests.TestCase):
1846
1813
test_suite_factory=factory)
1847
1814
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
from bzrlib.tests import stub_sftp
1951
self.check_transport_set(stub_sftp.SFTPAbsoluteServer)
1953
def test_transport_memory(self):
1954
self.check_transport_set(memory.MemoryServer)
1957
class TestSelftestWithIdList(tests.TestCaseInTempDir, SelfTestHelper):
1958
# Does IO: reads test.list
1960
def test_load_list(self):
1961
# Provide a list with one test - this test.
1962
test_id_line = '%s\n' % self.id()
1963
self.build_tree_contents([('test.list', test_id_line)])
1964
# And generate a list of the tests in the suite.
1965
stream = self.run_selftest(load_list='test.list', list_only=True)
1966
self.assertEqual(test_id_line, stream.getvalue())
1968
def test_load_unknown(self):
1969
# Provide a list with one test - this test.
1970
# And generate a list of the tests in the suite.
1971
err = self.assertRaises(errors.NoSuchFile, self.run_selftest,
1972
load_list='missing file name', list_only=True)
1975
class TestRunBzr(tests.TestCase):
1980
def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,
1982
"""Override _run_bzr_core to test how it is invoked by run_bzr.
1984
Attempts to run bzr from inside this class don't actually run it.
1986
We test how run_bzr actually invokes bzr in another location. Here we
1987
only need to test that it passes the right parameters to run_bzr.
1989
self.argv = list(argv)
1990
self.retcode = retcode
1991
self.encoding = encoding
1993
self.working_dir = working_dir
1994
return self.retcode, self.out, self.err
1996
def test_run_bzr_error(self):
1997
self.out = "It sure does!\n"
1998
out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=34)
1999
self.assertEqual(['rocks'], self.argv)
2000
self.assertEqual(34, self.retcode)
2001
self.assertEqual('It sure does!\n', out)
2002
self.assertEquals(out, self.out)
2003
self.assertEqual('', err)
2004
self.assertEquals(err, self.err)
2006
def test_run_bzr_error_regexes(self):
2008
self.err = "bzr: ERROR: foobarbaz is not versioned"
2009
out, err = self.run_bzr_error(
2010
["bzr: ERROR: foobarbaz is not versioned"],
2011
['file-id', 'foobarbaz'])
2013
def test_encoding(self):
2014
"""Test that run_bzr passes encoding to _run_bzr_core"""
2015
self.run_bzr('foo bar')
2016
self.assertEqual(None, self.encoding)
2017
self.assertEqual(['foo', 'bar'], self.argv)
2019
self.run_bzr('foo bar', encoding='baz')
2020
self.assertEqual('baz', self.encoding)
2021
self.assertEqual(['foo', 'bar'], self.argv)
2023
def test_retcode(self):
2024
"""Test that run_bzr passes retcode to _run_bzr_core"""
2025
# Default is retcode == 0
2026
self.run_bzr('foo bar')
2027
self.assertEqual(0, self.retcode)
2028
self.assertEqual(['foo', 'bar'], self.argv)
2030
self.run_bzr('foo bar', retcode=1)
2031
self.assertEqual(1, self.retcode)
2032
self.assertEqual(['foo', 'bar'], self.argv)
2034
self.run_bzr('foo bar', retcode=None)
2035
self.assertEqual(None, self.retcode)
2036
self.assertEqual(['foo', 'bar'], self.argv)
2038
self.run_bzr(['foo', 'bar'], retcode=3)
2039
self.assertEqual(3, self.retcode)
2040
self.assertEqual(['foo', 'bar'], self.argv)
2042
def test_stdin(self):
2043
# test that the stdin keyword to run_bzr is passed through to
2044
# _run_bzr_core as-is. We do this by overriding
2045
# _run_bzr_core in this class, and then calling run_bzr,
2046
# which is a convenience function for _run_bzr_core, so
2048
self.run_bzr('foo bar', stdin='gam')
2049
self.assertEqual('gam', self.stdin)
2050
self.assertEqual(['foo', 'bar'], self.argv)
2052
self.run_bzr('foo bar', stdin='zippy')
2053
self.assertEqual('zippy', self.stdin)
2054
self.assertEqual(['foo', 'bar'], self.argv)
2056
def test_working_dir(self):
2057
"""Test that run_bzr passes working_dir to _run_bzr_core"""
2058
self.run_bzr('foo bar')
2059
self.assertEqual(None, self.working_dir)
2060
self.assertEqual(['foo', 'bar'], self.argv)
2062
self.run_bzr('foo bar', working_dir='baz')
2063
self.assertEqual('baz', self.working_dir)
2064
self.assertEqual(['foo', 'bar'], self.argv)
2066
def test_reject_extra_keyword_arguments(self):
2067
self.assertRaises(TypeError, self.run_bzr, "foo bar",
2068
error_regex=['error message'])
2071
class TestRunBzrCaptured(tests.TestCaseWithTransport):
2072
# Does IO when testing the working_dir parameter.
2074
def apply_redirected(self, stdin=None, stdout=None, stderr=None,
2075
a_callable=None, *args, **kwargs):
2077
self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
2078
self.factory = bzrlib.ui.ui_factory
2079
self.working_dir = osutils.getcwd()
2080
stdout.write('foo\n')
2081
stderr.write('bar\n')
2084
def test_stdin(self):
2085
# test that the stdin keyword to _run_bzr_core is passed through to
2086
# apply_redirected as a StringIO. We do this by overriding
2087
# apply_redirected in this class, and then calling _run_bzr_core,
2088
# which calls apply_redirected.
2089
self.run_bzr(['foo', 'bar'], stdin='gam')
2090
self.assertEqual('gam', self.stdin.read())
2091
self.assertTrue(self.stdin is self.factory_stdin)
2092
self.run_bzr(['foo', 'bar'], stdin='zippy')
2093
self.assertEqual('zippy', self.stdin.read())
2094
self.assertTrue(self.stdin is self.factory_stdin)
2096
def test_ui_factory(self):
2097
# each invocation of self.run_bzr should get its
2098
# own UI factory, which is an instance of TestUIFactory,
2099
# with stdin, stdout and stderr attached to the stdin,
2100
# stdout and stderr of the invoked run_bzr
2101
current_factory = bzrlib.ui.ui_factory
2102
self.run_bzr(['foo'])
2103
self.failIf(current_factory is self.factory)
2104
self.assertNotEqual(sys.stdout, self.factory.stdout)
2105
self.assertNotEqual(sys.stderr, self.factory.stderr)
2106
self.assertEqual('foo\n', self.factory.stdout.getvalue())
2107
self.assertEqual('bar\n', self.factory.stderr.getvalue())
2108
self.assertIsInstance(self.factory, tests.TestUIFactory)
2110
def test_working_dir(self):
2111
self.build_tree(['one/', 'two/'])
2112
cwd = osutils.getcwd()
2114
# Default is to work in the current directory
2115
self.run_bzr(['foo', 'bar'])
2116
self.assertEqual(cwd, self.working_dir)
2118
self.run_bzr(['foo', 'bar'], working_dir=None)
2119
self.assertEqual(cwd, self.working_dir)
2121
# The function should be run in the alternative directory
2122
# but afterwards the current working dir shouldn't be changed
2123
self.run_bzr(['foo', 'bar'], working_dir='one')
2124
self.assertNotEqual(cwd, self.working_dir)
2125
self.assertEndsWith(self.working_dir, 'one')
2126
self.assertEqual(cwd, osutils.getcwd())
2128
self.run_bzr(['foo', 'bar'], working_dir='two')
2129
self.assertNotEqual(cwd, self.working_dir)
2130
self.assertEndsWith(self.working_dir, 'two')
2131
self.assertEqual(cwd, osutils.getcwd())
2134
class StubProcess(object):
2135
"""A stub process for testing run_bzr_subprocess."""
2137
def __init__(self, out="", err="", retcode=0):
2140
self.returncode = retcode
2142
def communicate(self):
2143
return self.out, self.err
2146
class TestWithFakedStartBzrSubprocess(tests.TestCaseWithTransport):
2147
"""Base class for tests testing how we might run bzr."""
2150
tests.TestCaseWithTransport.setUp(self)
2151
self.subprocess_calls = []
2153
def start_bzr_subprocess(self, process_args, env_changes=None,
2154
skip_if_plan_to_signal=False,
2156
allow_plugins=False):
2157
"""capture what run_bzr_subprocess tries to do."""
2158
self.subprocess_calls.append({'process_args':process_args,
2159
'env_changes':env_changes,
2160
'skip_if_plan_to_signal':skip_if_plan_to_signal,
2161
'working_dir':working_dir, 'allow_plugins':allow_plugins})
2162
return self.next_subprocess
2165
class TestRunBzrSubprocess(TestWithFakedStartBzrSubprocess):
2167
def assertRunBzrSubprocess(self, expected_args, process, *args, **kwargs):
2168
"""Run run_bzr_subprocess with args and kwargs using a stubbed process.
2170
Inside TestRunBzrSubprocessCommands we use a stub start_bzr_subprocess
2171
that will return static results. This assertion method populates those
2172
results and also checks the arguments run_bzr_subprocess generates.
2174
self.next_subprocess = process
2176
result = self.run_bzr_subprocess(*args, **kwargs)
2178
self.next_subprocess = None
2179
for key, expected in expected_args.iteritems():
2180
self.assertEqual(expected, self.subprocess_calls[-1][key])
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])
2183
self.next_subprocess = None
2184
for key, expected in expected_args.iteritems():
2185
self.assertEqual(expected, self.subprocess_calls[-1][key])
2188
def test_run_bzr_subprocess(self):
2189
"""The run_bzr_helper_external command behaves nicely."""
2190
self.assertRunBzrSubprocess({'process_args':['--version']},
2191
StubProcess(), '--version')
2192
self.assertRunBzrSubprocess({'process_args':['--version']},
2193
StubProcess(), ['--version'])
2194
# retcode=None disables retcode checking
2195
result = self.assertRunBzrSubprocess({},
2196
StubProcess(retcode=3), '--version', retcode=None)
2197
result = self.assertRunBzrSubprocess({},
2198
StubProcess(out="is free software"), '--version')
2199
self.assertContainsRe(result[0], 'is free software')
2200
# Running a subcommand that is missing errors
2201
self.assertRaises(AssertionError, self.assertRunBzrSubprocess,
2202
{'process_args':['--versionn']}, StubProcess(retcode=3),
2204
# Unless it is told to expect the error from the subprocess
2205
result = self.assertRunBzrSubprocess({},
2206
StubProcess(retcode=3), '--versionn', retcode=3)
2207
# Or to ignore retcode checking
2208
result = self.assertRunBzrSubprocess({},
2209
StubProcess(err="unknown command", retcode=3), '--versionn',
2211
self.assertContainsRe(result[1], 'unknown command')
2213
def test_env_change_passes_through(self):
2214
self.assertRunBzrSubprocess(
2215
{'env_changes':{'new':'value', 'changed':'newvalue', 'deleted':None}},
2217
env_changes={'new':'value', 'changed':'newvalue', 'deleted':None})
2219
def test_no_working_dir_passed_as_None(self):
2220
self.assertRunBzrSubprocess({'working_dir': None}, StubProcess(), '')
2222
def test_no_working_dir_passed_through(self):
2223
self.assertRunBzrSubprocess({'working_dir': 'dir'}, StubProcess(), '',
2226
def test_run_bzr_subprocess_no_plugins(self):
2227
self.assertRunBzrSubprocess({'allow_plugins': False},
2230
def test_allow_plugins(self):
2231
self.assertRunBzrSubprocess({'allow_plugins': True},
2232
StubProcess(), '', allow_plugins=True)
2235
class TestFinishBzrSubprocess(TestWithFakedStartBzrSubprocess):
2237
def test_finish_bzr_subprocess_with_error(self):
2238
"""finish_bzr_subprocess allows specification of the desired exit code.
2240
process = StubProcess(err="unknown command", retcode=3)
2241
result = self.finish_bzr_subprocess(process, retcode=3)
2242
self.assertEqual('', result[0])
2243
self.assertContainsRe(result[1], 'unknown command')
2245
def test_finish_bzr_subprocess_ignoring_retcode(self):
2246
"""finish_bzr_subprocess allows the exit code to be ignored."""
2247
process = StubProcess(err="unknown command", retcode=3)
2248
result = self.finish_bzr_subprocess(process, retcode=None)
2249
self.assertEqual('', result[0])
2250
self.assertContainsRe(result[1], 'unknown command')
2252
def test_finish_subprocess_with_unexpected_retcode(self):
2253
"""finish_bzr_subprocess raises self.failureException if the retcode is
2254
not the expected one.
2256
process = StubProcess(err="unknown command", retcode=3)
2257
self.assertRaises(self.failureException, self.finish_bzr_subprocess,
2261
class _DontSpawnProcess(Exception):
2262
"""A simple exception which just allows us to skip unnecessary steps"""
2265
class TestStartBzrSubProcess(tests.TestCase):
2267
def check_popen_state(self):
2268
"""Replace to make assertions when popen is called."""
2270
def _popen(self, *args, **kwargs):
2271
"""Record the command that is run, so that we can ensure it is correct"""
2272
self.check_popen_state()
2273
self._popen_args = args
2274
self._popen_kwargs = kwargs
2275
raise _DontSpawnProcess()
2277
def test_run_bzr_subprocess_no_plugins(self):
2278
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [])
2279
command = self._popen_args[0]
2280
self.assertEqual(sys.executable, command[0])
2281
self.assertEqual(self.get_bzr_path(), command[1])
2282
self.assertEqual(['--no-plugins'], command[2:])
2284
def test_allow_plugins(self):
2285
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2287
command = self._popen_args[0]
2288
self.assertEqual([], command[2:])
2290
def test_set_env(self):
2291
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2293
def check_environment():
2294
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2295
self.check_popen_state = check_environment
2296
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2297
env_changes={'EXISTANT_ENV_VAR':'set variable'})
2298
# not set in theparent
2299
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2301
def test_run_bzr_subprocess_env_del(self):
2302
"""run_bzr_subprocess can remove environment variables too."""
2303
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2304
def check_environment():
2305
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2306
os.environ['EXISTANT_ENV_VAR'] = 'set variable'
2307
self.check_popen_state = check_environment
2308
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2309
env_changes={'EXISTANT_ENV_VAR':None})
2310
# Still set in parent
2311
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2312
del os.environ['EXISTANT_ENV_VAR']
2314
def test_env_del_missing(self):
2315
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ)
2316
def check_environment():
2317
self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
2318
self.check_popen_state = check_environment
2319
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2320
env_changes={'NON_EXISTANT_ENV_VAR':None})
2322
def test_working_dir(self):
2323
"""Test that we can specify the working dir for the child"""
2324
orig_getcwd = osutils.getcwd
2325
orig_chdir = os.chdir
2333
osutils.getcwd = getcwd
2335
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2338
osutils.getcwd = orig_getcwd
2340
os.chdir = orig_chdir
2341
self.assertEqual(['foo', 'current'], chdirs)
2343
def test_get_bzr_path_with_cwd_bzrlib(self):
2344
self.get_source_path = lambda: ""
2345
self.overrideAttr(os.path, "isfile", lambda path: True)
2346
self.assertEqual(self.get_bzr_path(), "bzr")
2349
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2350
"""Tests that really need to do things with an external bzr."""
2352
def test_start_and_stop_bzr_subprocess_send_signal(self):
2353
"""finish_bzr_subprocess raises self.failureException if the retcode is
2354
not the expected one.
2356
self.disable_missing_extensions_warning()
2357
process = self.start_bzr_subprocess(['wait-until-signalled'],
2358
skip_if_plan_to_signal=True)
2359
self.assertEqual('running\n', process.stdout.readline())
2360
result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT,
2362
self.assertEqual('', result[0])
2363
self.assertEqual('bzr: interrupted\n', result[1])
1836
self.fail('Assertion not raised')
2366
1839
class TestFeature(tests.TestCase):