Пример #1
0
 def test_text_factory_prompt(self):
     # see <https://launchpad.net/bugs/365891>
     StringIO = tests.StringIOWrapper
     factory = _mod_ui_text.TextUIFactory(StringIO(), StringIO(), StringIO())
     factory.prompt(u'foo %2e')
     self.assertEqual('', factory.stdout.getvalue())
     self.assertEqual('foo %2e', factory.stderr.getvalue())
Пример #2
0
 def test_text_factory_prompts_and_clears(self):
     # a get_boolean call should clear the pb before prompting
     out = TTYStringIO()
     self.overrideEnv('TERM', 'xterm')
     factory = _mod_ui_text.TextUIFactory(
         stdin=tests.StringIOWrapper("yada\ny\n"),
         stdout=out, stderr=out)
     factory._avail_width = lambda: 79
     pb = factory.nested_progress_bar()
     pb.show_bar = False
     pb.show_spinner = False
     pb.show_count = False
     pb.update("foo", 0, 1)
     self.assertEqual(True,
                      self.apply_redirected(None, factory.stdout,
                                            factory.stdout,
                                            factory.get_boolean,
                                            u"what do you want"))
     output = out.getvalue()
     self.assertContainsRe(output,
         "| foo *\r\r  *\r*")
     self.assertContainsString(output,
         r"what do you want? ([y]es, [n]o): what do you want? ([y]es, [n]o): ")
     # stdin should have been totally consumed
     self.assertEqual('', factory.stdin.readline())
Пример #3
0
 def test_text_ui_choose_return_values(self):
     choose = lambda: factory.choose(u"", u"&Yes\n&No\nMaybe\nmore &info", 3)
     stdin = tests.StringIOWrapper("y\n" # 0
                                   "n\n" # 1
                                   " \n" # default: 3
                                   " no \n" # 1
                                   "b\na\nd \n" # bad shortcuts, all ignored
                                   "yes with garbage\nY\n" # 0
                                   "not an answer\nno\n" # 1
                                   "info\nmore info\n" # 3
                                   "Maybe\n" # 2
                                   "foo\n")
     stdout = tests.StringIOWrapper()
     stderr = tests.StringIOWrapper()
     factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
     self.assertEqual(0, choose())
     self.assertEqual(1, choose())
     self.assertEqual(3, choose())
     self.assertEqual(1, choose())
     self.assertEqual(0, choose())
     self.assertEqual(1, choose())
     self.assertEqual(3, choose())
     self.assertEqual(2, choose())
     self.assertEqual("foo\n", factory.stdin.read())
     # stdin should be empty
     self.assertEqual('', factory.stdin.readline())
     # return None on EOF
     self.assertEqual(None, choose())
Пример #4
0
 def test_text_ui_get_boolean(self):
     stdin = tests.StringIOWrapper("y\n" # True
                                   "n\n" # False
                                   " \n y \n" # True
                                   " no \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(u""))
     self.assertEqual(False, factory.get_boolean(u""))
     self.assertEqual(True, factory.get_boolean(u""))
     self.assertEqual(False, factory.get_boolean(u""))
     self.assertEqual(True, factory.get_boolean(u""))
     self.assertEqual(False, factory.get_boolean(u""))
     self.assertEqual(True, factory.get_boolean(u""))
     self.assertEqual(False, factory.get_boolean(u""))
     self.assertEqual("foo\n", factory.stdin.read())
     # stdin should be empty
     self.assertEqual('', factory.stdin.readline())
     # return false on EOF
     self.assertEqual(False, factory.get_boolean(u""))
Пример #5
0
 def test_text_ui_choose_no_default(self):
     stdin = tests.StringIOWrapper(" \n" # no default, invalid!
                                   " yes \n" # 0
                                   "foo\n")
     stdout = tests.StringIOWrapper()
     stderr = tests.StringIOWrapper()
     factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
     self.assertEqual(0, factory.choose(u"", u"&Yes\n&No"))
     self.assertEqual("foo\n", factory.stdin.read())
Пример #6
0
 def test_quietness(self):
     self.overrideEnv('BZR_PROGRESS_BAR', 'text')
     ui_factory = _mod_ui_text.TextUIFactory(None,
         TTYStringIO(),
         TTYStringIO())
     self.assertIsInstance(ui_factory._progress_view,
         _mod_ui_text.TextProgressView)
     ui_factory.be_quiet(True)
     self.assertIsInstance(ui_factory._progress_view,
         _mod_ui_text.NullProgressView)
Пример #7
0
 def test_text_ui_getusername_utf8(self):
     ui = _mod_ui_text.TextUIFactory(None, None, None)
     ui.stdin = tests.StringIOWrapper(u'someuser\u1234'.encode('utf8'))
     ui.stdout = tests.StringIOWrapper()
     ui.stderr = tests.StringIOWrapper()
     ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
     username = ui.get_username(u'Hello %(host)s', host=u'some\u1234')
     self.assertEqual(u"someuser\u1234", username)
     self.assertEqual(u"Hello some\u1234: ",
                       ui.stderr.getvalue().decode("utf8"))
     self.assertEqual('', ui.stdout.getvalue())
Пример #8
0
 def test_text_tick_after_update(self):
     ui_factory = _mod_ui_text.TextUIFactory(stdout=tests.StringIOWrapper(),
                                             stderr=tests.StringIOWrapper())
     pb = ui_factory.nested_progress_bar()
     try:
         pb.update('task', 0, 3)
         # Reset the clock, so that it actually tries to repaint itself
         ui_factory._progress_view._last_repaint = time.time() - 1.0
         pb.tick()
     finally:
         pb.finished()
Пример #9
0
 def test_text_ui_get_integer(self):
     stdin = tests.StringIOWrapper(
         "1\n"
         "  -2  \n"
         "hmmm\nwhat else ?\nCome on\nok 42\n4.24\n42\n")
     stdout = tests.StringIOWrapper()
     stderr = tests.StringIOWrapper()
     factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
     self.assertEqual(1, factory.get_integer(u""))
     self.assertEqual(-2, factory.get_integer(u""))
     self.assertEqual(42, factory.get_integer(u""))
Пример #10
0
 def test_text_ui_choose_bad_parameters(self):
     stdin = tests.StringIOWrapper()
     stdout = tests.StringIOWrapper()
     stderr = tests.StringIOWrapper()
     factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
     # invalid default index
     self.assertRaises(ValueError, factory.choose, u"", u"&Yes\n&No", 3)
     # duplicated choice
     self.assertRaises(ValueError, factory.choose, u"", u"&choice\n&ChOiCe")
     # duplicated shortcut
     self.assertRaises(ValueError, factory.choose, u"", u"&choice1\nchoi&ce2")
Пример #11
0
 def test_text_ui_choose_prompt(self):
     stdin = tests.StringIOWrapper()
     stdout = tests.StringIOWrapper()
     stderr = tests.StringIOWrapper()
     factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
     # choices with explicit shortcuts
     factory.choose(u"prompt", u"&yes\n&No\nmore &info")
     self.assertEqual("prompt ([y]es, [N]o, more [i]nfo): \n", factory.stderr.getvalue())
     # automatic shortcuts
     factory.stderr.truncate(0)
     factory.choose(u"prompt", u"yes\nNo\nmore info")
     self.assertEqual("prompt ([y]es, [N]o, [m]ore info): \n", factory.stderr.getvalue())
Пример #12
0
 def test_text_ui_getusername(self):
     ui = _mod_ui_text.TextUIFactory(None, None, None)
     ui.stdin = tests.StringIOWrapper('someuser\n\n')
     ui.stdout = tests.StringIOWrapper()
     ui.stderr = tests.StringIOWrapper()
     ui.stdout.encoding = 'utf8'
     self.assertEqual('someuser',
                      ui.get_username(u'Hello %(host)s', host='some'))
     self.assertEqual('Hello some: ', ui.stderr.getvalue())
     self.assertEqual('', ui.stdout.getvalue())
     self.assertEqual('', ui.get_username(u"Gebruiker"))
     # stdin should be empty
     self.assertEqual('', ui.stdin.readline())
Пример #13
0
 def test_text_factory_utf8_password(self):
     """Test an utf8 password."""
     ui = _mod_ui_text.TextUIFactory(None, None, None)
     ui.stdin = tests.StringIOWrapper(u'baz\u1234'.encode('utf8'))
     ui.stdout = tests.StringIOWrapper()
     ui.stderr = tests.StringIOWrapper()
     ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
     password = ui.get_password(u'Hello \u1234 %(user)s', user=u'some\u1234')
     self.assertEqual(u'baz\u1234', password)
     self.assertEqual(u'Hello \u1234 some\u1234: ',
                      ui.stderr.getvalue().decode('utf8'))
     # stdin and stdout should be empty
     self.assertEqual('', ui.stdin.readline())
     self.assertEqual('', ui.stdout.getvalue())
Пример #14
0
    def test_output_clears_terminal(self):
        stdout = tests.StringIOWrapper()
        stderr = tests.StringIOWrapper()
        clear_calls = []

        uif =  _mod_ui_text.TextUIFactory(None, stdout, stderr)
        uif.clear_term = lambda: clear_calls.append('clear')

        stream = _mod_ui_text.TextUIOutputStream(uif, uif.stdout)
        stream.write("Hello world!\n")
        stream.write("there's more...\n")
        stream.writelines(["1\n", "2\n", "3\n"])

        self.assertEqual(stdout.getvalue(),
            "Hello world!\n"
            "there's more...\n"
            "1\n2\n3\n")
        self.assertEqual(['clear', 'clear', 'clear'],
            clear_calls)

        stream.flush()
Пример #15
0
    graph,
    ui,
    trace,
    _known_graph_py,
    _known_graph_pyx,
)
from bzrlib.ui import text

p = optparse.OptionParser()
p.add_option('--quick', default=False, action='store_true')
p.add_option('--max-combinations', default=500, type=int)
p.add_option('--lsprof', default=None, type=str)
opts, args = p.parse_args(sys.argv[1:])

trace.enable_default_logging()
ui.ui_factory = text.TextUIFactory()

begin = time.clock()
if len(args) >= 1:
    b = branch.Branch.open(args[0])
else:
    b = branch.Branch.open('.')
b.lock_read()
try:
    g = b.repository.get_graph()
    parent_map = dict(p for p in g.iter_ancestry([b.last_revision()])
                      if p[1] is not None)
finally:
    b.unlock()
end = time.clock()