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
572
573
return setattr(self._cstring, name, val)
576
class TestUIFactory(ui.CLIUIFactory):
577
"""A UI Factory for testing.
579
Hide the progress bar but emit note()s.
581
Allows get_password to be tested without real tty attached.
588
super(TestUIFactory, self).__init__()
589
if stdin is not None:
590
# We use a StringIOWrapper to be able to test various
591
# encodings, but the user is still responsible to
592
# encode the string and to set the encoding attribute
593
# of StringIOWrapper.
594
self.stdin = StringIOWrapper(stdin)
596
self.stdout = sys.stdout
600
self.stderr = sys.stderr
605
"""See progress.ProgressBar.clear()."""
607
def clear_term(self):
608
"""See progress.ProgressBar.clear_term()."""
610
def clear_term(self):
611
"""See progress.ProgressBar.clear_term()."""
614
"""See progress.ProgressBar.finished()."""
616
def note(self, fmt_string, *args, **kwargs):
617
"""See progress.ProgressBar.note()."""
618
self.stdout.write((fmt_string + "\n") % args)
620
def progress_bar(self):
623
def nested_progress_bar(self):
626
def update(self, message, count=None, total=None):
627
"""See progress.ProgressBar.update()."""
629
def get_non_echoed_password(self, prompt):
630
"""Get password from stdin without trying to handle the echo mode"""
632
self.stdout.write(prompt)
633
password = self.stdin.readline()
636
if password[-1] == '\n':
637
password = password[:-1]
575
641
class TestCase(unittest.TestCase):
576
642
"""Base class for bzr unit tests.
621
687
def _silenceUI(self):
622
688
"""Turn off UI for duration of test"""
623
689
# by default the UI is off; tests can turn it on if they want it.
624
saved = bzrlib.ui.ui_factory
690
saved = ui.ui_factory
626
bzrlib.ui.ui_factory = saved
627
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
692
ui.ui_factory = saved
693
ui.ui_factory = ui.SilentUIFactory()
628
694
self.addCleanup(_restore)
630
696
def _ndiff_strings(self, a, b):
1008
1072
handler.setLevel(logging.INFO)
1009
1073
logger = logging.getLogger('')
1010
1074
logger.addHandler(handler)
1011
old_ui_factory = bzrlib.ui.ui_factory
1012
bzrlib.ui.ui_factory = bzrlib.tests.blackbox.TestUIFactory(
1015
bzrlib.ui.ui_factory.stdin = stdin
1075
old_ui_factory = ui.ui_factory
1076
ui.ui_factory = TestUIFactory(stdin=stdin, stdout=stdout, stderr=stderr)
1018
1079
if working_dir is not None:
1023
1084
saved_debug_flags = frozenset(debug.debug_flags)
1024
1085
debug.debug_flags.clear()
1026
result = self.apply_redirected(stdin, stdout, stderr,
1087
result = self.apply_redirected(ui.ui_factory.stdin,
1027
1089
bzrlib.commands.run_bzr_catch_errors,
1030
1092
debug.debug_flags.update(saved_debug_flags)
1032
1094
logger.removeHandler(handler)
1033
bzrlib.ui.ui_factory = old_ui_factory
1095
ui.ui_factory = old_ui_factory
1034
1096
if cwd is not None:
1900
1962
'bzrlib.tests.test_merge',
1901
1963
'bzrlib.tests.test_merge3',
1902
1964
'bzrlib.tests.test_merge_core',
1965
'bzrlib.tests.test_merge_directive',
1903
1966
'bzrlib.tests.test_missing',
1904
1967
'bzrlib.tests.test_msgeditor',
1905
1968
'bzrlib.tests.test_nonascii',
1926
1989
'bzrlib.tests.test_smart_add',
1927
1990
'bzrlib.tests.test_smart_transport',
1928
1991
'bzrlib.tests.test_source',
1992
'bzrlib.tests.test_ssh_transport',
1929
1993
'bzrlib.tests.test_status',
1930
1994
'bzrlib.tests.test_store',
1931
1995
'bzrlib.tests.test_subsume',
1934
1998
'bzrlib.tests.test_testament',
1935
1999
'bzrlib.tests.test_textfile',
1936
2000
'bzrlib.tests.test_textmerge',
2001
'bzrlib.tests.test_timestamp',
1937
2002
'bzrlib.tests.test_trace',
1938
2003
'bzrlib.tests.test_transactions',
1939
2004
'bzrlib.tests.test_transform',