174
175
bench_history.write("--date %s %s\n" % (time.time(), revision_id))
175
176
self._bench_history = bench_history
176
self.ui = bzrlib.ui.ui_factory
177
self.ui = ui.ui_factory
177
178
self.num_tests = num_tests
178
179
self.error_count = 0
179
180
self.failure_count = 0
571
572
return setattr(self._cstring, name, val)
575
class TestUIFactory(ui.CLIUIFactory):
576
"""A UI Factory for testing.
578
Hide the progress bar but emit note()s.
580
Allows get_password to be tested without real tty attached.
587
super(TestUIFactory, self).__init__()
588
if stdin is not None:
589
# We use a StringIOWrapper to be able to test various
590
# encodings, but the user is still responsible to
591
# encode the string and to set the encoding attribute
592
# of StringIOWrapper.
593
self.stdin = StringIOWrapper(stdin)
595
self.stdout = sys.stdout
599
self.stderr = sys.stderr
604
"""See progress.ProgressBar.clear()."""
606
def clear_term(self):
607
"""See progress.ProgressBar.clear_term()."""
609
def clear_term(self):
610
"""See progress.ProgressBar.clear_term()."""
613
"""See progress.ProgressBar.finished()."""
615
def note(self, fmt_string, *args, **kwargs):
616
"""See progress.ProgressBar.note()."""
617
self.stdout.write((fmt_string + "\n") % args)
619
def progress_bar(self):
622
def nested_progress_bar(self):
625
def update(self, message, count=None, total=None):
626
"""See progress.ProgressBar.update()."""
628
def get_non_echoed_password(self, prompt):
629
"""Get password from stdin without trying to handle the echo mode"""
631
self.stdout.write(prompt)
632
password = self.stdin.readline()
635
if password[-1] == '\n':
636
password = password[:-1]
574
640
class TestCase(unittest.TestCase):
575
641
"""Base class for bzr unit tests.
620
686
def _silenceUI(self):
621
687
"""Turn off UI for duration of test"""
622
688
# by default the UI is off; tests can turn it on if they want it.
623
saved = bzrlib.ui.ui_factory
689
saved = ui.ui_factory
625
bzrlib.ui.ui_factory = saved
626
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
691
ui.ui_factory = saved
692
ui.ui_factory = ui.SilentUIFactory()
627
693
self.addCleanup(_restore)
629
695
def _ndiff_strings(self, a, b):
1007
1071
handler.setLevel(logging.INFO)
1008
1072
logger = logging.getLogger('')
1009
1073
logger.addHandler(handler)
1010
old_ui_factory = bzrlib.ui.ui_factory
1011
bzrlib.ui.ui_factory = bzrlib.tests.blackbox.TestUIFactory(
1014
bzrlib.ui.ui_factory.stdin = stdin
1074
old_ui_factory = ui.ui_factory
1075
ui.ui_factory = TestUIFactory(stdin=stdin, stdout=stdout, stderr=stderr)
1017
1078
if working_dir is not None:
1022
1083
saved_debug_flags = frozenset(debug.debug_flags)
1023
1084
debug.debug_flags.clear()
1025
result = self.apply_redirected(stdin, stdout, stderr,
1086
result = self.apply_redirected(ui.ui_factory.stdin,
1026
1088
bzrlib.commands.run_bzr_catch_errors,
1029
1091
debug.debug_flags.update(saved_debug_flags)
1031
1093
logger.removeHandler(handler)
1032
bzrlib.ui.ui_factory = old_ui_factory
1094
ui.ui_factory = old_ui_factory
1033
1095
if cwd is not None:
1893
1955
'bzrlib.tests.test_merge',
1894
1956
'bzrlib.tests.test_merge3',
1895
1957
'bzrlib.tests.test_merge_core',
1958
'bzrlib.tests.test_merge_directive',
1896
1959
'bzrlib.tests.test_missing',
1897
1960
'bzrlib.tests.test_msgeditor',
1898
1961
'bzrlib.tests.test_nonascii',
1919
1982
'bzrlib.tests.test_smart_add',
1920
1983
'bzrlib.tests.test_smart_transport',
1921
1984
'bzrlib.tests.test_source',
1985
'bzrlib.tests.test_ssh_transport',
1922
1986
'bzrlib.tests.test_status',
1923
1987
'bzrlib.tests.test_store',
1924
1988
'bzrlib.tests.test_subsume',
1927
1991
'bzrlib.tests.test_testament',
1928
1992
'bzrlib.tests.test_textfile',
1929
1993
'bzrlib.tests.test_textmerge',
1994
'bzrlib.tests.test_timestamp',
1930
1995
'bzrlib.tests.test_trace',
1931
1996
'bzrlib.tests.test_transactions',
1932
1997
'bzrlib.tests.test_transform',