~gary/tarmac/fix693595

« back to all changes in this revision

Viewing changes to tarmac/tests/test_commands.py

  • Committer: Gary Poster
  • Date: 2010-12-23 18:28:32 UTC
  • Revision ID: gary.poster@canonical.com-20101223182832-t8fiby7u45rjo3be
fix bug 693595 by making commit plugins able to cancel a merge.  Correct some logic errors along the way, revealed by this work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
383
383
        self.install_plugin(plugin, hook_name)
384
384
        return plugin
385
385
 
 
386
    def install_recorder_plugin(self, hook_name):
 
387
        class RecorderPlugin(TarmacPlugin):
 
388
            calls = []
 
389
 
 
390
            def run(self, *args):
 
391
                self.__class__.calls.append(args)
 
392
 
 
393
        plugin = RecorderPlugin()
 
394
        self.install_plugin(plugin, hook_name)
 
395
        return plugin
 
396
 
386
397
    def install_plugin(self, plugin, hook_name):
387
398
        '''Install a plugin at the given hookpoint name.
388
399
 
434
445
    def test_plugin_merge_errors_are_handled(self):
435
446
        # Setup
436
447
        self.approve_all_proposals()
437
 
        plugin = self.install_merge_error_injecting_plugin('tarmac_pre_commit')
 
448
        pre_commit_plugin = self.install_merge_error_injecting_plugin(
 
449
            'tarmac_pre_commit')
 
450
        bundle_merge_plugin = self.install_recorder_plugin(
 
451
            'tarmac_bundle_merge')
438
452
 
439
453
        # Act
440
454
        self.command.run(launchpad=self.launchpad)
441
455
 
442
456
        # Verify
443
 
        self.assertTrue(plugin.has_run)
 
457
        self.assertTrue(pre_commit_plugin.has_run)
444
458
        self.assertIsInstance(self.error, TarmacMergeError)
445
 
        self.assertEqual(self.error.comment, plugin.long_message)
 
459
        self.assertEqual(self.error.comment, pre_commit_plugin.long_message)
 
460
        # No commits were accepted, so we should have aborted the merge,
 
461
        # and not called the merge hook (which would usually run tests).
 
462
        self.assertEqual(bundle_merge_plugin.calls, [])
 
463
 
446
464
 
447
465
# XXX matsubara 2010-12-17: Test commented out because we're not handling
448
466
# errors in the command itself but in the plugin. This is a temporary hack
461
479
#        self.assertIsInstance(self.error, TarmacMergeError)
462
480
#        self.assertEqual(self.error.comment, plugin.long_message)
463
481
#
 
482
 
 
483
 
 
484
# This is a debug helper.
 
485
# nosetests eat stdout.  This is a way to work around it.  Use like this:
 
486
# with pdb():
 
487
#     ...stuff you want to pdb through...
 
488
from contextlib import contextmanager
 
489
@contextmanager
 
490
def pdb():
 
491
    import pdb, sys
 
492
    test_stdout = sys.stdout
 
493
    sys.stdout = sys.__stdout__
 
494
    import pdb; pdb.set_trace()
 
495
    try:
 
496
        yield
 
497
    finally:
 
498
        sys.stdout = test_stdout