/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Alexander Belchenko
  • Date: 2007-03-13 02:16:17 UTC
  • mfrom: (2346 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2356.
  • Revision ID: bialix@ukr.net-20070313021617-azd5lv30b23gyu48
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    memorytree,
52
52
    osutils,
53
53
    progress,
 
54
    ui,
54
55
    urlutils,
55
56
    )
56
57
import bzrlib.branch
57
58
import bzrlib.commands
58
 
import bzrlib.bundle.serializer
 
59
import bzrlib.timestamp
59
60
import bzrlib.export
60
61
import bzrlib.inventory
61
62
import bzrlib.iterablefile
92
93
 
93
94
MODULES_TO_TEST = []
94
95
MODULES_TO_DOCTEST = [
95
 
                      bzrlib.bundle.serializer,
 
96
                      bzrlib.timestamp,
96
97
                      bzrlib.errors,
97
98
                      bzrlib.export,
98
99
                      bzrlib.inventory,
173
174
                revision_id = ''
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)
573
574
 
574
575
 
 
576
class TestUIFactory(ui.CLIUIFactory):
 
577
    """A UI Factory for testing.
 
578
 
 
579
    Hide the progress bar but emit note()s.
 
580
    Redirect stdin.
 
581
    Allows get_password to be tested without real tty attached.
 
582
    """
 
583
 
 
584
    def __init__(self,
 
585
                 stdout=None,
 
586
                 stderr=None,
 
587
                 stdin=None):
 
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)
 
595
        if stdout is None:
 
596
            self.stdout = sys.stdout
 
597
        else:
 
598
            self.stdout = stdout
 
599
        if stderr is None:
 
600
            self.stderr = sys.stderr
 
601
        else:
 
602
            self.stderr = stderr
 
603
 
 
604
    def clear(self):
 
605
        """See progress.ProgressBar.clear()."""
 
606
 
 
607
    def clear_term(self):
 
608
        """See progress.ProgressBar.clear_term()."""
 
609
 
 
610
    def clear_term(self):
 
611
        """See progress.ProgressBar.clear_term()."""
 
612
 
 
613
    def finished(self):
 
614
        """See progress.ProgressBar.finished()."""
 
615
 
 
616
    def note(self, fmt_string, *args, **kwargs):
 
617
        """See progress.ProgressBar.note()."""
 
618
        self.stdout.write((fmt_string + "\n") % args)
 
619
 
 
620
    def progress_bar(self):
 
621
        return self
 
622
 
 
623
    def nested_progress_bar(self):
 
624
        return self
 
625
 
 
626
    def update(self, message, count=None, total=None):
 
627
        """See progress.ProgressBar.update()."""
 
628
 
 
629
    def get_non_echoed_password(self, prompt):
 
630
        """Get password from stdin without trying to handle the echo mode"""
 
631
        if prompt:
 
632
            self.stdout.write(prompt)
 
633
        password = self.stdin.readline()
 
634
        if not password:
 
635
            raise EOFError
 
636
        if password[-1] == '\n':
 
637
            password = password[:-1]
 
638
        return password
 
639
 
 
640
 
575
641
class TestCase(unittest.TestCase):
576
642
    """Base class for bzr unit tests.
577
643
    
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
625
691
        def _restore():
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)
629
695
 
630
696
    def _ndiff_strings(self, a, b):
995
1061
        """
996
1062
        if encoding is None:
997
1063
            encoding = bzrlib.user_encoding
998
 
        if stdin is not None:
999
 
            stdin = StringIO(stdin)
1000
1064
        stdout = StringIOWrapper()
1001
1065
        stderr = StringIOWrapper()
1002
1066
        stdout.encoding = encoding
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(
1013
 
            stdout=stdout,
1014
 
            stderr=stderr)
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)
1016
1077
 
1017
1078
        cwd = None
1018
1079
        if working_dir is not None:
1023
1084
            saved_debug_flags = frozenset(debug.debug_flags)
1024
1085
            debug.debug_flags.clear()
1025
1086
            try:
1026
 
                result = self.apply_redirected(stdin, stdout, stderr,
 
1087
                result = self.apply_redirected(ui.ui_factory.stdin,
 
1088
                                               stdout, stderr,
1027
1089
                                               bzrlib.commands.run_bzr_catch_errors,
1028
1090
                                               argv)
1029
1091
            finally:
1030
1092
                debug.debug_flags.update(saved_debug_flags)
1031
1093
        finally:
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:
1035
1097
                os.chdir(cwd)
1036
1098
 
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',