()
| 2784 | |
| 2785 | |
| 2786 | def _test(): |
| 2787 | import argparse |
| 2788 | |
| 2789 | parser = argparse.ArgumentParser(description="doctest runner") |
| 2790 | parser.add_argument('-v', '--verbose', action='store_true', default=False, |
| 2791 | help='print very verbose output for all tests') |
| 2792 | parser.add_argument('-o', '--option', action='append', |
| 2793 | choices=OPTIONFLAGS_BY_NAME.keys(), default=[], |
| 2794 | help=('specify a doctest option flag to apply' |
| 2795 | ' to the test run; may be specified more' |
| 2796 | ' than once to apply multiple options')) |
| 2797 | parser.add_argument('-f', '--fail-fast', action='store_true', |
| 2798 | help=('stop running tests after first failure (this' |
| 2799 | ' is a shorthand for -o FAIL_FAST, and is' |
| 2800 | ' in addition to any other -o options)')) |
| 2801 | parser.add_argument('file', nargs='+', |
| 2802 | help='file containing the tests to run') |
| 2803 | args = parser.parse_args() |
| 2804 | testfiles = args.file |
| 2805 | # Verbose used to be handled by the "inspect argv" magic in DocTestRunner, |
| 2806 | # but since we are using argparse we are passing it manually now. |
| 2807 | verbose = args.verbose |
| 2808 | options = 0 |
| 2809 | for option in args.option: |
| 2810 | options |= OPTIONFLAGS_BY_NAME[option] |
| 2811 | if args.fail_fast: |
| 2812 | options |= FAIL_FAST |
| 2813 | for filename in testfiles: |
| 2814 | if filename.endswith(".py"): |
| 2815 | # It is a module -- insert its dir into sys.path and try to |
| 2816 | # import it. If it is part of a package, that possibly |
| 2817 | # won't work because of package imports. |
| 2818 | dirname, filename = os.path.split(filename) |
| 2819 | sys.path.insert(0, dirname) |
| 2820 | m = __import__(filename[:-3]) |
| 2821 | del sys.path[0] |
| 2822 | failures, _ = testmod(m, verbose=verbose, optionflags=options) |
| 2823 | else: |
| 2824 | failures, _ = testfile(filename, module_relative=False, |
| 2825 | verbose=verbose, optionflags=options) |
| 2826 | if failures: |
| 2827 | return 1 |
| 2828 | return 0 |
| 2829 | |
| 2830 | |
| 2831 | if __name__ == "__main__": |
no test coverage detected