2507
2508
class TestStartBzrSubProcess(tests.TestCase):
2509
"""Stub test start_bzr_subprocess."""
2509
def check_popen_state(self):
2510
"""Replace to make assertions when popen is called."""
2511
def _subprocess_log_cleanup(self):
2512
"""Inhibits the base version as we don't produce a log file."""
2512
2514
def _popen(self, *args, **kwargs):
2513
"""Record the command that is run, so that we can ensure it is correct"""
2515
"""Override the base version to record the command that is run.
2517
From there we can ensure it is correct without spawning a real process.
2514
2519
self.check_popen_state()
2515
2520
self._popen_args = args
2516
2521
self._popen_kwargs = kwargs
2517
2522
raise _DontSpawnProcess()
2524
def check_popen_state(self):
2525
"""Replace to make assertions when popen is called."""
2519
2527
def test_run_bzr_subprocess_no_plugins(self):
2520
2528
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [])
2521
2529
command = self._popen_args[0]
2526
2534
def test_allow_plugins(self):
2527
2535
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2529
2537
command = self._popen_args[0]
2530
2538
self.assertEqual([], command[2:])
2536
2544
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2537
2545
self.check_popen_state = check_environment
2538
2546
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2539
env_changes={'EXISTANT_ENV_VAR':'set variable'})
2547
env_changes={'EXISTANT_ENV_VAR':'set variable'})
2540
2548
# not set in theparent
2541
2549
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2548
2556
os.environ['EXISTANT_ENV_VAR'] = 'set variable'
2549
2557
self.check_popen_state = check_environment
2550
2558
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2551
env_changes={'EXISTANT_ENV_VAR':None})
2559
env_changes={'EXISTANT_ENV_VAR':None})
2552
2560
# Still set in parent
2553
2561
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2554
2562
del os.environ['EXISTANT_ENV_VAR']
2559
2567
self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
2560
2568
self.check_popen_state = check_environment
2561
2569
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2562
env_changes={'NON_EXISTANT_ENV_VAR':None})
2570
env_changes={'NON_EXISTANT_ENV_VAR':None})
2564
2572
def test_working_dir(self):
2565
2573
"""Test that we can specify the working dir for the child"""
2569
2577
def chdir(path):
2570
2578
chdirs.append(path)
2575
osutils.getcwd = getcwd
2577
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2580
osutils.getcwd = orig_getcwd
2582
os.chdir = orig_chdir
2579
self.overrideAttr(os, 'chdir', chdir)
2582
self.overrideAttr(osutils, 'getcwd', getcwd)
2583
self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
2583
2585
self.assertEqual(['foo', 'current'], chdirs)
2585
2587
def test_get_bzr_path_with_cwd_bzrlib(self):
3560
3562
def test_mutiple_excludes(self):
3561
3563
self.assertTestList(['c'], '-x', 'a', '-x', 'b')
3566
class TestCounterHooks(tests.TestCase, SelfTestHelper):
3568
_test_needs_features = [features.subunit]
3571
super(TestCounterHooks, self).setUp()
3572
class Test(tests.TestCase):
3575
super(Test, self).setUp()
3576
self.hooks = hooks.Hooks()
3577
self.hooks.add_hook('myhook', 'Foo bar blah', (2,4))
3578
self.install_counter_hook(self.hooks, 'myhook')
3583
def run_hook_once(self):
3584
for hook in self.hooks['myhook']:
3587
self.test_class = Test
3589
def assertHookCalls(self, expected_calls, test_name):
3590
test = self.test_class(test_name)
3591
result = unittest.TestResult()
3593
self.assertTrue(hasattr(test, '_counters'))
3594
self.assertTrue(test._counters.has_key('myhook'))
3595
self.assertEquals(expected_calls, test._counters['myhook'])
3597
def test_no_hook(self):
3598
self.assertHookCalls(0, 'no_hook')
3600
def test_run_hook_once(self):
3601
tt = features.testtools
3602
if tt.module.__version__ < (0, 9, 8):
3603
raise tests.TestSkipped('testtools-0.9.8 required for addDetail')
3604
self.assertHookCalls(1, 'run_hook_once')