Rev 4775: Cleanup imports in test_ui in file:///home/vila/src/bzr/cleanup/various/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Dec 10 15:13:11 GMT 2009


At file:///home/vila/src/bzr/cleanup/various/

------------------------------------------------------------
revno: 4775
revision-id: v.ladeuil+lp at free.fr-20091210151311-u5jr781yeagxmovi
parent: v.ladeuil+lp at free.fr-20091210151036-yz9ak6m51do9xru3
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: various
timestamp: Thu 2009-12-10 16:13:11 +0100
message:
  Cleanup imports in test_ui
-------------- next part --------------
=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py	2009-10-15 20:04:37 +0000
+++ b/bzrlib/tests/test_ui.py	2009-12-10 15:13:11 +0000
@@ -18,9 +18,7 @@
 """
 
 import os
-from StringIO import StringIO
 import re
-import sys
 import time
 
 from bzrlib import (
@@ -31,26 +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,
-    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):
@@ -100,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)),
@@ -120,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
@@ -146,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
@@ -159,16 +139,16 @@
         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(""))
@@ -181,16 +161,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
@@ -210,7 +193,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)
@@ -221,10 +205,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",
@@ -258,22 +242,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:
@@ -284,8 +270,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,
@@ -293,27 +279,27 @@
 
     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 SilentUITests(TestCase):
+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,
@@ -322,34 +308,36 @@
         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'])
-        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')
+        uif = _mod_ui.CannedInputUIFactory([True, 'mbp', 'password', 42])
+        self.assertEqual(True, uif.get_boolean('Extra cheese?'))
+        self.assertEqual('mbp', uif.get_username('Enter your user name'))
+        self.assertEqual('password',
+                         uif.get_password('Password for %(host)s',
+                                          host='example.com'))
+        self.assertEqual(42, uif.get_integer('And all that jazz ?'))
 
 
 class TestBoolFromString(tests.TestCase):



More information about the bazaar-commits mailing list