Rev 4634: Fix imports and various cleanups in test_ui. in file:///home/vila/src/bzr/experimental/conflict-manager/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Oct 26 14:40:07 GMT 2009


At file:///home/vila/src/bzr/experimental/conflict-manager/

------------------------------------------------------------
revno: 4634
revision-id: v.ladeuil+lp at free.fr-20091026144007-5vptd9794mbjdzzc
parent: v.ladeuil+lp at free.fr-20091020144712-8kdhonvi42q7aoos
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: description
timestamp: Mon 2009-10-26 15:40:07 +0100
message:
  Fix imports and various cleanups in test_ui.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py	2009-10-14 08:51:44 +0000
+++ b/bzrlib/tests/test_ui.py	2009-10-26 14:40:07 +0000
@@ -18,9 +18,7 @@
 """
 
 import os
-from StringIO import StringIO
 import re
-import sys
 import time
 
 from bzrlib import (
@@ -31,27 +29,8 @@
 from bzrlib.symbol_versioning import (
     deprecated_in,
     )
-from bzrlib.tests import (
-    TestCase,
-    TestUIFactory,
-    StringIOWrapper,
-    )
-from bzrlib.tests.test_progress import (
-    _NonTTYStringIO,
-    _TTYStringIO,
-    )
-from bzrlib.ui import (
-    CannedInputUIFactory,
-    CLIUIFactory,
-    SilentUIFactory,
-    UIFactory,
-    make_ui_for_terminal,
-    )
-from bzrlib.ui.text import (
-    NullProgressView,
-    TextProgressView,
-    TextUIFactory,
-    )
+from bzrlib.tests import test_progress
+from bzrlib.ui import text as _mod_ui_text
 
 
 class TestTextUIFactory(tests.TestCase):
@@ -101,11 +80,11 @@
             pb.finished()
 
     def test_progress_note(self):
-        stderr = StringIO()
-        stdout = StringIO()
-        ui_factory = TextUIFactory(stdin=StringIO(''),
-            stderr=stderr,
-            stdout=stdout)
+        stderr = tests.StringIOWrapper()
+        stdout = tests.StringIOWrapper()
+        ui_factory = _mod_ui_text.TextUIFactory(stdin=tests.StringIOWrapper(''),
+                                                stderr=stderr,
+                                                stdout=stdout)
         pb = ui_factory.nested_progress_bar()
         try:
             result = self.applyDeprecated(deprecated_in((2, 1, 0)),
@@ -121,15 +100,15 @@
             pb.finished()
 
     def test_progress_note_clears(self):
-        stderr = _TTYStringIO()
-        stdout = _TTYStringIO()
+        stderr = test_progress._TTYStringIO()
+        stdout = test_progress._TTYStringIO()
         # so that we get a TextProgressBar
         os.environ['TERM'] = 'xterm'
-        ui_factory = TextUIFactory(
-            stdin=StringIO(''),
+        ui_factory = _mod_ui_text.TextUIFactory(
+            stdin=tests.StringIOWrapper(''),
             stdout=stdout, stderr=stderr)
         self.assertIsInstance(ui_factory._progress_view,
-            TextProgressView)
+                              _mod_ui_text.TextProgressView)
         pb = ui_factory.nested_progress_bar()
         try:
             # Create a progress update that isn't throttled
@@ -147,7 +126,7 @@
 
     def test_progress_nested(self):
         # test factory based nested and popping.
-        ui = TextUIFactory(None, None, None)
+        ui = _mod_ui_text.TextUIFactory(None, None, None)
         pb1 = ui.nested_progress_bar()
         pb2 = ui.nested_progress_bar()
         # You do get a warning if the outermost progress bar wasn't finished
@@ -160,16 +139,17 @@
         pb1.finished()
 
     def test_text_ui_get_boolean(self):
-        stdin = StringIO("y\n" # True
-                         "n\n" # False
-                         "yes with garbage\nY\n" # True
-                         "not an answer\nno\n" # False
-                         "I'm sure!\nyes\n" # True
-                         "NO\n" # False
-                         "foo\n")
-        stdout = StringIO()
-        stderr = StringIO()
-        factory = TextUIFactory(stdin, stdout, stderr)
+        stdin = tests.StringIOWrapper(
+            "y\n" # True
+            "n\n" # False
+            "yes with garbage\nY\n" # True
+            "not an answer\nno\n" # False
+            "I'm sure!\nyes\n" # True
+            "NO\n" # False
+            "foo\n")
+        stdout = tests.StringIOWrapper()
+        stderr = tests.StringIOWrapper()
+        factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
         self.assertEqual(True, factory.get_boolean(""))
         self.assertEqual(False, factory.get_boolean(""))
         self.assertEqual(True, factory.get_boolean(""))
@@ -182,16 +162,19 @@
 
     def test_text_factory_prompt(self):
         # see <https://launchpad.net/bugs/365891>
-        factory = TextUIFactory(StringIO(), StringIO(), StringIO())
+        StringIO = tests.StringIOWrapper
+        factory = _mod_ui_text.TextUIFactory(StringIO(), StringIO(), StringIO())
         factory.prompt('foo %2e')
         self.assertEqual('', factory.stdout.getvalue())
         self.assertEqual('foo %2e', factory.stderr.getvalue())
 
     def test_text_factory_prompts_and_clears(self):
         # a get_boolean call should clear the pb before prompting
-        out = _TTYStringIO()
+        out = test_progress._TTYStringIO()
         os.environ['TERM'] = 'xterm'
-        factory = TextUIFactory(stdin=StringIO("yada\ny\n"), stdout=out, stderr=out)
+        factory = _mod_ui_text.TextUIFactory(
+            stdin=tests.StringIOWrapper("yada\ny\n"),
+            stdout=out, stderr=out)
         pb = factory.nested_progress_bar()
         pb.show_bar = False
         pb.show_spinner = False
@@ -211,7 +194,8 @@
         self.assertEqual('', factory.stdin.readline())
 
     def test_text_tick_after_update(self):
-        ui_factory = TextUIFactory(stdout=StringIO(), stderr=StringIO())
+        ui_factory = _mod_ui_text.TextUIFactory(stdout=tests.StringIOWrapper(),
+                                                stderr=tests.StringIOWrapper())
         pb = ui_factory.nested_progress_bar()
         try:
             pb.update('task', 0, 3)
@@ -222,10 +206,10 @@
             pb.finished()
 
     def test_text_ui_getusername(self):
-        factory = TextUIFactory(None, None, None)
-        factory.stdin = StringIO("someuser\n\n")
-        factory.stdout = StringIO()
-        factory.stderr = StringIO()
+        factory = _mod_ui_text.TextUIFactory(None, None, None)
+        factory.stdin = tests.StringIOWrapper("someuser\n\n")
+        factory.stdout = tests.StringIOWrapper()
+        factory.stderr = tests.StringIOWrapper()
         factory.stdout.encoding = "utf8"
         # there is no output from the base factory
         self.assertEqual("someuser",
@@ -259,22 +243,24 @@
     def test_progress_construction(self):
         """TextUIFactory constructs the right progress view.
         """
+        TTYStringIO = test_progress._TTYStringIO
+        FileStringIO = tests.StringIOWrapper
         for (file_class, term, pb, expected_pb_class) in (
             # on an xterm, either use them or not as the user requests,
             # otherwise default on
-            (_TTYStringIO, 'xterm', 'none', NullProgressView),
-            (_TTYStringIO, 'xterm', 'text', TextProgressView),
-            (_TTYStringIO, 'xterm', None, TextProgressView),
+            (TTYStringIO, 'xterm', 'none', _mod_ui_text.NullProgressView),
+            (TTYStringIO, 'xterm', 'text', _mod_ui_text.TextProgressView),
+            (TTYStringIO, 'xterm', None, _mod_ui_text.TextProgressView),
             # on a dumb terminal, again if there's explicit configuration do
             # it, otherwise default off
-            (_TTYStringIO, 'dumb', 'none', NullProgressView),
-            (_TTYStringIO, 'dumb', 'text', TextProgressView),
-            (_TTYStringIO, 'dumb', None, NullProgressView),
+            (TTYStringIO, 'dumb', 'none', _mod_ui_text.NullProgressView),
+            (TTYStringIO, 'dumb', 'text', _mod_ui_text.TextProgressView),
+            (TTYStringIO, 'dumb', None, _mod_ui_text.NullProgressView),
             # on a non-tty terminal, it's null regardless of $TERM
-            (StringIO, 'xterm', None, NullProgressView),
-            (StringIO, 'dumb', None, NullProgressView),
+            (FileStringIO, 'xterm', None, _mod_ui_text.NullProgressView),
+            (FileStringIO, 'dumb', None, _mod_ui_text.NullProgressView),
             # however, it can still be forced on
-            (StringIO, 'dumb', 'text', TextProgressView),
+            (FileStringIO, 'dumb', 'text', _mod_ui_text.TextProgressView),
             ):
             os.environ['TERM'] = term
             if pb is None:
@@ -285,8 +271,8 @@
             stdin = file_class('')
             stderr = file_class()
             stdout = file_class()
-            uif = make_ui_for_terminal(stdin, stdout, stderr)
-            self.assertIsInstance(uif, TextUIFactory,
+            uif = _mod_ui.make_ui_for_terminal(stdin, stdout, stderr)
+            self.assertIsInstance(uif, _mod_ui_text.TextUIFactory,
                 "TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
             self.assertIsInstance(uif.make_progress_view(),
                 expected_pb_class,
@@ -294,36 +280,37 @@
 
     def test_text_ui_non_terminal(self):
         """Even on non-ttys, make_ui_for_terminal gives a text ui."""
-        stdin = _NonTTYStringIO('')
-        stderr = _NonTTYStringIO()
-        stdout = _NonTTYStringIO()
+        stdin = test_progress._NonTTYStringIO('')
+        stderr = test_progress._NonTTYStringIO()
+        stdout = test_progress._NonTTYStringIO()
         for term_type in ['dumb', None, 'xterm']:
             if term_type is None:
                 del os.environ['TERM']
             else:
                 os.environ['TERM'] = term_type
-            uif = make_ui_for_terminal(stdin, stdout, stderr)
-            self.assertIsInstance(uif, TextUIFactory,
+            uif = _mod_ui.make_ui_for_terminal(stdin, stdout, stderr)
+            self.assertIsInstance(uif, _mod_ui_text.TextUIFactory,
                 'TERM=%r' % (term_type,))
 
 
-class CLIUITests(TestCase):
+class CLIUITests(tests.TestCase):
 
     def test_cli_factory_deprecated(self):
+        StringIO = tests.StringIOWrapper
         uif = self.applyDeprecated(deprecated_in((1, 18, 0)),
-            CLIUIFactory,
+            _mod_ui.CLIUIFactory,
             StringIO(), StringIO(), StringIO())
-        self.assertIsInstance(uif, UIFactory)
-
-
-class SilentUITests(TestCase):
+        self.assertIsInstance(uif, _mod_ui.UIFactory)
+
+
+class SilentUITests(tests.TestCase):
 
     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 = SilentUIFactory()
-        stdout = StringIO()
+        ui = _mod_ui.SilentUIFactory()
+        stdout = tests.StringIOWrapper()
         self.assertRaises(
             NotImplementedError,
             self.apply_redirected,
@@ -332,34 +319,35 @@
         self.assertEqual('', stdout.getvalue())
 
     def test_silent_ui_getbool(self):
-        factory = SilentUIFactory()
-        stdout = StringIO()
+        factory = _mod_ui.SilentUIFactory()
+        stdout = tests.StringIOWrapper()
         self.assertRaises(
             NotImplementedError,
             self.apply_redirected,
             None, stdout, stdout, factory.get_boolean, "foo")
 
 
-class TestUIFactoryTests(TestCase):
+class TestUIFactoryTests(tests.TestCase):
 
     def test_test_ui_factory_progress(self):
         # there's no output; we just want to make sure this doesn't crash -
         # see https://bugs.edge.launchpad.net/bzr/+bug/408201
-        ui = TestUIFactory()
+        ui = tests.TestUIFactory()
         pb = ui.nested_progress_bar()
         pb.update('hello')
         pb.tick()
         pb.finished()
 
 
-class CannedInputUIFactoryTests(TestCase):
-    
+class CannedInputUIFactoryTests(tests.TestCase):
+
     def test_canned_input_get_input(self):
-        uif = CannedInputUIFactory([True, 'mbp', 'password'])
+        uif = _mod_ui.CannedInputUIFactory([True, 'mbp', 'password'])
         self.assertEqual(uif.get_boolean('Extra cheese?'), True)
         self.assertEqual(uif.get_username('Enter your user name'), 'mbp')
-        self.assertEqual(uif.get_password('Password for %(host)s', host='example.com'),
-            'password')
+        self.assertEqual(uif.get_password('Password for %(host)s',
+                                          host='example.com'),
+                         'password')
 
 
 class TestBoolFromString(tests.TestCase):



More information about the bazaar-commits mailing list