Opened 10 years ago
Closed 5 years ago
#14272 closed defect (wontfix)
Add DocTestFinder to the doctesting framework
Reported by: | David Roe | Owned by: | David Roe |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | doctest framework | Keywords: | |
Cc: | Andrew Mathas, Vincent Delecroix | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #12415 | Stopgaps: |
Description
We should use Python's DocTestFinder to generate doctests from Python files: our current approach misses some doctests that are added dynamically:
sage: from sage.doctest.sources import FileDocTestSource sage: os.chdir(os.path.join(os.environ['SAGE_ROOT'],'devel','sage')) sage: filename1 = 'sage/combinat/partition.py' sage: FDS1 = FileDocTestSource(filename1, True, True, True, False) sage: filename2 = 'sage/combinat/tableau.py' sage: FDS2 = FileDocTestSource(filename2, True, True, True, False) sage: FDS1._test_enough_doctests() There are 18 tests in sage/combinat/partition.py that are not being run Tests on lines 315, 316, 318, 319, 321, 322, 328, 330, 332, 333, 338, 339, 348, 349, 352, 353, 358, 361 are not run sage: FDS2._test_enough_doctests() There are 12 tests in sage/combinat/tableau.py that are not being run Tests on lines 120, 121, 123, 124, 127, 128, 135, 136, 140, 141, 145, 148 are not run
Attachments (1)
Change History (16)
comment:1 Changed 10 years ago by
Dependencies: | → #12415 |
---|
comment:2 Changed 10 years ago by
Component: | doctest → doctest framework |
---|---|
Owner: | changed from Minh Van Nguyen to David Roe |
comment:3 Changed 10 years ago by
Cc: | Andrew Mathas added |
---|
comment:4 follow-up: 5 Changed 10 years ago by
The approach advocated in this ticket would be to get these doctests from the __doc__
attribute of the class after parsing the file. I think that's what doctest.DocTestFinder
does, but I haven't looked into the details so I'm not sure.
comment:5 Changed 10 years ago by
Replying to roed:
The approach advocated in this ticket would be to get these doctests from the
__doc__
attribute of the class after parsing the file. I think that's whatdoctest.DocTestFinder
does, but I haven't looked into the details so I'm not sure.
Thanks for the explanation. I see that I didn't read the ticket very well...
comment:6 Changed 9 years ago by
Milestone: | sage-5.11 → sage-5.12 |
---|
comment:7 Changed 9 years ago by
Milestone: | sage-6.1 → sage-6.2 |
---|
comment:8 Changed 9 years ago by
Milestone: | sage-6.2 → sage-6.3 |
---|
comment:9 Changed 8 years ago by
Milestone: | sage-6.3 → sage-6.4 |
---|
comment:10 Changed 8 years ago by
Cc: | Vincent Delecroix added |
---|
Hello,
I independently opened this discussion on sage-devel. There are cases were Sage is too laxist as
class A: a = ( """ TESTS:: sage: print "Is this a test?" Of course not! """ )
the string above is considered as a doctest!!
Vincent
comment:11 Changed 5 years ago by
I feel like closing this ticket as "wontfix". First of all, the current doctester works quite well (except for GlobalOptions
, but that can be fixed thanks to #23238). It is actually convenient that it works purely syntactically, there is no need to recompile anything to run changed doctests. The current approach also works well with things that don't have a docstring at all, like cdef
functions in Cython.
And Vincent, I think that #23196 fixed your last comment.
comment:13 Changed 5 years ago by
Milestone: | sage-6.4 → sage-duplicate/invalid/wontfix |
---|---|
Status: | new → needs_review |
Fine with me.
comment:14 Changed 5 years ago by
Status: | needs_review → positive_review |
---|
comment:15 Changed 5 years ago by
Resolution: | → wontfix |
---|---|
Status: | positive_review → closed |
All of these doctests appear in a string which is passed as an argument to the GlobalOptions? class. For example, here is part of the "problem" in partition.py:
The string
end_doc
contains all of the untested doc-tests but it is an argument being passed to a class rather than a documentation string. This string will become part of the doc-string for the associated options classes for partitions (resp. tableaux), so doc-testing it would be a good idea.
Arguably, however, doc-tests should not be performed on hard coded strings in the code unless they are actually doc-strings. It is not clear to me how to fix this problem or even if it should be fixed.