Example #1
0
 def test_number_re(self):
     for s in [
             "1.",
             "+1.",
             "-1.",
             ".1",
             "+.1",
             "-.1",
             "0.1",
             "+0.1",
             "-0.1",
             "1e5",
             "+1e5",
             "1e+5",
             "+1e+5",
             "1e-5",
             "+1e-5",
             "-1e-5",
             "1.2e3",
             "-1.2e-3",
     ]:
         print(s)
         m = _get_checker()._number_re.match(s)
         assert m is not None
         assert float(m.group()) == pytest.approx(float(s))
     for s in ["1", "abc"]:
         print(s)
         assert _get_checker()._number_re.match(s) is None
Example #2
0
    def collect(self):
        import doctest

        if self.fspath.basename == "conftest.py":
            module = self.config.pluginmanager._importconftest(self.fspath)
        else:
            try:
                # XXX patch pyimport in pytest._pytest.doctest.DoctestModule
                module = _patch_pyimport(self.fspath)
            except ImportError:
                if self.config.getoption('--cython-ignore-import-errors'):
                    pytest.skip('unable to import module %r' % self.fspath)
                else:
                    raise

        # uses internal doctest module parsing mechanism
        finder = doctest.DocTestFinder()
        optionflags = get_optionflags(self)
        checker = None if _get_checker is None else _get_checker()
        runner = doctest.DebugRunner(verbose=0,
                                     optionflags=optionflags,
                                     checker=checker)
        for test in finder.find(module, module.__name__):
            if test.examples:  # skip empty doctests
                yield DoctestItem.from_parent(self,
                                              name=test.name,
                                              runner=runner,
                                              dtest=test)
Example #3
0
    def collect(self):
        import numpy as np
        # Copied from pytest
        import doctest
        if self.fspath.basename == "conftest.py":
            module = self.config.pluginmanager._importconftest(self.fspath)
        else:
            try:
                module = self.fspath.pyimport()
            except ImportError:
                if self.config.getvalue('doctest_ignore_import_errors'):
                    pytest.skip('unable to import module %r' % self.fspath)
                else:
                    raise
        # uses internal doctest module parsing mechanism
        finder = doctest.DocTestFinder()
        optionflags = get_optionflags(self)
        runner = doctest.DebugRunner(verbose=0,
                                     optionflags=optionflags,
                                     checker=_get_checker())
        # End copied from pytest

        for method in module.__dict__.values():
            if isinstance(method, np.ufunc) or isinstance(
                    getattr(method, '__wrapped__', None), np.ufunc):
                for test in finder.find(method, module=module):
                    if test.examples:  # skip empty doctests
                        yield DoctestItem(test.name, self, runner, test)
    def collect(self):
        # Adapted from pytest
        import doctest
        if self.fspath.basename == "conftest.py":
            # Copied from pytest-doctestplus
            if PYTEST_GT_5:
                module = self.config.pluginmanager._importconftest(
                    self.fspath, self.config.getoption("importmode"))
            else:
                module = self.config.pluginmanager._importconftest(self.fspath)
        else:
            try:
                module = self.fspath.pyimport()
            except ImportError:
                if self.config.getvalue('doctest_ignore_import_errors'):
                    pytest.skip('unable to import module %r' % self.fspath)
                else:
                    raise
        # uses internal doctest module parsing mechanism
        finder = doctest.DocTestFinder()
        optionflags = get_optionflags(self)
        runner = doctest.DebugRunner(verbose=0,
                                     optionflags=optionflags,
                                     checker=_get_checker())
        # End copied from pytest

        for method in module.__dict__.values():
            if _is_numpy_ufunc(method):
                for test in finder.find(method, module=module):
                    if test.examples:  # skip empty doctests
                        yield DoctestItem.from_parent(self,
                                                      name=test.name,
                                                      runner=runner,
                                                      dtest=test)
Example #5
0
    def collect(self):
        import doctest

        if self.fspath.basename == "conftest.py":
            module = self.config.pluginmanager._importconftest(self.fspath)
        else:
            try:
                # XXX patch pyimport in pytest._pytest.doctest.DoctestModule
                module = _patch_pyimport(self.fspath)
            except ImportError:
                if self.config.getoption('--cython-ignore-import-errors'):
                    pytest.skip('unable to import module %r' % self.fspath)
                else:
                    raise

        # uses internal doctest module parsing mechanism
        finder = doctest.DocTestFinder()
        optionflags = get_optionflags(self)
        checker = None if _get_checker is None else _get_checker()
        runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
                                     checker=checker)
        for test in finder.find(module, module.__name__):
            if test.examples:  # skip empty doctests
                yield DoctestItem(test.name, self, runner, test)