~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_script.py

  • Committer: Martin Pool
  • Date: 2010-09-13 04:20:14 UTC
  • mto: (5416.1.7 ui-factory)
  • mto: This revision was merged to the branch mainline in revision 5422.
  • Revision ID: mbp@sourcefrog.net-20100913042014-9ia1c0b2cv8mxpyc
ScriptRunner can now cope with commands that prompt for input.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
from bzrlib import (
 
19
    commands,
19
20
    osutils,
20
21
    tests,
 
22
    ui,
21
23
    )
22
24
from bzrlib.tests import script
23
25
 
459
461
        self.failIfExists('file')
460
462
        self.failUnlessExists('dir/file')
461
463
 
 
464
 
 
465
class cmd_test_confirm(commands.Command):
 
466
 
 
467
    def run(self):
 
468
        if ui.ui_factory.get_boolean(
 
469
            'Really do it',
 
470
            # 'bzrlib.tests.test_script.confirm',
 
471
            # {}
 
472
            ):
 
473
            self.outf.write('yes\n')
 
474
        else:
 
475
            print 'no'
 
476
 
 
477
 
 
478
class TestUserInteraction(script.TestCaseWithMemoryTransportAndScript):
 
479
 
 
480
    def test_confirm_action(self):
 
481
        """You can write tests that demonstrate user confirmation"""
 
482
        commands.builtin_command_registry.register(cmd_test_confirm)
 
483
        self.addCleanup(commands.builtin_command_registry.remove, 'test-confirm')
 
484
        self.run_script("""
 
485
            $ bzr test-confirm
 
486
            2>Really do it? [y/n]: 
 
487
            <yes
 
488
            yes
 
489
            """)
 
490