Example #1
0
 def test_silent_ui_getbool(self):
     factory = _mod_ui.SilentUIFactory()
     stdout = tests.StringIOWrapper()
     self.assertRaises(
         NotImplementedError,
         self.apply_redirected,
         None, stdout, stdout, factory.get_boolean, u"foo")
 def test_trace_context(self):
     tracer = fixtures.RecordingContextManager()
     ui = _mod_ui.SilentUIFactory()
     state = library_state.BzrLibraryState(ui=ui, trace=tracer)
     state.__enter__()
     try:
         self.assertEqual(['__enter__'], tracer._calls)
     finally:
         state.__exit__(None, None, None)
         self.assertEqual(['__enter__', '__exit__'], tracer._calls)
Example #3
0
    def prepare_for_break_lock(self):
        # Setup the global ui factory state so that a break-lock method call
        # will find usable input in the input stream.
        old_factory = ui.ui_factory

        def restoreFactory():
            ui.ui_factory = old_factory

        self.addCleanup(restoreFactory)
        ui.ui_factory = ui.SilentUIFactory()
        ui.ui_factory.stdin = StringIO("y\n")
 def test_ui_is_used(self):
     ui = _mod_ui.SilentUIFactory()
     state = library_state.BzrLibraryState(
         ui=ui, trace=fixtures.RecordingContextManager())
     orig_ui = _mod_ui.ui_factory
     state.__enter__()
     try:
         self.assertEqual(ui, _mod_ui.ui_factory)
     finally:
         state.__exit__(None, None, None)
         self.assertEqual(orig_ui, _mod_ui.ui_factory)
Example #5
0
 def test_silent_factory_get_password(self):
     # A silent factory that can't do user interaction can't get a
     # password.  Possibly it should raise a more specific error but it
     # can't succeed.
     ui = _mod_ui.SilentUIFactory()
     stdout = tests.StringIOWrapper()
     self.assertRaises(
         NotImplementedError,
         self.apply_redirected,
         None, stdout, stdout, ui.get_password)
     # and it didn't write anything out either
     self.assertEqual('', stdout.getvalue())
Example #6
0
 def run_server(self, smart_server):
     """Run the given smart server."""
     # for the duration of this server, no UI output is permitted.
     # note that this may cause problems with blackbox tests. This should
     # be changed with care though, as we dont want to use bandwidth
     # sending progress over stderr to smart server clients!
     old_factory = ui.ui_factory
     try:
         ui.ui_factory = ui.SilentUIFactory()
         smart_server.serve()
     finally:
         ui.ui_factory = old_factory
Example #7
0
    def _change_globals(self):
        from bzrlib import lockdir, ui
        # For the duration of this server, no UI output is permitted. note
        # that this may cause problems with blackbox tests. This should be
        # changed with care though, as we dont want to use bandwidth sending
        # progress over stderr to smart server clients!
        old_factory = ui.ui_factory
        old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS

        def restore_default_ui_factory_and_lockdir_timeout():
            ui.ui_factory = old_factory
            lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout

        self.cleanups.append(restore_default_ui_factory_and_lockdir_timeout)
        ui.ui_factory = ui.SilentUIFactory()
        lockdir._DEFAULT_TIMEOUT_SECONDS = 0
        orig = signals.install_sighup_handler()

        def restore_signals():
            signals.restore_sighup_handler(orig)

        self.cleanups.append(restore_signals)
Example #8
0
 def setUp(self):
     super(TestSilentUIFactory, self).setUp()
     self.factory = ui.SilentUIFactory()