scipy-doctest 1.7.1__tar.gz → 1.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/PKG-INFO +21 -5
  2. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/README.md +19 -3
  3. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/pyproject.toml +1 -1
  4. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/__init__.py +1 -1
  5. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/impl.py +14 -0
  6. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/plugin.py +29 -1
  7. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/failure_cases.py +43 -0
  8. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/module_cases.py +18 -0
  9. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/test_testmod.py +13 -0
  10. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/LICENSE +0 -0
  11. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/__main__.py +0 -0
  12. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/conftest.py +0 -0
  13. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/frontend.py +0 -0
  14. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/__init__.py +0 -0
  15. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/failure_cases_2.py +0 -0
  16. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/finder_cases.py +0 -0
  17. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/finder_cases_2.py +0 -0
  18. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/local_file.txt +0 -0
  19. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/local_file_cases.py +0 -0
  20. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/octave_a.mat +0 -0
  21. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/scipy_ndimage_tutorial_clone.rst +0 -0
  22. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/stopwords_cases.py +0 -0
  23. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/test_finder.py +0 -0
  24. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/test_parser.py +0 -0
  25. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/test_pytest_configuration.py +0 -0
  26. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/test_runner.py +0 -0
  27. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/test_skipmarkers.py +0 -0
  28. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/tests/test_testfile.py +0 -0
  29. {scipy_doctest-1.7.1 → scipy_doctest-1.8.0}/scipy_doctest/util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scipy_doctest
3
- Version: 1.7.1
3
+ Version: 1.8.0
4
4
  Summary: Configurable, whitespace-insensitive, floating-point-aware doctest helpers.
5
5
  Maintainer-email: SciPy developers <scipy-dev@python.org>
6
6
  Requires-Python: >=3.8
@@ -17,7 +17,7 @@ Requires-Dist: furo==2024.8.6 ; extra == "doc"
17
17
  Requires-Dist: myst-parser==4.0.0 ; extra == "doc"
18
18
  Requires-Dist: sphinx==8.1.3 ; extra == "doc"
19
19
  Requires-Dist: sphinx-copybutton==0.5.2 ; extra == "doc"
20
- Requires-Dist: scipy <= 1.14.1 ; extra == "test"
20
+ Requires-Dist: scipy ; extra == "test"
21
21
  Requires-Dist: matplotlib ; extra == "test"
22
22
  Project-URL: Home, https://github.com/scipy/scipy_doctest
23
23
  Provides-Extra: doc
@@ -176,6 +176,22 @@ $ pytest --pyargs <your-package> --doctest-modules --doctest-collect=api
176
176
  See [More fine-grained control](#more-fine-grained-control) section
177
177
  for details on how to customize the behavior.
178
178
 
179
+ ** NOTE ** Currently, `pytest --doctest-modules` only collects doctests and skips
180
+ 'regular' unit tests. This differs from the vanilla `pytest` behavior, which collects
181
+ both doctests and unit tests.
182
+ The behavior will change in a future version: `scipy-doctest==2.0` **will change the
183
+ default** to align with the vanilla `pytest`.
184
+
185
+ To retain the current behavior, use the `--doctest-only-doctests` CLI option:
186
+
187
+ ```
188
+ $ pytest --doctest-modules --doctest-only-doctests
189
+ ```
190
+
191
+ is unambiguous and will behave identically in the current version 1.8 and upcoming
192
+ versions of `scipy-doctest`.
193
+
194
+
179
195
  ### Basic usage
180
196
 
181
197
  The use of `pytest` is optional, and you can use the `doctest` layer API.
@@ -316,11 +332,11 @@ NumPy wraps `scipy-doctest` with the `spin` command
316
332
  $ spin check-docs
317
333
  ```
318
334
 
319
- SciPy wraps `scipy-doctest` with custom `dev.py` commands:
335
+ In SciPy, the name of the `spin` command is `smoke-docs`::
320
336
 
321
337
  ```
322
- $ python dev.py smoke-docs # check docstrings
323
- $ python dev.py smoke-tutorials # ReST user guide tutorials
338
+ $ spin smoke-docs # check docstrings
339
+ $ spin smoke-tutorials # ReST user guide tutorials
324
340
  ```
325
341
 
326
342
  ## Rough edges and sharp bits
@@ -151,6 +151,22 @@ $ pytest --pyargs <your-package> --doctest-modules --doctest-collect=api
151
151
  See [More fine-grained control](#more-fine-grained-control) section
152
152
  for details on how to customize the behavior.
153
153
 
154
+ ** NOTE ** Currently, `pytest --doctest-modules` only collects doctests and skips
155
+ 'regular' unit tests. This differs from the vanilla `pytest` behavior, which collects
156
+ both doctests and unit tests.
157
+ The behavior will change in a future version: `scipy-doctest==2.0` **will change the
158
+ default** to align with the vanilla `pytest`.
159
+
160
+ To retain the current behavior, use the `--doctest-only-doctests` CLI option:
161
+
162
+ ```
163
+ $ pytest --doctest-modules --doctest-only-doctests
164
+ ```
165
+
166
+ is unambiguous and will behave identically in the current version 1.8 and upcoming
167
+ versions of `scipy-doctest`.
168
+
169
+
154
170
  ### Basic usage
155
171
 
156
172
  The use of `pytest` is optional, and you can use the `doctest` layer API.
@@ -291,11 +307,11 @@ NumPy wraps `scipy-doctest` with the `spin` command
291
307
  $ spin check-docs
292
308
  ```
293
309
 
294
- SciPy wraps `scipy-doctest` with custom `dev.py` commands:
310
+ In SciPy, the name of the `spin` command is `smoke-docs`::
295
311
 
296
312
  ```
297
- $ python dev.py smoke-docs # check docstrings
298
- $ python dev.py smoke-tutorials # ReST user guide tutorials
313
+ $ spin smoke-docs # check docstrings
314
+ $ spin smoke-tutorials # ReST user guide tutorials
299
315
  ```
300
316
 
301
317
  ## Rough edges and sharp bits
@@ -25,7 +25,7 @@ dependencies = [
25
25
 
26
26
  [project.optional-dependencies]
27
27
  test = [
28
- "scipy <= 1.14.1", # black-list 1.5.1 ?
28
+ "scipy",
29
29
  "matplotlib"
30
30
  ]
31
31
  doc = [
@@ -3,7 +3,7 @@ Configurable, whitespace-insensitive, floating-point-aware doctest helpers.
3
3
  """
4
4
 
5
5
 
6
- __version__ = "1.7.1"
6
+ __version__ = "1.8.0"
7
7
 
8
8
  try:
9
9
  # register internal modules with pytest; obscure errors galore otherwise
@@ -2,6 +2,7 @@ import re
2
2
  import warnings
3
3
  import inspect
4
4
  import doctest
5
+ import operator
5
6
  from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, IGNORE_EXCEPTION_DETAIL
6
7
  from itertools import zip_longest
7
8
  from sys import version_info
@@ -413,6 +414,19 @@ class DTChecker(doctest.OutputChecker):
413
414
  if is_list_or_tuple and type(a_want) is not type(a_got):
414
415
  return False
415
416
 
417
+ # dicts and other mappings need special treatment
418
+ want_is_dict = hasattr(a_want, 'items')
419
+ got_is_dict = hasattr(a_got, 'items')
420
+ if operator.xor(want_is_dict, got_is_dict):
421
+ # either both are dicts or both are not
422
+ return False
423
+
424
+ if want_is_dict:
425
+ # convert dicts into lists of key-value pairs and retry
426
+ want_items = str(list(a_want.items()))
427
+ got_items = str(list(a_got.items()))
428
+ return self.check_output(want_items, got_items, optionflags)
429
+
416
430
  # ... and defer to numpy
417
431
  strict = self.config.strict_check
418
432
  try:
@@ -29,6 +29,28 @@ def pytest_addoption(parser):
29
29
  dest="collection_strategy"
30
30
  )
31
31
 
32
+ # We cannot add `--doctest-only` option because of
33
+ # https://github.com/pytest-dev/pytest/discussions/13435
34
+ #
35
+ # Therefore, we add a new option, --doctest-only-doctests,
36
+ # which is `true` by default, for now.
37
+ #
38
+ # In v2.0, it the default will become `false`, so that
39
+ #
40
+ # $ pytest --doctest-modules
41
+ #
42
+ # will run both doctests and unit tests, and the way to use the
43
+ # current behavior (only run doctests, skip unit tests) will be
44
+ #
45
+ # $ pytest --doctest-modules --doctest-only-doctests=true
46
+ #
47
+ group.addoption("--doctest-only-doctests",
48
+ action="store",
49
+ default="true",
50
+ help="Whether to only collect doctests, or also collect unit tests, too.",
51
+ choices=("true", "false"),
52
+ dest="doctest_only_doctests"
53
+ )
32
54
 
33
55
  def pytest_configure(config):
34
56
  """
@@ -49,7 +71,13 @@ def pytest_ignore_collect(collection_path, config):
49
71
  This function is used to exclude the 'tests' directory and test modules when
50
72
  the `--doctest-modules` option is used.
51
73
  """
52
- if config.getoption("--doctest-modules"):
74
+ # XXX: in v2.0, --doctest-modules will mean "run both doctests and unit tests",
75
+ # (consistent with vanilla pytest), and the way to retain the current behavior
76
+ # will be to add --doctest-only-doctests=true to the CLI command
77
+ if (
78
+ config.getoption("--doctest-modules") and
79
+ config.getoption("--doctest-only-doctests") == 'true'
80
+ ):
53
81
  path_str = str(collection_path)
54
82
  if "tests" in path_str or "test_" in path_str:
55
83
  return True
@@ -53,3 +53,46 @@ def dtype_mismatch():
53
53
  >>> 3.0
54
54
  3
55
55
  """
56
+
57
+
58
+ def dict_not_dict():
59
+ """
60
+ >>> dict(a=1, b=2)
61
+ ['a', 'b']
62
+ """
63
+
64
+ def dict_not_dict_2():
65
+ """
66
+ >>> [('a', 1), ('b', 2)]
67
+ {'a': 1, 'b': 2}
68
+ """
69
+
70
+
71
+ def dict_wrong_keys():
72
+ """
73
+ >>> dict(a=1, b=2)
74
+ {'c': 1, 'd': 2}
75
+ """
76
+
77
+
78
+ def dict_wrong_values():
79
+ """
80
+ >>> dict(a=1, b=2)
81
+ {'a': -1, 'b': -2}
82
+ """
83
+
84
+
85
+ def dict_wrong_values_np():
86
+ """
87
+ >>> import numpy as np
88
+ >>> dict(a=1, b=np.arange(3)/3)
89
+ {'a': 1, 'b': array([0, 0.335, 0.669])}
90
+ """
91
+
92
+
93
+ def dict_nested_wrong_values_np():
94
+ """
95
+ >>> import numpy as np
96
+ >>> dict(a=1, b=dict(blurb=np.arange(3)/3))
97
+ {'a': 1, 'b': {'blurb': array([0, 0.335, 0.669])}}
98
+ """
@@ -242,3 +242,21 @@ def array_and_list_2():
242
242
  >>> [1, 2, 3]
243
243
  array([1, 2, 3])
244
244
  """
245
+
246
+
247
+ def two_dicts():
248
+ """
249
+ >>> import numpy as np
250
+ >>> dict(a=0, b=1)
251
+ {'a': 0, 'b': 1}
252
+ >>> {'a': 0., 'b': np.arange(3) / 3 }
253
+ {'a': 0.0, 'b': array([0, 0.33333333, 0.66666667])}
254
+ """
255
+
256
+ def nested_dicts():
257
+ """
258
+ >>> import numpy as np
259
+ >>> {'a': 1.0, 'b': dict(blurb=np.arange(3)/3)}
260
+ {'a': 1.0, 'b': {'blurb': array([0, 0.33333333, 0.66666667])}}
261
+ """
262
+
@@ -15,6 +15,7 @@ import pytest
15
15
 
16
16
  try:
17
17
  import scipy # noqa
18
+ from scipy import stats # https://github.com/scipy/scipy_doctest/issues/184
18
19
  HAVE_SCIPY = True
19
20
  except Exception:
20
21
  HAVE_SCIPY = False
@@ -116,6 +117,18 @@ def test_tuple_and_list():
116
117
  config=config)
117
118
  assert res.failed == 2
118
119
 
120
+ def test_dict():
121
+ config = DTConfig()
122
+ res, _ = _testmod(failure_cases,
123
+ strategy=[failure_cases.dict_not_dict,
124
+ failure_cases.dict_not_dict_2,
125
+ failure_cases.dict_wrong_keys,
126
+ failure_cases.dict_wrong_values,
127
+ failure_cases.dict_wrong_values_np,
128
+ failure_cases.dict_nested_wrong_values_np],
129
+ config=config)
130
+ assert res.failed == 6
131
+
119
132
 
120
133
  @pytest.mark.parametrize('strict, num_fails', [(True, 1), (False, 0)])
121
134
  class TestStrictDType:
File without changes