Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'trac/public/tests/doctests_pytest' into…
Browse files Browse the repository at this point in the history
… public/tests/pytest_wrong_test_methods
  • Loading branch information
tobiasdiez committed Mar 25, 2022
2 parents dec7b7b + 01f376c commit 1b7da1b
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 41 deletions.
9 changes: 9 additions & 0 deletions src/bin/sage-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class CoverageResults:
if not docstring:
self.no_doc.append(fullname)
return

if "pytest" in docstring:
self.good.append(fullname)
return

if "sage: " not in docstring:
self.no_test.append(fullname)
return
Expand Down Expand Up @@ -276,6 +281,10 @@ def go(filename):
or filename.endswith('.sage')):
return

# Filter pytest files which are not supposed to have doctests
if filename.endswith('_test.py'):
return

with open(filename, 'r') as f:
cr = CoverageResults(filename).check_file(f)
bad = cr.no_doc or cr.no_test or cr.possibly_wrong
Expand Down
7 changes: 0 additions & 7 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
from typing import Any, List
import pytest

# Ignore a few test files that are (not yet) using pytest
collect_ignore = [
"sage/misc/nested_class_test.py",
"sage/repl/rich_output/backend_test.py",
"sage/tests/deprecation_test.py"
]


def pytest_collection_modifyitems(
session: pytest.Session, config: pytest.Config, items: List[pytest.Item]
Expand Down
6 changes: 6 additions & 0 deletions src/doc/en/developer/coding_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,12 @@ information. You can use the existing functions of Sage as templates.
However, lines only containing double colons `::` do not
end "TESTS" blocks.

Sometimes (but rarely) one has private or protected methods that don't need a
proper ``EXAMPLES`` doctest. In these cases, one can either write traditional
doctest using the ``TESTS`` block or use pytest to test the method.
In the latter case, one has to add ``TESTS: pytest`` to the docstring, so that
the method is explicitly marked as tested.

Note about Sphinx directives vs. other blocks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion src/doc/en/reference/misc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Testing

sage/misc/sage_unittest
sage/misc/random_testing
sage/misc/nested_class_test
sage/misc/test_nested_class

Benchmarking and Profiling
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion src/doc/en/reference/repl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Display Backend Infrastructure
sage/repl/rich_output/output_catalog

sage/repl/rich_output/backend_base
sage/repl/rich_output/backend_test
sage/repl/rich_output/test_backend
sage/repl/rich_output/backend_doctest
sage/repl/rich_output/backend_ipython

Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ class ElementMethods:
reveal some glitches in their implementation, in particular around
class naming and introspection. Sage currently works around the
more annoying ones but some remain visible. See
e.g. :mod:`sage.misc.nested_class_test`.
e.g. :mod:`sage.misc.test_nested_class`.
Let us now look at the categories of ``C``::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def process_docstring_module_title(app, what, name, obj, options, docstringlines
break

skip_picklability_check_modules = [
#'sage.misc.nested_class_test', # for test only
#'sage.misc.test_nested_class', # for test only
'sage.misc.latex',
'sage.misc.explain_pickle',
'__builtin__',
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/nested_class.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This module provides two utilities to workaround this issue:
- :class:`NestedClassMetaclass` is a metaclass ensuring that
:func:`nested_pickle` is called on a class upon creation.
See also :mod:`sage.misc.nested_class_test`.
See also :mod:`sage.misc.test_nested_class`.
.. NOTE::
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/sageinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2310,12 +2310,12 @@ def sage_getsourcelines(obj):
use a dummy parent class that has defined an element class by a
nested class definition::
sage: from sage.misc.nested_class_test import TestNestedParent
sage: from sage.misc.test_nested_class import TestNestedParent
sage: from sage.misc.sageinspect import sage_getsource
sage: P = TestNestedParent()
sage: E = P.element_class
sage: E.__bases__
(<class 'sage.misc.nested_class_test.TestNestedParent.Element'>,
(<class 'sage.misc.test_nested_class.TestNestedParent.Element'>,
<class 'sage.categories.sets_cat.Sets.element_class'>)
sage: print(sage_getsource(E))
class Element(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Currently pickling fails for parents using nested classes (typically
for categories), but deriving only from Parent::
sage: from sage.misc.nested_class_test import TestParent1, TestParent2, TestParent3, TestParent4
sage: from sage.misc.test_nested_class import TestParent1, TestParent2, TestParent3, TestParent4
sage: P = TestParent1()
sage: TestSuite(P).run()
Failure ...
Expand Down Expand Up @@ -59,8 +59,8 @@ def __init__(self):
"""
EXAMPLES::
sage: sage.misc.nested_class_test.TestParent1()
<sage.misc.nested_class_test.TestParent1_with_category object at ...>
sage: sage.misc.test_nested_class.TestParent1()
<sage.misc.test_nested_class.TestParent1_with_category object at ...>
"""
from sage.categories.sets_cat import Sets
Parent.__init__(self, category = Sets())
Expand All @@ -74,7 +74,7 @@ def __init__(self):
"""
EXAMPLES::
sage: sage.misc.nested_class_test.TestParent2()
sage: sage.misc.test_nested_class.TestParent2()
Traceback (most recent call last):
...
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Expand All @@ -92,8 +92,8 @@ def __init__(self):
"""
EXAMPLES::
sage: sage.misc.nested_class_test.TestParent3()
<sage.misc.nested_class_test.TestParent3_with_category object at ...>
sage: sage.misc.test_nested_class.TestParent3()
<sage.misc.test_nested_class.TestParent3_with_category object at ...>
"""
from sage.categories.sets_cat import Sets
Parent.__init__(self, category = Sets())
Expand All @@ -107,8 +107,8 @@ def __init__(self):
"""
EXAMPLES::
sage: sage.misc.nested_class_test.TestParent4()
<sage.misc.nested_class_test.TestParent4_with_category object at ...>
sage: sage.misc.test_nested_class.TestParent4()
<sage.misc.test_nested_class.TestParent4_with_category object at ...>
"""
from sage.categories.sets_cat import Sets
Parent.__init__(self, category=Sets())
Expand All @@ -117,7 +117,7 @@ def __eq__(self, other):
"""
EXAMPLES::
sage: from sage.misc.nested_class_test import TestParent4
sage: from sage.misc.test_nested_class import TestParent4
sage: TestParent4() == TestParent4()
True
"""
Expand All @@ -127,7 +127,7 @@ def __ne__(self, other):
"""
EXAMPLES::
sage: from sage.misc.nested_class_test import TestParent4
sage: from sage.misc.test_nested_class import TestParent4
sage: TestParent4() != TestParent4()
False
"""
Expand All @@ -139,7 +139,7 @@ def __hash__(self):
EXAMPLES::
sage: from sage.misc.nested_class_test import TestParent4
sage: from sage.misc.test_nested_class import TestParent4
sage: hash(TestParent4()) == hash(TestParent4())
True
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/repl/rich_output/backend_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Subclass the rich output container to attach your backend-specific
functionality. Then :meth:`~BackendBase.display_immediately` will
receive instances of your subclass. See
:class:`~sage.repl.rich_output.backend_test.BackendTest` for an
:class:`~sage.repl.rich_output.test_backend.BackendTest` for an
example of how this is done.
You can also mix both ways of implementing different rich output types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
sage: from sage.repl.rich_output import get_display_manager
sage: dm = get_display_manager()
sage: from sage.repl.rich_output.backend_test import BackendTest, TestObject
sage: from sage.repl.rich_output.test_backend import BackendTest, TestObject
sage: doctest_backend = dm.switch_backend(BackendTest())
sage: dm
The Sage display manager using the test backend
sage: dm._output_promotions
{<class 'sage.repl.rich_output.output_basic.OutputPlainText'>:
<class 'sage.repl.rich_output.backend_test.TestOutputPlainText'>}
<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>}
sage: dm.displayhook(1/2)
1/2 [TestOutputPlainText]
TestOutputPlainText container
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(self, *args, **kwds):
EXAMPLES::
sage: from sage.repl.rich_output.backend_test import TestOutputPlainText
sage: from sage.repl.rich_output.test_backend import TestOutputPlainText
sage: TestOutputPlainText()
Traceback (most recent call last):
...
Expand All @@ -81,7 +81,7 @@ def print_to_stdout(self):
sage: test_output = dm.displayhook(123)
123 [TestOutputPlainText]
sage: type(test_output)
<class 'sage.repl.rich_output.backend_test.TestOutputPlainText'>
<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>
sage: test_output.print_to_stdout()
123 [TestOutputPlainText]
"""
Expand All @@ -103,7 +103,7 @@ def _repr_(self):
EXAMPLES::
sage: from sage.repl.rich_output.backend_test import TestObject
sage: from sage.repl.rich_output.test_backend import TestObject
sage: obj = TestObject()
sage: obj._repr_()
'called the _repr_ method'
Expand All @@ -119,7 +119,7 @@ def _rich_repr_(self, display_manager):
EXAMPLES::
sage: display_manager = sage.repl.rich_output.get_display_manager()
sage: from sage.repl.rich_output.backend_test import TestObject
sage: from sage.repl.rich_output.test_backend import TestObject
sage: obj = TestObject()
sage: rich_output = obj._rich_repr_(display_manager); rich_output
OutputPlainText container
Expand Down Expand Up @@ -157,15 +157,15 @@ def supported_output(self):
OUTPUT:
Iterable of output container classes. Only the
:class:`~sage.repl.rich_repr.backend_test.TestOutputPlainText`
:class:`~sage.repl.rich_repr.test_backend.TestOutputPlainText`
output container is supported by the test backend.
EXAMPLES::
sage: display_manager = sage.repl.rich_output.get_display_manager()
sage: backend = display_manager._backend
sage: list(backend.supported_output())
[<class 'sage.repl.rich_output.backend_test.TestOutputPlainText'>]
[<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>]
The output of this method is used by the display manager to
set up the actual supported outputs. Compare::
Expand Down Expand Up @@ -193,7 +193,7 @@ def display_immediately(self, plain_text, rich_output):
sage: from sage.repl.rich_output.output_basic import OutputPlainText
sage: plain_text = OutputPlainText.example()
sage: from sage.repl.rich_output.backend_test import BackendTest
sage: from sage.repl.rich_output.test_backend import BackendTest
sage: backend = BackendTest()
sage: backend.display_immediately(plain_text, plain_text)
Example plain text output
Expand Down
2 changes: 1 addition & 1 deletion src/sage/structure/element_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ cdef class ElementWrapper(Element):
Check that elements of equal-but-not-identical parents compare
properly (see :trac:`19488`)::
sage: from sage.misc.nested_class_test import TestParent4
sage: from sage.misc.test_nested_class import TestParent4
sage: P = TestParent4()
sage: Q = TestParent4()
sage: P == Q
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
EXAMPLES::
sage: import sage.tests.deprecation_test
sage: sage.tests.deprecation_test.function_old()
sage: import sage.tests.test_deprecation
sage: sage.tests.test_deprecation.function_old()
doctest:...: DeprecationWarning: function_old is deprecated. Please
use sage.tests.deprecation_test.function_new instead.
use sage.tests.test_deprecation.function_new instead.
See http://trac.sagemath.org/12345 for details.
"""
from sage.misc.superseded import deprecated_function_alias
Expand All @@ -18,10 +18,10 @@ def function_new():
EXAMPLES::
sage: from sage.tests.deprecation_test import function_old
sage: from sage.tests.test_deprecation import function_old
sage: function_old()
doctest:...: DeprecationWarning: function_old is deprecated. Please
use sage.tests.deprecation_test.function_new instead.
use sage.tests.test_deprecation.function_new instead.
See http://trac.sagemath.org/12345 for details.
"""
pass
Expand Down

0 comments on commit 1b7da1b

Please sign in to comment.