|
69 | 69 | from . import streamlines
|
70 | 70 | from . import viewers
|
71 | 71 |
|
72 |
| -from numpy.testing import Tester |
73 |
| -test = Tester().test |
74 |
| -bench = Tester().bench |
75 |
| -del Tester |
76 |
| - |
77 | 72 | from .pkg_info import get_pkg_info as _get_pkg_info
|
78 | 73 |
|
79 | 74 |
|
80 | 75 | def get_info():
|
81 | 76 | return _get_pkg_info(os.path.dirname(__file__))
|
| 77 | + |
| 78 | + |
| 79 | +def test(label=None, verbose=1, extra_argv=None, |
| 80 | + doctests=False, coverage=False, raise_warnings=None, |
| 81 | + timer=False): |
| 82 | + """ |
| 83 | + Run tests for nibabel using pytest |
| 84 | +
|
| 85 | + The protocol mimics the ``numpy.testing.NoseTester.test()``. |
| 86 | + Not all features are currently implemented. |
| 87 | +
|
| 88 | + Parameters |
| 89 | + ---------- |
| 90 | + label : None |
| 91 | + Unused. |
| 92 | + verbose: int, optional |
| 93 | + Verbosity value for test outputs. Positive values increase verbosity, and |
| 94 | + negative values decrease it. Default is 1. |
| 95 | + extra_argv : list, optional |
| 96 | + List with any extra arguments to pass to pytest. |
| 97 | + doctests: bool, optional |
| 98 | + If True, run doctests in module. Default is False. |
| 99 | + coverage: bool, optional |
| 100 | + If True, report coverage of NumPy code. Default is False. |
| 101 | + (This requires the |
| 102 | + `coverage module <https://nedbatchelder.com/code/modules/coveragehtml>`_). |
| 103 | + raise_warnings : None |
| 104 | + Unused. |
| 105 | + timer : False |
| 106 | + Unused. |
| 107 | +
|
| 108 | + Returns |
| 109 | + ------- |
| 110 | + code : ExitCode |
| 111 | + Returns the result of running the tests as a ``pytest.ExitCode`` enum |
| 112 | + """ |
| 113 | + import pytest |
| 114 | + args = [] |
| 115 | + |
| 116 | + if label is not None: |
| 117 | + raise NotImplementedError("Labels cannot be set at present") |
| 118 | + |
| 119 | + try: |
| 120 | + verbose = int(verbose) |
| 121 | + except ValueError: |
| 122 | + pass |
| 123 | + else: |
| 124 | + if verbose > 0: |
| 125 | + args.append("-" + "v" * verbose) |
| 126 | + elif verbose < 0: |
| 127 | + args.append("-" + "q" * -verbose) |
| 128 | + |
| 129 | + if extra_argv: |
| 130 | + args.extend(extra_argv) |
| 131 | + if doctests: |
| 132 | + args.append("--doctest-modules") |
| 133 | + if coverage: |
| 134 | + args.extend(["--cov", "nibabel"]) |
| 135 | + if raise_warnings: |
| 136 | + raise NotImplementedError("Warning filters are not implemented") |
| 137 | + if timer: |
| 138 | + raise NotImplementedError("Timing is not implemented") |
| 139 | + |
| 140 | + args.extend(["--pyargs", "nibabel"]) |
| 141 | + |
| 142 | + pytest.main(args=args) |
| 143 | + |
| 144 | + |
| 145 | +def bench(label=None, verbose=1, extra_argv=None): |
| 146 | + """ |
| 147 | + Run benchmarks for nibabel using pytest |
| 148 | +
|
| 149 | + The protocol mimics the ``numpy.testing.NoseTester.bench()``. |
| 150 | + Not all features are currently implemented. |
| 151 | +
|
| 152 | + Parameters |
| 153 | + ---------- |
| 154 | + label : None |
| 155 | + Unused. |
| 156 | + verbose: int, optional |
| 157 | + Verbosity value for test outputs. Positive values increase verbosity, and |
| 158 | + negative values decrease it. Default is 1. |
| 159 | + extra_argv : list, optional |
| 160 | + List with any extra arguments to pass to pytest. |
| 161 | +
|
| 162 | + Returns |
| 163 | + ------- |
| 164 | + code : ExitCode |
| 165 | + Returns the result of running the tests as a ``pytest.ExitCode`` enum |
| 166 | + """ |
| 167 | + from pkg_resources import resource_filename |
| 168 | + config = resource_filename("nibabel", "benchmarks/pytest.benchmark.ini") |
| 169 | + args = [] |
| 170 | + if extra_argv is not None: |
| 171 | + args.extend(extra_argv) |
| 172 | + args.extend(["-c", config]) |
| 173 | + test(label, verbose, extra_argv=args) |
0 commit comments