Python doctest.testfile() Examples

The following are code examples for showing how to use doctest.testfile(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: Alexa-Ecovacs   Author: EtienneMD   File: doctest.py    MIT License 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {'__name__': '__main__'}

        optionflags = get_optionflags(self)
        runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
                                     checker=_get_checker())
        _fix_spoof_python2(runner, encoding)

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 2
Project: python-netsurv   Author: sofia-netsurv   File: doctest.py    MIT License 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {"__name__": "__main__"}

        optionflags = get_optionflags(self)

        runner = _get_runner(
            verbose=0,
            optionflags=optionflags,
            checker=_get_checker(),
            continue_on_failure=_get_continue_on_failure(self.config),
        )

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 3
Project: python-netsurv   Author: sofia-netsurv   File: doctest.py    MIT License 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {"__name__": "__main__"}

        optionflags = get_optionflags(self)

        runner = _get_runner(
            verbose=0,
            optionflags=optionflags,
            checker=_get_checker(),
            continue_on_failure=_get_continue_on_failure(self.config),
        )

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 4
Project: pytest-sphinx   Author: thisch   File: pytest_sphinx.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def collect(self):
        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        name = self.fspath.basename

        optionflags = _pytest.doctest.get_optionflags(self)
        runner = SphinxDocTestRunner(verbose=0,
                                     optionflags=optionflags,
                                     checker=_pytest.doctest._get_checker())

        test = doctest.DocTest(examples=docstring2examples(text),
                               globs={},
                               name=name,
                               filename=name,
                               lineno=0,
                               docstring=text)

        if test.examples:
            yield _pytest.doctest.DoctestItem(
                test.name, self, runner, test) 
Example 5
Project: 2019-1-OSS-L1   Author: 19-1-skku-oss   File: doctest.py    MIT License 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {"__name__": "__main__"}

        optionflags = get_optionflags(self)

        runner = _get_runner(
            verbose=0,
            optionflags=optionflags,
            checker=_get_checker(),
            continue_on_failure=_get_continue_on_failure(self.config),
        )
        _fix_spoof_python2(runner, encoding)

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 6
Project: pytest   Author: pytest-dev   File: doctest.py    MIT License 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {"__name__": "__main__"}

        optionflags = get_optionflags(self)

        runner = _get_runner(
            verbose=False,
            optionflags=optionflags,
            checker=_get_checker(),
            continue_on_failure=_get_continue_on_failure(self.config),
        )

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 7
Project: linear_neuron   Author: uglyboxer   File: doctest.py    MIT License 6 votes vote down vote up
def runtest(self):
        import doctest
        fixture_request = _setup_fixtures(self)

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        text = self.fspath.read()
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = dict(getfixture=fixture_request.getfuncargvalue)
        if '__name__' not in globs:
            globs['__name__'] = '__main__'

        optionflags = get_optionflags(self)
        runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
                                     checker=_get_unicode_checker())

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        _check_all_skipped(test)
        runner.run(test) 
Example 8
Project: management-api   Author: rancher   File: doctest.py    Apache License 2.0 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        text = self.fspath.read()
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {'__name__': '__main__'}


        optionflags = get_optionflags(self)
        runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
                                     checker=_get_checker())

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 9
Project: management-api   Author: rancher   File: doctest.py    Apache License 2.0 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        text = self.fspath.read()
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {'__name__': '__main__'}


        optionflags = get_optionflags(self)
        runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
                                     checker=_get_checker())

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 10
Project: Mastering-Object-Oriented-Python-Second-Edition   Author: PacktPublishing   File: test_all.py    MIT License 6 votes vote down vote up
def run_doctest_suite(pkg_mod_iter: Iterable[Tuple[Path, Iterable[Path]]]) -> None:
    """Doctest each module individually. With a few exclusions.

    Might be simpler to use doctest.testfile()? However, the examples aren't laid out for this.
    """
    for package, module_iter in pkg_mod_iter:
        print()
        print(package.name)
        print("="*len(package.name))
        print()
        for module_path in module_iter:
            if module_path.stem in DOCTEST_EXCLUDE:
                print(f"Excluding {module_path}")
                continue
            result = subprocess.run(['python3', '-m', 'doctest', str(module_path)])
            if result.returncode != 0:
                sys.exit(f"Failure {result!r} in {module_path}") 
Example 11
Project: Namsor-API-Wrapper-Python   Author: JosephPallipadan   File: doctest.py    MIT License 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {"__name__": "__main__"}

        optionflags = get_optionflags(self)

        runner = _get_runner(
            verbose=0,
            optionflags=optionflags,
            checker=_get_checker(),
            continue_on_failure=_get_continue_on_failure(self.config),
        )

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 12
Project: tesla-alfred-workflow   Author: ejsuncy   File: doctest.py    MIT License 6 votes vote down vote up
def collect(self):
        import doctest

        # inspired by doctest.testfile; ideally we would use it directly,
        # but it doesn't support passing a custom checker
        encoding = self.config.getini("doctest_encoding")
        text = self.fspath.read_text(encoding)
        filename = str(self.fspath)
        name = self.fspath.basename
        globs = {"__name__": "__main__"}

        optionflags = get_optionflags(self)

        runner = _get_runner(
            verbose=0,
            optionflags=optionflags,
            checker=_get_checker(),
            continue_on_failure=_get_continue_on_failure(self.config),
        )
        _fix_spoof_python2(runner, encoding)

        parser = doctest.DocTestParser()
        test = parser.get_doctest(text, globs, name, filename, 0)
        if test.examples:
            yield DoctestItem(test.name, self, runner, test) 
Example 13
Project: pyblish-win   Author: pyblish   File: test_zipimport.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 14
Project: pyblish-win   Author: pyblish   File: test_doctest.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> open(fn, 'w').write('Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    >>> doctest.testfile(fn, False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> open(fn, 'w').write('Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    >>> doctest.testfile(fn, False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

"""

# old_test1, ... used to live in doctest.py, but cluttered it.  Note
# that these use the deprecated doctest.Tester, so should go away (or
# be rewritten) someday. 
Example 15
Project: NiujiaoDebugger   Author: MrSrc   File: test_zipimport.py    GNU General Public License v3.0 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 16
Project: NiujiaoDebugger   Author: MrSrc   File: test_doctest.py    GNU General Public License v3.0 5 votes vote down vote up
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...    f.write(b'Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    35
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...     f.write(b'Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    30
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

""" 
Example 17
Project: ironpython2   Author: IronLanguages   File: test_zipimport.py    Apache License 2.0 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 18
Project: ironpython2   Author: IronLanguages   File: test_doctest.py    Apache License 2.0 5 votes vote down vote up
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...     f.write('Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...     f.write('Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

"""

# old_test1, ... used to live in doctest.py, but cluttered it.  Note
# that these use the deprecated doctest.Tester, so should go away (or
# be rewritten) someday. 
Example 19
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_zipimport.py    GNU General Public License v3.0 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 20
Project: pyskiplist   Author: geertj   File: documentation.py    MIT License 5 votes vote down vote up
def test_readme(self):
        doctest.testfile(os.path.join(self.topdir, 'README.rst'),
                         module_relative=False, verbose=self.verbose > 2) 
Example 21
Project: cysignals   Author: sagemath   File: rundoctests.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def testfile(file):
    # Child process
    try:
        if sys.platform == 'darwin':
            from cysignals.signals import _setup_alt_stack
            _setup_alt_stack()
        failures, _ = doctest.testfile(file, module_relative=False, optionflags=flags, parser=parser)
        if not failures:
            os._exit(0)
    except BaseException as E:
        print(E)
    finally:
        os._exit(23) 
Example 22
Project: mappers   Author: dry-python   File: mddoctest.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _main():
    apps.populate(settings.INSTALLED_APPS)
    _setup()
    markdown_files = glob("**/*.md", recursive=True)
    exit_code = 0
    for markdown_file in markdown_files:
        failed, attempted = testfile(markdown_file, module_relative=False)
        exit_code += failed
    sys.exit(exit_code) 
Example 23
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_zipimport.py    GNU General Public License v2.0 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 24
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_doctest.py    GNU General Public License v2.0 5 votes vote down vote up
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...    f.write(b'Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    35
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...     f.write(b'Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    30
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

""" 
Example 25
Project: oss-ftp   Author: aliyun   File: test_zipimport.py    MIT License 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 26
Project: oss-ftp   Author: aliyun   File: test_doctest.py    MIT License 5 votes vote down vote up
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> open(fn, 'w').write('Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    >>> doctest.testfile(fn, False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> open(fn, 'w').write('Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    >>> doctest.testfile(fn, False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

"""

# old_test1, ... used to live in doctest.py, but cluttered it.  Note
# that these use the deprecated doctest.Tester, so should go away (or
# be rewritten) someday. 
Example 27
Project: pyxtf   Author: pktrigg   File: shapefile.py    MIT License 5 votes vote down vote up
def test():
    import doctest
    doctest.NORMALIZE_WHITESPACE = 1
    doctest.testfile("README.txt", verbose=1) 
Example 28
Project: stories   Author: dry-python   File: mddoctest.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main():
    apps.populate(settings.INSTALLED_APPS)
    setup()
    markdown_files = glob("**/*.md", recursive=True)
    exit_code = 0
    for markdown_file in markdown_files:
        failed, attempted = testfile(markdown_file, module_relative=False)
        exit_code += failed
    sys.exit(exit_code) 
Example 29
Project: pypedream   Author: garywu   File: __init__.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_15(self):
        try:            
            os.chdir('../docs')
            
            doctest_f_name = 'build/text/doctest_reference.txt'
            if os.path.exists(doctest_f_name):
                os.remove(doctest_f_name)
            os.system('make text')
            num_fails, num_tests = doctest.testfile(doctest_f_name)
        finally:        
            os.chdir('../tests')
        self.assertGreater(num_tests, 0)            
        self.assertEqual(num_fails, 0) 
Example 30
Project: clatter   Author: delgadom   File: test_readme.py    MIT License 5 votes vote down vote up
def test_readme():
    errs, _ = doctest.testfile('../README.rst', report=True)
    assert not errs 
Example 31
Project: beniget   Author: serge-sans-paille   File: doc.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_beniget_readme(self):
        failed, _ = doctest.testfile(os.path.join("..", "README.rst"))
        self.assertEqual(failed, 0) 
Example 32
Project: Hot   Author: dsolimando   File: test_zipimport.py    GNU General Public License v3.0 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 33
Project: notebooks   Author: fluentpython   File: sentence_runner.py    MIT License 5 votes vote down vote up
def test(cls, verbose=False):

    res = doctest.testfile(
            TEST_FILE,
            globs={'Sentence': cls},
            verbose=verbose,
            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)
    tag = 'FAIL' if res.failed else 'OK'
    print(TEST_MSG.format(cls.__module__, res, tag)) 
Example 34
Project: notebooks   Author: fluentpython   File: iso2709.py    MIT License 5 votes vote down vote up
def test():
    import doctest
    doctest.testfile('iso2709_test.txt') 
Example 35
Project: notebooks   Author: fluentpython   File: aritprog_runner.py    MIT License 5 votes vote down vote up
def test(gen_factory, verbose=False):
    res = doctest.testfile(
            TEST_FILE,
            globs={'aritprog_gen': gen_factory},
            verbose=verbose,
            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)
    tag = 'FAIL' if res.failed else 'OK'
    print(TEST_MSG.format(gen_factory.__module__, res, tag)) 
Example 36
Project: notebooks   Author: fluentpython   File: tombola_runner.py    MIT License 5 votes vote down vote up
def test(cls, verbose=False):

    res = doctest.testfile(
            TEST_FILE,
            globs={'ConcreteTombola': cls},  # <5>
            verbose=verbose,
            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)
    tag = 'FAIL' if res.failed else 'OK'
    print(TEST_MSG.format(cls.__name__, res, tag))  # <6> 
Example 37
Project: django-ca   Author: mathiasertl   File: tests_profiles.py    GNU General Public License v3.0 5 votes vote down vote up
def test_python_intro(self):
        doctest.testfile('../../../docs/source/python/profiles.rst', globs=self.get_globs()) 
Example 38
Project: django-ca   Author: mathiasertl   File: tests_docs.py    GNU General Public License v3.0 5 votes vote down vote up
def test_python_intro(self):
        doctest.testfile('%s/python/intro.rst' % base, globs=self.get_globs()) 
Example 39
Project: django-ca   Author: mathiasertl   File: tests_docs.py    GNU General Public License v3.0 5 votes vote down vote up
def test_python_models(self):
        doctest.testfile('%s/python/models.rst' % base, globs=self.get_globs()) 
Example 40
Project: opac-airflow   Author: scieloorg   File: iso2709.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test():
    import doctest

    doctest.testfile("iso2709_test.txt") 
Example 41
Project: spyder-doctest-plugin   Author: dougthor42   File: doctestgui.py    MIT License 5 votes vote down vote up
def run_doctest(self, filename):
        """
        Actually runs doctest on the file
        """
        import doctest
        fail_count, test_count = doctest.testfile(filename)
        print(fail_count, test_count) 
Example 42
Project: randomsheetmusic   Author: musescore   File: testDocumentation.py    MIT License 5 votes vote down vote up
def main(runOne=False):
    totalTests = 0
    totalFailures = 0
    
    timeStart = time.time()
    for mt in getDocumentationFiles(runOne):        
        print(mt.module + ":", end="")
        try:
            (failcount, testcount) = doctest.testfile(mt.fullModulePath, module_relative = False, optionflags = doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
            if failcount > 0:
                print("%s had %d failures in %d tests" % (mt.module, failcount, testcount))
            elif testcount == 0:
                print("no tests")
            else:
                print("all %d tests ran successfully" % (testcount))
            totalTests += testcount
            totalFailures += failcount
        except Exception as e:
            print("failed miserably! %s" % str(e))
            import traceback
            tb = traceback.format_exc()
            print("Here's the traceback for the exeception: \n%s" % (tb))


    elapsedTime = time.time() - timeStart
    print("Ran %d tests (%d failed) in %.4f seconds" % (totalTests, totalFailures, elapsedTime)) 
Example 43
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_zipimport.py    GNU General Public License v3.0 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True]) 
Example 44
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_doctest.py    GNU General Public License v3.0 5 votes vote down vote up
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...    f.write(b'Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    35
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...     f.write(b'Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    30
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

""" 
Example 45
Project: example-code-2e   Author: fluentpython   File: sentence_runner.py    MIT License 5 votes vote down vote up
def test(cls, verbose=False):

    res = doctest.testfile(
            TEST_FILE,
            globs={'Sentence': cls},
            verbose=verbose,
            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)
    tag = 'FAIL' if res.failed else 'OK'
    print(TEST_MSG.format(cls.__module__, res, tag)) 
Example 46
Project: example-code-2e   Author: fluentpython   File: iso2709.py    MIT License 5 votes vote down vote up
def test():
    import doctest
    doctest.testfile('iso2709_test.txt') 
Example 47
Project: example-code-2e   Author: fluentpython   File: aritprog_runner.py    MIT License 5 votes vote down vote up
def test(gen_factory, verbose=False):
    res = doctest.testfile(
            TEST_FILE,
            globs={'aritprog_gen': gen_factory},
            verbose=verbose,
            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)
    tag = 'FAIL' if res.failed else 'OK'
    print(TEST_MSG.format(gen_factory.__module__, res, tag)) 
Example 48
Project: example-code-2e   Author: fluentpython   File: tombola_runner.py    MIT License 5 votes vote down vote up
def test(cls, verbose=False):

    res = doctest.testfile(
            TEST_FILE,
            globs={'ConcreteTombola': cls},  # <5>
            verbose=verbose,
            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)
    tag = 'FAIL' if res.failed else 'OK'
    print(TEST_MSG.format(cls.__name__, res, tag))  # <6> 
Example 49
Project: darkc0de-old-stuff   Author: tuwid   File: test_doc.py    GNU General Public License v3.0 5 votes vote down vote up
def testDoc(filename, name=None):
    print "--- %s: Run tests" % filename
    failure, nb_test = testfile(
        filename, optionflags=ELLIPSIS, name=name)
    if failure:
        exit(1)
    print "--- %s: End of tests" % filename 
Example 50
Project: cells   Author: AlesTsurko   File: test_zipimport.py    MIT License 5 votes vote down vote up
def doDoctestFile(self, module):
        log = []
        old_master, doctest.master = doctest.master, None
        try:
            doctest.testfile(
                'xyz.txt', package=module, module_relative=True,
                globs=locals()
            )
        finally:
            doctest.master = old_master
        self.assertEqual(log,[True])