Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Lib/doctest.py

    r2 r388  
    217217                # conversion as universal newlines would do.
    218218                return file_contents.replace(os.linesep, '\n'), filename
    219     return open(filename).read(), filename
     219    with open(filename) as f:
     220        return f.read(), filename
    220221
    221222# Use sys.stdout encoding for ouput.
     
    264265        if hasattr(self, "softspace"):
    265266            del self.softspace
     267        if not self.buf:
     268            # Reset it to an empty string, to make sure it's not unicode.
     269            self.buf = ''
    266270
    267271# Worst-case linear-time ellipsis matching.
     
    333337        self.__debugger_used = False
    334338        pdb.Pdb.__init__(self, stdout=out)
     339        # still use input() to get user input
     340        self.use_rawinput = 1
    335341
    336342    def set_trace(self, frame=None):
     
    419425
    420426      - indent: The example's indentation in the DocTest string.
    421         I.e., the number of space characters that preceed the
     427        I.e., the number of space characters that precede the
    422428        example's first prompt.
    423429
     
    446452        self.exc_msg = exc_msg
    447453
     454    def __eq__(self, other):
     455        if type(self) is not type(other):
     456            return NotImplemented
     457
     458        return self.source == other.source and \
     459               self.want == other.want and \
     460               self.lineno == other.lineno and \
     461               self.indent == other.indent and \
     462               self.options == other.options and \
     463               self.exc_msg == other.exc_msg
     464
     465    def __ne__(self, other):
     466        return not self == other
     467
     468    def __hash__(self):
     469        return hash((self.source, self.want, self.lineno, self.indent,
     470                     self.exc_msg))
     471
     472
    448473class DocTest:
    449474    """
     
    494519                (self.name, self.filename, self.lineno, examples))
    495520
     521    def __eq__(self, other):
     522        if type(self) is not type(other):
     523            return NotImplemented
     524
     525        return self.examples == other.examples and \
     526               self.docstring == other.docstring and \
     527               self.globs == other.globs and \
     528               self.name == other.name and \
     529               self.filename == other.filename and \
     530               self.lineno == other.lineno
     531
     532    def __ne__(self, other):
     533        return not self == other
     534
     535    def __hash__(self):
     536        return hash((self.docstring, self.name, self.filename, self.lineno))
    496537
    497538    # This lets us sort tests by name:
     
    524565        (?P<want> (?:(?![ ]*$)    # Not a blank line
    525566                     (?![ ]*>>>)  # Not a line starting with PS1
    526                      .*$\n?       # But any other line
     567                     .+$\n?       # But any other line
    527568                  )*)
    528569        ''', re.MULTILINE | re.VERBOSE)
     
    855896            globs['__name__'] = '__main__'  # provide a default module name
    856897
    857         # Recursively expore `obj`, extracting DocTests.
     898        # Recursively explore `obj`, extracting DocTests.
    858899        tests = []
    859900        self._find(tests, obj, name, module, source_lines, globs, {})
     
    12121253        for examplenum, example in enumerate(test.examples):
    12131254
    1214             # If REPORT_ONLY_FIRST_FAILURE is set, then supress
     1255            # If REPORT_ONLY_FIRST_FAILURE is set, then suppress
    12151256            # reporting after the first failure.
    12161257            quiet = (self.optionflags & REPORT_ONLY_FIRST_FAILURE and
     
    12831324                # Another chance if they didn't care about the detail.
    12841325                elif self.optionflags & IGNORE_EXCEPTION_DETAIL:
    1285                     m1 = re.match(r'[^:]*:', example.exc_msg)
    1286                     m2 = re.match(r'[^:]*:', exc_msg)
    1287                     if m1 and m2 and check(m1.group(0), m2.group(0),
     1326                    m1 = re.match(r'(?:[^:]*\.)?([^:]*:)', example.exc_msg)
     1327                    m2 = re.match(r'(?:[^:]*\.)?([^:]*:)', exc_msg)
     1328                    if m1 and m2 and check(m1.group(1), m2.group(1),
    12881329                                           self.optionflags):
    12891330                        outcome = SUCCESS
     
    13231364
    13241365    __LINECACHE_FILENAME_RE = re.compile(r'<doctest '
    1325                                          r'(?P<name>[\w\.]+)'
     1366                                         r'(?P<name>.+)'
    13261367                                         r'\[(?P<examplenum>\d+)\]>$')
    13271368    def __patched_linecache_getlines(self, filename, module_globals=None):
     
    13291370        if m and m.group('name') == self.test.name:
    13301371            example = self.test.examples[int(m.group('examplenum'))]
    1331             return example.source.splitlines(True)
     1372            source = example.source
     1373            if isinstance(source, unicode):
     1374                source = source.encode('ascii', 'backslashreplace')
     1375            return source.splitlines(True)
    13321376        else:
    13331377            return self.save_linecache_getlines(filename, module_globals)
     
    13781422        linecache.getlines = self.__patched_linecache_getlines
    13791423
     1424        # Make sure sys.displayhook just prints the value to stdout
     1425        save_displayhook = sys.displayhook
     1426        sys.displayhook = sys.__displayhook__
     1427
    13801428        try:
    13811429            return self.__run(test, compileflags, out)
     
    13841432            pdb.set_trace = save_set_trace
    13851433            linecache.getlines = self.save_linecache_getlines
     1434            sys.displayhook = save_displayhook
    13861435            if clear_globs:
    13871436                test.globs.clear()
     
    17611810    Return (#failures, #tests).
    17621811
    1763     See doctest.__doc__ for an overview.
     1812    See help(doctest) for an overview.
    17641813
    17651814    Optional keyword arg "name" gives the name of the module; by default
     
    21732222
    21742223           The DocTestCase provides a debug method that raises
    2175            UnexpectedException errors if there is an unexepcted
     2224           UnexpectedException errors if there is an unexpected
    21762225           exception:
    21772226
     
    22392288        return self._dt_test.name
    22402289
     2290    def __eq__(self, other):
     2291        if type(self) is not type(other):
     2292            return NotImplemented
     2293
     2294        return self._dt_test == other._dt_test and \
     2295               self._dt_optionflags == other._dt_optionflags and \
     2296               self._dt_setUp == other._dt_setUp and \
     2297               self._dt_tearDown == other._dt_tearDown and \
     2298               self._dt_checker == other._dt_checker
     2299
     2300    def __ne__(self, other):
     2301        return not self == other
     2302
     2303    def __hash__(self):
     2304        return hash((self._dt_optionflags, self._dt_setUp, self._dt_tearDown,
     2305                     self._dt_checker))
     2306
    22412307    def __repr__(self):
    22422308        name = self._dt_test.name.split('.')
     
    22472313    def shortDescription(self):
    22482314        return "Doctest: " + self._dt_test.name
     2315
     2316class SkipDocTestCase(DocTestCase):
     2317    def __init__(self, module):
     2318        self.module = module
     2319        DocTestCase.__init__(self, None)
     2320
     2321    def setUp(self):
     2322        self.skipTest("DocTestSuite will not work with -O2 and above")
     2323
     2324    def test_skip(self):
     2325        pass
     2326
     2327    def shortDescription(self):
     2328        return "Skipping tests from %s" % self.module.__name__
     2329
     2330    __str__ = shortDescription
     2331
    22492332
    22502333def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
     
    22902373    module = _normalize_module(module)
    22912374    tests = test_finder.find(module, globs=globs, extraglobs=extraglobs)
    2292     if not tests:
     2375
     2376    if not tests and sys.flags.optimize >=2:
     2377        # Skip doctests when running with -O2
     2378        suite = unittest.TestSuite()
     2379        suite.addTest(SkipDocTestCase(module))
     2380        return suite
     2381    elif not tests:
    22932382        # Why do we want to do this? Because it reveals a bug that might
    22942383        # otherwise be hidden.
    2295         raise ValueError(module, "has no tests")
     2384        # It is probably a bug that this exception is not also raised if the
     2385        # number of doctest examples in tests is zero (i.e. if no doctest
     2386        # examples were found).  However, we should probably not be raising
     2387        # an exception at all here, though it is too late to make this change
     2388        # for a maintenance release.  See also issue #14649.
     2389        raise ValueError(module, "has no docstrings")
    22962390
    22972391    tests.sort()
    22982392    suite = unittest.TestSuite()
     2393
    22992394    for test in tests:
    23002395        if len(test.examples) == 0:
     
    26682763           }
    26692764
     2765
    26702766def _test():
    26712767    testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-']
    2672     if testfiles:
    2673         for filename in testfiles:
    2674             if filename.endswith(".py"):
    2675                 # It is a module -- insert its dir into sys.path and try to
    2676                 # import it. If it is part of a package, that possibly won't work
    2677                 # because of package imports.
    2678                 dirname, filename = os.path.split(filename)
    2679                 sys.path.insert(0, dirname)
    2680                 m = __import__(filename[:-3])
    2681                 del sys.path[0]
    2682                 failures, _ = testmod(m)
    2683             else:
    2684                 failures, _ = testfile(filename, module_relative=False)
    2685             if failures:
    2686                 return 1
    2687     else:
    2688         r = unittest.TextTestRunner()
    2689         r.run(DocTestSuite())
     2768    if not testfiles:
     2769        name = os.path.basename(sys.argv[0])
     2770        if '__loader__' in globals():          # python -m
     2771            name, _ = os.path.splitext(name)
     2772        print("usage: {0} [-v] file ...".format(name))
     2773        return 2
     2774    for filename in testfiles:
     2775        if filename.endswith(".py"):
     2776            # It is a module -- insert its dir into sys.path and try to
     2777            # import it. If it is part of a package, that possibly
     2778            # won't work because of package imports.
     2779            dirname, filename = os.path.split(filename)
     2780            sys.path.insert(0, dirname)
     2781            m = __import__(filename[:-3])
     2782            del sys.path[0]
     2783            failures, _ = testmod(m)
     2784        else:
     2785            failures, _ = testfile(filename, module_relative=False)
     2786        if failures:
     2787            return 1
    26902788    return 0
     2789
    26912790
    26922791if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.