Run modified doctests for the set of `tests`. Parameters ---------- tests : list full_name : str verbose : bool doctest_warnings : bool Returns ------- tuple(bool, list) Tuple of (success, output)
(tests, full_name, verbose, doctest_warnings)
| 768 | |
| 769 | |
| 770 | def _run_doctests(tests, full_name, verbose, doctest_warnings): |
| 771 | """ |
| 772 | Run modified doctests for the set of `tests`. |
| 773 | |
| 774 | Parameters |
| 775 | ---------- |
| 776 | tests : list |
| 777 | |
| 778 | full_name : str |
| 779 | |
| 780 | verbose : bool |
| 781 | doctest_warnings : bool |
| 782 | |
| 783 | Returns |
| 784 | ------- |
| 785 | tuple(bool, list) |
| 786 | Tuple of (success, output) |
| 787 | """ |
| 788 | flags = NORMALIZE_WHITESPACE | ELLIPSIS |
| 789 | runner = DTRunner(full_name, checker=Checker(), optionflags=flags, |
| 790 | verbose=verbose) |
| 791 | |
| 792 | output = io.StringIO(newline='') |
| 793 | success = True |
| 794 | |
| 795 | # Redirect stderr to the stdout or output |
| 796 | tmp_stderr = sys.stdout if doctest_warnings else output |
| 797 | |
| 798 | @contextmanager |
| 799 | def temp_cwd(): |
| 800 | cwd = os.getcwd() |
| 801 | tmpdir = tempfile.mkdtemp() |
| 802 | try: |
| 803 | os.chdir(tmpdir) |
| 804 | yield tmpdir |
| 805 | finally: |
| 806 | os.chdir(cwd) |
| 807 | shutil.rmtree(tmpdir) |
| 808 | |
| 809 | # Run tests, trying to restore global state afterward |
| 810 | cwd = os.getcwd() |
| 811 | with np.errstate(), np.printoptions(), temp_cwd() as tmpdir, \ |
| 812 | redirect_stderr(tmp_stderr): |
| 813 | # try to ensure random seed is NOT reproducible |
| 814 | np.random.seed(None) |
| 815 | |
| 816 | ns = {} |
| 817 | for t in tests: |
| 818 | # We broke the tests up into chunks to try to avoid PSEUDOCODE |
| 819 | # This has the unfortunate side effect of restarting the global |
| 820 | # namespace for each test chunk, so variables will be "lost" after |
| 821 | # a chunk. Chain the globals to avoid this |
| 822 | t.globs.update(ns) |
| 823 | t.filename = short_path(t.filename, cwd) |
| 824 | # Process our options |
| 825 | if any([SKIPBLOCK in ex.options for ex in t.examples]): |
| 826 | continue |
| 827 | fails, successes = runner.run(t, out=output.write, clear_globs=False) |
no test coverage detected