File: test_docstrings.py

package info (click to toggle)
domdf-python-tools 3.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,784 kB
  • sloc: python: 10,838; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# stdlib
import doctest
import inspect
import shutil
from textwrap import indent

# 3rd party
import pytest

# this package
from domdf_python_tools import getters, iterative, pagesizes, secrets, stringlist, utils, words
from domdf_python_tools.utils import redirect_output

VERBOSE = 1

ret = 0


@pytest.mark.parametrize("module", [iterative, getters, secrets, stringlist, utils, words, pagesizes.units])
def test_docstrings(module):
	# Check that we were actually given a module.
	if inspect.ismodule(module):
		print(f"Running doctest in {module!r}".center(shutil.get_terminal_size().columns, '='))
	else:
		raise TypeError(f"testmod: module required; {module!r}")

	with redirect_output(combine=True) as (stdout, stderr):

		# Find, parse, and run all tests in the given module.
		finder = doctest.DocTestFinder()
		runner = doctest.DocTestRunner(verbose=VERBOSE >= 2)

		for test in finder.find(module, module.__name__):
			runner.run(test)

		runner.summarize(verbose=bool(VERBOSE))

	# results = doctest.TestResults(runner.failures, runner.tries)
	print(indent(stdout.getvalue(), "  "))

	if runner.failures:
		pytest.fail(f"{runner.failures} tests failed")