Пример #1
0
    def _any_match(matchers, record):
        """return the bool of whether `record` starts with
        any item in `matchers`"""
        def record_matches_key(key):
            return record == key or record.startswith(key + '.')

        return anyp(bool, list(map(record_matches_key, matchers)))
Пример #2
0
    def _any_match(matchers, record):
        """return the bool of whether `record` starts with
        any item in `matchers`"""

        def record_matches_key(key):
            return record == key or record.startswith(key + ".")

        return anyp(bool, list(map(record_matches_key, matchers)))
Пример #3
0
 def loadTestsFromPath(self, filename, package=None, importPath=None):
     if self.extension and anyp(filename.endswith, self.extension):
         try:
             return doctest.DocFileSuite(filename, module_relative=False)
         except AttributeError:
             raise Exception("Doctests in files other than .py "
                             "(python source) not supported in this "
                             "version of doctest")
     else:
         # Don't return None, users may iterate over result
         return []
Пример #4
0
 def wantFile(self, file):
     # always want .py files
     if file.endswith('.py'):
         return True
     # also want files that match my extension
     if (self.extension and anyp(file.endswith, self.extension) and
         (not self.conf.exclude or
          not filter(None, [exc.search(file)
                            for exc in self.conf.exclude]))):
         return True
     return None
Пример #5
0
    def loadTestsFromFile(self, filename):
        """Load doctests from the file.

        Tests are loaded only if filename's extension matches
        configured doctest extension.

        """
        if self.extension and anyp(filename.endswith, self.extension):
            name = os.path.basename(filename)
            dh = open(filename)
            try:
                doc = dh.read()
            finally:
                dh.close()

            fixture_context = None
            globs = {'__file__': filename}
            if self.fixtures:
                base, ext = os.path.splitext(name)
                dirname = os.path.dirname(filename)
                sys.path.append(dirname)
                fixt_mod = base + self.fixtures
                try:
                    fixture_context = __import__(fixt_mod, globals(), locals(),
                                                 ["nop"])
                except ImportError as e:
                    log.debug("Could not import %s: %s (%s)", fixt_mod, e,
                              sys.path)
                log.debug("Fixture module %s resolved to %s", fixt_mod,
                          fixture_context)
                if hasattr(fixture_context, 'globs'):
                    globs = fixture_context.globs(globs)
            parser = doctest.DocTestParser()
            test = parser.get_doctest(doc,
                                      globs=globs,
                                      name=name,
                                      filename=filename,
                                      lineno=0)
            if test.examples:
                case = DocFileCase(test,
                                   optionflags=self.optionflags,
                                   setUp=getattr(fixture_context, 'setup_test',
                                                 None),
                                   tearDown=getattr(fixture_context,
                                                    'teardown_test', None),
                                   result_var=self.doctest_result_var)
                if fixture_context:
                    yield ContextList((case, ), context=fixture_context)
                else:
                    yield case
            else:
                yield False  # no tests to load
Пример #6
0
 def wantFile(self, file, package=None):
     # always want .py files
     if file.endswith('.py'):
         return True
     # also want files that match my extension
     if (self.extension
         and anyp(file.endswith, self.extension)
         and (not self.conf.exclude
              or not filter(None, 
                            [exc.search(file)
                             for exc in self.conf.exclude]))):
         return True
     return None
Пример #7
0
 def wantFile(self, file):
     """Override to select all modules and any file ending with
     configured doctest extension.
     """
     # always want .py files
     if file.endswith('.py'):
         return True
     # also want files that match my extension
     if (self.extension and anyp(file.endswith, self.extension) and
         (not self.conf.exclude or
          not filter(None, [exc.search(file)
                            for exc in self.conf.exclude]))):
         return True
     return None
Пример #8
0
    def loadTestsFromFile(self, filename):
        """Load doctests from the file.

        Tests are loaded only if filename's extension matches
        configured doctest extension.

        """
        if self.extension and anyp(filename.endswith, self.extension):
            name = os.path.basename(filename)
            dh = open(filename)
            try:
                doc = dh.read()
            finally:
                dh.close()

            fixture_context = None
            globs = {'__file__': filename}
            if self.fixtures:
                base, ext = os.path.splitext(name)
                dirname = os.path.dirname(filename)
                sys.path.append(dirname)
                fixt_mod = base + self.fixtures
                try:
                    fixture_context = __import__(
                        fixt_mod, globals(), locals(), ["nop"])
                except ImportError as e:
                    log.debug(
                        "Could not import %s: %s (%s)", fixt_mod, e, sys.path)
                log.debug("Fixture module %s resolved to %s",
                          fixt_mod, fixture_context)
                if hasattr(fixture_context, 'globs'):
                    globs = fixture_context.globs(globs)                    
            parser = doctest.DocTestParser()
            test = parser.get_doctest(
                doc, globs=globs, name=name,
                filename=filename, lineno=0)
            if test.examples:
                case = DocFileCase(
                    test,
                    optionflags=self.optionflags,
                    setUp=getattr(fixture_context, 'setup_test', None),
                    tearDown=getattr(fixture_context, 'teardown_test', None),
                    result_var=self.doctest_result_var)
                if fixture_context:
                    yield ContextList((case,), context=fixture_context)
                else:
                    yield case
            else:
                yield False # no tests to load
Пример #9
0
 def wantFile(self, file):
     """Override to select all modules and any file ending with
     configured doctest extension.
     """
     # always want .py files
     if file.endswith('.py'):
         return True
     # also want files that match my extension
     if (self.extension
         and anyp(file.endswith, self.extension)
         and (not self.conf.exclude
              or not [_f for _f in [exc.search(file)
                             for exc in self.conf.exclude] if _f])):
         return True
     return None
Пример #10
0
 def loadTestsFromFile(self, filename):
     if self.extension and anyp(filename.endswith, self.extension):
         name = os.path.basename(filename)
         dh = open(filename)
         try:
             doc = dh.read()
         finally:
             dh.close()
         parser = doctest.DocTestParser()
         test = parser.get_doctest(
             doc, globs={'__file__': filename}, name=name,
             filename=filename, lineno=0)
         if test.examples:
             yield DocFileCase(test)
         else:
             yield False # no tests to load
Пример #11
0
    def loadTestsFromFileUnicode(self, filename):
        if self.extension and anyp(filename.endswith, self.extension):
            name = os.path.basename(filename)
            dh = codecs.open(filename, "r",
                             self.options.get("doctestencoding"))
            try:
                doc = dh.read()
            finally:
                dh.close()

            fixture_context = None
            globs = {"__file__": filename}
            if self.fixtures:
                base, ext = os.path.splitext(name)
                dirname = os.path.dirname(filename)
                sys.path.append(dirname)
                fixt_mod = base + self.fixtures
                try:
                    fixture_context = __import__(fixt_mod, globals(), locals(),
                                                 ["nop"])
                except ImportError as e:
                    log.debug("Could not import %s: %s (%s)", fixt_mod, e,
                              sys.path)
                log.debug("Fixture module %s resolved to %s", fixt_mod,
                          fixture_context)
                if hasattr(fixture_context, "globs"):
                    globs = fixture_context.globs(globs)
            parser = doctest.DocTestParser()
            test = parser.get_doctest(doc,
                                      globs=globs,
                                      name=name,
                                      filename=filename,
                                      lineno=0)
            if test.examples:
                case = DocFileCase(
                    test,
                    optionflags=self.optionflags,
                    setUp=getattr(fixture_context, "setup_test", None),
                    tearDown=getattr(fixture_context, "teardown_test", None),
                    result_var=self.doctest_result_var,
                )
                if fixture_context:
                    yield ContextList((case, ), context=fixture_context)
                else:
                    yield case
            else:
                yield False  # no tests to load
Пример #12
0
 def wantFile(self, file):
     """Override to select all modules and any file ending with
     configured doctest extension.
     """
     # exclude unwanted files
     if self.conf.exclude and \
             filter(None, [exc.search(file) for exc in self.conf.exclude]):
         log.debug('%s matches exclude pattern; skipped', file)
         return False
     # always want .py files
     if file.endswith('.py'):
         return True
     # also want files that match my extension
     if self.extension and \
             anyp(file.endswith, self.extension):
         return True
     return None
Пример #13
0
 def loadTestsFromFile(self, filename):
     if self.extension and anyp(filename.endswith, self.extension):
         name = os.path.basename(filename)
         dh = open(filename)
         try:
             doc = dh.read()
         finally:
             dh.close()
         parser = doctest.DocTestParser()
         test = parser.get_doctest(doc,
                                   globs={'__file__': filename},
                                   name=name,
                                   filename=filename,
                                   lineno=0)
         if test.examples:
             yield DocFileCase(test)
         else:
             yield False  # no tests to load
 def loadTestsFromFile(self, filename):
     #print "ipdoctest - from file", filename # dbg
     if is_extension_module(filename):
         for t in self.loadTestsFromExtensionModule(filename):
             yield t
     else:
         if self.extension and anyp(filename.endswith, self.extension):
             name = os.path.basename(filename)
             with open(filename) as dh:
                 doc = dh.read()
             test = self.parser.get_doctest(
                 doc, globs={'__file__': filename}, name=name,
                 filename=filename, lineno=0)
             if test.examples:
                 #print 'FileCase:',test.examples  # dbg
                 yield DocFileCase(test)
             else:
                 yield False # no tests to load
Пример #15
0
 def loadTestsFromFile(self, filename):
     #print "ipdoctest - from file", filename # dbg
     if is_extension_module(filename):
         for t in self.loadTestsFromExtensionModule(filename):
             yield t
     else:
         if self.extension and anyp(filename.endswith, self.extension):
             name = PurePath(filename).name
             doc = Path(filename).read_text()
             test = self.parser.get_doctest(doc,
                                            globs={'__file__': filename},
                                            name=name,
                                            filename=filename,
                                            lineno=0)
             if test.examples:
                 #print 'FileCase:',test.examples  # dbg
                 yield DocFileCase(test)
             else:
                 yield False  # no tests to load
Пример #16
0
 def loadTestsFromFile(self, filename):
     if is_extension_module(filename):
         for t in self.loadTestsFromExtensionModule(filename):
             yield t
     else:
         if self.extension and anyp(filename.endswith, self.extension):
             name = os.path.basename(filename)
             dh = open(filename)
             try:
                 doc = dh.read()
             finally:
                 dh.close()
             test = self.parser.get_doctest(
                 doc, globs={'__file__': filename}, name=name,
                 filename=filename, lineno=0)
             if test.examples:
                 #print 'FileCase:',test.examples  # dbg
                 yield DocFileCase(test)
             else:
                 yield False # no tests to load
Пример #17
0
 def loadTestsFromFile(self, filename):
     # print "ipdoctest - from file", filename # dbg
     if is_extension_module(filename):
         for t in self.loadTestsFromExtensionModule(filename):
             yield t
     else:
         if self.extension and anyp(filename.endswith, self.extension):
             name = os.path.basename(filename)
             with open(filename) as dh:
                 doc = dh.read()
             test = self.parser.get_doctest(
                 doc,
                 globs={"__file__": filename},
                 name=name,
                 filename=filename,
                 lineno=0,
             )
             if test.examples:
                 # print 'FileCase:',test.examples  # dbg
                 yield DocFileCase(test)
             else:
                 yield False  # no tests to load