~jelmer/brz/fix-c-extensions

« back to all changes in this revision

Viewing changes to breezy/tests/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
599
599
 
600
600
    def __init__(self, stream, descriptions, verbosity,
601
601
                 bench_history=None,
602
 
                 pb=None,
603
602
                 strict=None,
604
603
                 ):
605
604
        ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
606
605
            bench_history, strict)
607
 
        # We no longer pass them around, but just rely on the UIFactory stack
608
 
        # for state
609
 
        if pb is not None:
610
 
            warnings.warn("Passing pb to TextTestResult is deprecated")
611
606
        self.pb = self.ui.nested_progress_bar()
612
607
        self.pb.show_pct = False
613
608
        self.pb.show_spinner = False
794
789
        # to encode using ascii.
795
790
        new_encoding = osutils.get_terminal_encoding()
796
791
        codec = codecs.lookup(new_encoding)
797
 
        if isinstance(codec, tuple):
798
 
            # Python 2.4
799
 
            encode = codec[0]
800
 
        else:
801
 
            encode = codec.encode
 
792
        encode = codec.encode
802
793
        # GZ 2010-09-08: Really we don't want to be writing arbitrary bytes,
803
794
        #                so should swap to the plain codecs.StreamWriter
804
795
        stream = osutils.UnicodeOrBytesToBytesWriter(encode, stream,
1042
1033
                                  % (counter_name,))
1043
1034
        _counters[counter_name] = 0
1044
1035
        self.addDetail(counter_name, content.Content(content.UTF8_TEXT,
1045
 
            lambda: ['%d' % (_counters[counter_name],)]))
 
1036
            lambda: [b'%d' % (_counters[counter_name],)]))
1046
1037
        def increment_counter(*args, **kwargs):
1047
1038
            _counters[counter_name] += 1
1048
1039
        label = 'count %s calls' % (counter_name,)
1560
1551
 
1561
1552
    def assertPathDoesNotExist(self, path):
1562
1553
        """Fail if path or paths, which may be abs or relative, exist."""
1563
 
        if not isinstance(path, basestring):
 
1554
        if not isinstance(path, (str, text_type)):
1564
1555
            for p in path:
1565
1556
                self.assertPathDoesNotExist(p)
1566
1557
        else:
1889
1880
        self._benchcalls.
1890
1881
        """
1891
1882
        if self._benchtime is None:
1892
 
            self.addDetail('benchtime', content.Content(content.ContentType(
1893
 
                "text", "plain"), lambda:[str(self._benchtime)]))
 
1883
            self.addDetail('benchtime', content.Content(content.UTF8_TEXT,
 
1884
                lambda:[str(self._benchtime).encode('utf-8')]))
1894
1885
            self._benchtime = 0
1895
1886
        start = time.time()
1896
1887
        try:
2091
2082
        if len(args) == 1:
2092
2083
            if isinstance(args[0], list):
2093
2084
                args = args[0]
2094
 
            elif isinstance(args[0], basestring):
 
2085
            elif isinstance(args[0], (str, text_type)):
2095
2086
                args = list(shlex.split(args[0]))
2096
2087
        else:
2097
2088
            raise ValueError("passing varargs to run_bzr_subprocess")
2253
2244
        if retcode is not None and retcode != process.returncode:
2254
2245
            if process_args is None:
2255
2246
                process_args = "(unknown args)"
2256
 
            trace.mutter('Output of brz %s:\n%s', process_args, out)
2257
 
            trace.mutter('Error for brz %s:\n%s', process_args, err)
2258
 
            self.fail('Command brz %s failed with retcode %s != %s'
 
2247
            trace.mutter('Output of brz %r:\n%s', process_args, out)
 
2248
            trace.mutter('Error for brz %r:\n%s', process_args, err)
 
2249
            self.fail('Command brz %r failed with retcode %d != %d'
2259
2250
                      % (process_args, retcode, process.returncode))
2260
2251
        return [out, err]
2261
2252
 
2289
2280
        if not callable(a_callable):
2290
2281
            raise ValueError("a_callable must be callable.")
2291
2282
        if stdin is None:
2292
 
            stdin = BytesIO("")
 
2283
            stdin = BytesIO(b"")
2293
2284
        if stdout is None:
2294
2285
            if getattr(self, "_log_file", None) is not None:
2295
2286
                stdout = self._log_file
2848
2839
        if transport is None or transport.is_readonly():
2849
2840
            transport = _mod_transport.get_transport_from_path(".")
2850
2841
        for name in shape:
2851
 
            self.assertIsInstance(name, basestring)
 
2842
            self.assertIsInstance(name, (str, text_type))
2852
2843
            if name[-1] == '/':
2853
2844
                transport.mkdir(urlutils.escape(name[:-1]))
2854
2845
            else:
2855
2846
                if line_endings == 'binary':
2856
 
                    end = '\n'
 
2847
                    end = b'\n'
2857
2848
                elif line_endings == 'native':
2858
 
                    end = os.linesep
 
2849
                    end = os.linesep.encode('ascii')
2859
2850
                else:
2860
2851
                    raise errors.BzrError(
2861
2852
                        'Invalid line ending request %r' % line_endings)
2862
 
                content = "contents of %s%s" % (name.encode('utf-8'), end)
 
2853
                content = b"contents of %s%s" % (name.encode('utf-8'), end)
2863
2854
                transport.put_bytes_non_atomic(urlutils.escape(name), content)
2864
2855
 
2865
2856
    build_tree_contents = staticmethod(treeshape.build_tree_contents)
2868
2859
        """Assert whether path or paths are in the WorkingTree"""
2869
2860
        if tree is None:
2870
2861
            tree = workingtree.WorkingTree.open(root_path)
2871
 
        if not isinstance(path, basestring):
 
2862
        if not isinstance(path, (str, text_type)):
2872
2863
            for p in path:
2873
2864
                self.assertInWorkingTree(p, tree=tree)
2874
2865
        else:
2879
2870
        """Assert whether path or paths are not in the WorkingTree"""
2880
2871
        if tree is None:
2881
2872
            tree = workingtree.WorkingTree.open(root_path)
2882
 
        if not isinstance(path, basestring):
 
2873
        if not isinstance(path, (str, text_type)):
2883
2874
            for p in path:
2884
2875
                self.assertNotInWorkingTree(p,tree=tree)
2885
2876
        else:
2998
2989
        There is no point in forcing them to duplicate the extension related
2999
2990
        warning.
3000
2991
        """
3001
 
        config.GlobalStack().set('ignore_missing_extensions', True)
 
2992
        config.GlobalConfig().set_user_option(
 
2993
            'suppress_warnings', 'missing_extensions')
3002
2994
 
3003
2995
 
3004
2996
class ChrootedTestCase(TestCaseWithTransport):