Esempio n. 1
0
def ic_testmod(m,
               name=None,
               globs=None,
               verbose=None,
               report=True,
               optionflags=0,
               extraglobs=None,
               raise_on_error=False,
               exclude_empty=False):
    """See original code in doctest.testmod."""
    if name is None:
        name = m.__name__
    finder = DocTestFinder(exclude_empty=exclude_empty)
    if raise_on_error:
        runner = DebugRunner(checker=Py23DocChecker(),
                             verbose=verbose,
                             optionflags=optionflags)
    else:
        runner = DocTestRunner(checker=Py23DocChecker(),
                               verbose=verbose,
                               optionflags=optionflags)
    for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
        runner.run(test)

    if report:
        runner.summarize()

    return doctest.TestResults(runner.failures, runner.tries)
Esempio n. 2
0
    def get_doc_test_cases_from_module(self, name):
        mod = self.import_dotted_name(name)

        finder = DocTestFinder()
        tests = finder.find(mod)

        doc_test_cases = []
        for test in tests:
            doc_test_cases.append(self.make_doc_test_case(test))
        return doc_test_cases
Esempio n. 3
0
def test_testil():
    # nose test generator
    import testil
    from doctest import DocTestFinder, DocTestRunner

    def run(test):
        result = runner.run(test)
        assert not result.failed, (
            "%s of %s examples failed while testing %s"
            % (result.failed, len(test.examples), test.name))

    # Find, parse, and run all tests in this module.
    finder = DocTestFinder()
    runner = DocTestRunner()
    for test in finder.find(testil, "testil"):
        yield run, test
        def check_output(self, want, got, optionflags):
            want, got = self.remove_u(want, got)
            return super(Py23DocChecker, self).check_output(
                want, got, optionflags)

        def output_difference(self, example, got, optionflags):
            example.want, got = self.remove_u(example.want, got)
            return super(Py23DocChecker, self).output_difference(
                example, got, optionflags)

    global master
    m = sys.modules.get('__main__')
    finder = DocTestFinder()
    runner = DocTestRunner(checker=Py23DocChecker())
    for test in finder.find(m, m.__name__):
        runner.run(test)
    runner.summarize()
    import sys
    sys.exit()

    # yapf: disable
    class Cache(object):
        def __init__(self):
            self.cache = {}

        def set(self, k, v, ttl):
            self.cache[k] = v

        def get(self, k):
            return self.cache.get(k, None)