scipy / scipy_doctest

Floating-point aware doctesting
BSD 3-Clause "New" or "Revised" License
5 stars 4 forks source link

FIX: iterable checks longest #162

Closed luxedo closed 2 months ago

luxedo commented 2 months ago

Fixes https://github.com/scipy/scipy_doctest/issues/161 by iterating the longest array

ev-br commented 2 months ago

Nice catch! Could you add a test please.

ATM it's probably easiest to add a case to https://github.com/scipy/scipy_doctest/blob/main/scipy_doctest/tests/module_cases.py

(we'll need to refactor tests into explicitly testing DTChecker, but that's separate)

luxedo commented 2 months ago

I don't know how to create such test. I want to test the failing behavior, so shouldn't I place tests at failure_cases.py?

196 
197     >>> [1, 2, 3]
Expected:
    [1, 2, 3, 4]
Got:
    [1, 2, 3]
ev-br commented 2 months ago

Yes indeed, failure_cases.py or failure_cases_2.py. You probably want something like

--- a/scipy_doctest/tests/failure_cases.py
+++ b/scipy_doctest/tests/failure_cases.py
@@ -15,3 +15,10 @@ def func10():
     >>> import numpy as np
     >>> np.arraY([1, 2, 3])
     """
+
+
+def func_lengths():
+    """
+    >>> [1, 2, 3]
+    [1, 2, 3, 4]
+    """
diff --git a/scipy_doctest/tests/test_testmod.py b/scipy_doctest/tests/test_testmod.py
index 0c0a839..2de341b 100644
--- a/scipy_doctest/tests/test_testmod.py
+++ b/scipy_doctest/tests/test_testmod.py
@@ -99,6 +99,13 @@ def test_user_context():
                 config=config)

+def test_wrong_lengths():
+    config = DTConfig()
+    res, _ = _testmod(failure_cases, strategy=[failure_cases.func_lengths],
+                      config=config)
+    assert res.failed == 1      # or use raise_on_error=True and pytest.raises
+
+
ev-br commented 2 months ago

Minor: as far as commit message acronyms go, FIX: is not a thing. You probably want BUG: going forward.