Commit Graph

261 Commits

Author SHA1 Message Date
Hugo van Kemenade 3b3f8dea57
gh-117225: Move colorize functionality to own internal module (#118283) 2024-05-01 12:27:06 -06:00
Pablo Galindo Salgado 345e1e04ec
gh-112730: Make the test suite resilient to color-activation environment variables (#117672) 2024-04-24 21:25:22 +01:00
Hugo van Kemenade 975081b11e
gh-117225: Add color to doctest output (#117583)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-04-24 14:27:40 +03:00
Nikita Sobolev 4bb7d121bc
gh-117692: Fix `AttributeError` in `DocTestFinder` on wrapped `builtin_or_method` (#117699)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-04-10 10:52:47 +01:00
Malcolm Smith 29829b58a8
gh-117294: Report DocTestCase as skipped if all examples in the doctest are skipped (GH-117297) 2024-03-28 21:59:12 +02:00
Hugo van Kemenade ce00de4c8c
gh-117225: doctest: only print "and X failed" when non-zero, don't pluralise "1 items" (#117228) 2024-03-27 16:46:35 +02:00
Serhiy Storchaka 872cc9957a
gh-115341: Fix loading unit tests with doctests in -OO mode (GH-115342) 2024-02-19 19:03:21 +02:00
Brian Schubert bb791c7728
gh-115392: Fix doctest reporting incorrect line numbers for decorated functions (#115440) 2024-02-14 15:01:27 +00:00
Serhiy Storchaka 8f8f0f97e1
gh-61648: Detect line numbers of properties in doctests (GH-113161) 2023-12-15 15:24:30 +02:00
Irit Katriel fbb9027a03
gh-94722: fix DocTest.__eq__ for case of no line number on one side (#112385) 2023-11-25 17:23:43 +00:00
Nikita Sobolev 18c954849b
gh-111159: Fix `SyntaxError` doctests for non-builtin exception classes (#111541) 2023-11-04 09:54:10 +00:00
Nikita Sobolev fd60549c0a
gh-111159: Fix `doctest` output comparison for exceptions with notes (#111160) 2023-10-21 19:02:00 +01:00
Victor Stinner 4f9b706c6f
gh-108794: doctest counts skipped tests (#108795)
* Add 'skipped' attribute to TestResults.
* Add 'skips' attribute to DocTestRunner.
* Rename private DocTestRunner._name2ft attribute
  to DocTestRunner._stats.
* Use f-string for string formatting.
* Add some tests.
* Document DocTestRunner attributes and its API for statistics.
* Document TestResults class.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-09-02 16:42:07 +02:00
Gertjan van Zwieten 8579327879
gh-107715: Escape class name in regular expression (GH-107716)
This patch escapes the class name before embedding it in the regular expression
for `pat` in `doctest.DocTestFinder._find_lineno`. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return `None` in
this scenario, rather than potentially matching a different class or raising
`re.error` depending on the symbols used.
2023-08-07 18:24:02 +03:00
Steve Dower b5d4347950
gh-86682: Adds sys._getframemodulename as an alternative to using _getframe (GH-99520)
Also updates calls in collections, doctest, enum, and typing modules to use _getframemodulename first when available.
2023-01-13 11:31:06 +00:00
Nikita Sobolev 79c10b7da8
gh-99433: Fix `doctest` failure on `types.MethodWrapperType` (#99434) 2022-12-30 17:25:01 +05:30
Nikita Sobolev 8db2b3b687
bpo-28249: fix `lineno` location for empty `DocTest` instances (GH-30498)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2022-05-19 17:46:15 +02:00
Daniël van Noord 7ba7eae508
bpo-2604: Make doctest.DocTestCase reset globs in teardown (GH-31932)
Co-authored-by: Piet Delport
Co-authored-by: Hugo Lopes Tavares
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-03-22 14:01:15 -07:00
Nikita Sobolev 0fc58c1e05
bpo-46306: simplify `CodeType` attribute access in `doctest.py` (GH-30481)
Assume co_firstlineno always exists on types.CodeType objects.

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-01-08 15:13:42 -05:00
Alex Waygood b1302abcc8
bpo-44904: Fix classmethod property bug in doctest module (GH-28838)
The doctest module raised an error if a docstring contained an example that
attempted to access a classmethod property. (Stacking '@classmethod' on top of
`@property` has been supported since Python 3.9; see
https://docs.python.org/3/howto/descriptor.html#class-methods.)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-10-28 10:48:02 +03:00
Alfred Perlstein 565a31804c
bpo-35753: Fix crash in doctest with unwrap-able functions (#22981)
Ignore objects that inspect.unwrap throws due to
too many wrappers.  This is a very rare case, however
it can easily be surfaced when a module under doctest
imports unitest.mock.call into its namespace.

We simply skip any object that throws this exception.
This should handle the majority of cases.
2021-05-05 19:33:17 +02:00
Peter Donis b36349a647
bpo-43049: Use io.IncrementalNewlineDecoder for doctest newline conversion (GH-24359)
Followup to bpo-1812 and GH-17385.
2021-03-02 11:06:20 -06:00
Brett Cannon 825ac38332
bpo-42133: update parts of the stdlib to fall back to `__spec__.loader` when `__loader__` is missing (#22929) 2020-11-06 18:45:56 -08:00
Peter Donis e0b8101492
bpo-1812: Fix newline conversion when doctest.testfile loads from a package whose loader has a get_data method (GH-17385)
This pull request fixes the newline conversion bug originally reported in bpo-1812. When that issue was originally submitted, the open builtin did not default to universal newline mode; now it does, which makes the issue fix simpler, since the only code path that needs to be changed is the one in doctest._load_testfile where the file is loaded from a package whose loader has a get_data method.
2020-03-26 10:53:16 -05:00
Xtreak 8289e27393 bpo-36406: Handle namespace packages in doctest (GH-12520) 2019-12-13 10:06:53 -08:00
Serhiy Storchaka 1f21eaa15e
bpo-15999: Clean up of handling boolean arguments. (GH-15610)
* Use the 'p' format unit instead of manually called PyObject_IsTrue().
* Pass boolean value instead 0/1 integers to functions that needs boolean.
* Convert some arguments to boolean only once.
2019-09-01 12:16:51 +03:00
Serhiy Storchaka 96aeaec647
bpo-36793: Remove unneeded __str__ definitions. (GH-13081)
Classes that define __str__ the same as __repr__ can
just inherit it from object.
2019-05-06 22:29:40 +03:00
Sanyam Khurana cbb1645993 bpo-24746: Avoid stripping trailing whitespace in doctest fancy diff (#10639) 2019-01-09 05:38:38 -08:00
Serhiy Storchaka 70d56fb525
bpo-25054, bpo-1647489: Added support of splitting on zerowidth patterns. (#4471)
Also fixed searching patterns that could match an empty string.
2017-12-04 14:29:05 +02:00
Serhiy Storchaka 7e4db2f253 bpo-30166: Import command-line parsing modules only when needed. (#1293) 2017-05-04 08:17:47 +03:00
R David Murray 44b548dda8 #27364: fix "incorrect" uses of escape character in the stdlib.
And most of the tools.

Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and
Martin Panter.
2016-09-08 13:59:53 -04:00
Victor Stinner b1511f789e doctest now supports packages
Issue #26641: doctest.DocFileTest and doctest.testfile() now support packages
(module splitted into multiple directories) for the package parameter.
2016-03-30 01:29:05 +02:00
Victor Stinner 84ca9fe145 doctest: fix _module_relative_path() error message
Write the module name rather than <module> in the error message, if module has
no __file__ attribute (ex: package).
2016-03-25 12:50:36 +01:00
Martin Panter 32acc16cda Merge typo and grammar fixes from 3.4 into 3.5 2015-11-14 01:14:25 +00:00
Martin Panter 2e4571a456 Fix a few grammar problems in the documentation and comments 2015-11-14 01:07:43 +00:00
Brett Cannon f299abdafa Issue #23731: Implement PEP 488.
The concept of .pyo files no longer exists. Now .pyc files have an
optional `opt-` tag which specifies if any extra optimizations beyond
the peepholer were applied.
2015-04-13 14:21:02 -04:00
Serhiy Storchaka 34af5023fc Issue #21408: The default __ne__() now returns NotImplemented if __eq__()
returned NotImplemented.  Removed incorrect implementations of __ne__().
2015-01-26 10:04:15 +02:00
Serhiy Storchaka f4b7a02e93 Issue #21408: The default __ne__() now returns NotImplemented if __eq__()
returned NotImplemented.  Removed incorrect implementations of __ne__().
2015-01-26 09:57:07 +02:00
Yury Selivanov b532df62b9 Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa. 2014-12-08 15:00:05 -05:00
Serhiy Storchaka 465e60e654 Issue #22033: Reprs of most Python implemened classes now contain actual
class name instead of hardcoded one.
2014-07-25 23:36:00 +03:00
R David Murray 1976d9bf6d #15916: if there are no docstrings, make empty suite, not an error.
This makes doctest work like unittest: if the test case is empty, that
just means there are zero tests run, it's not an error.  The existing
behavior was broken, since it only gave an error if there were *no*
docstrings, and zero tests run if there were docstrings but none of them
contained tests.  So this makes it self-consistent as well.

Patch by Glenn Jones.
2014-04-14 20:28:36 -04:00
Zachary Ware eee44f28a9 Issue #3158: Provide a couple of fallbacks for in case a method_descriptor
doesn't have __objclass__.
2014-02-06 15:46:38 -06:00
Tim Peters f9a07f2e11 Issue #19138: doctest's IGNORE_EXCEPTION_DETAIL now allows no detail at all. 2013-12-03 21:02:05 -06:00
Zachary Ware a4b7a7548c Issue #3158: doctest can now find doctests in functions and methods
written in C.

As a part of this, a few doctests have been added to the builtins module
(on hex(), oct(), and bin()), a doctest has been fixed (hopefully on all
platforms) on float, and test_builtins now runs doctests in builtins.
2013-11-24 01:19:09 -06:00
Andrew Svetlov 7c1017bfee Fix tests for #11798 2013-08-29 01:24:39 +03:00
Serhiy Storchaka 75674ae8dd Issue #18647: A regular expression in the doctest module rewritten so that
determined minimal width of repeated subexpression is >0 (an empty line was
not matched in any case).
2013-08-19 23:04:33 +03:00
Serhiy Storchaka 1ca66edbc5 Issue #18647: A regular expression in the doctest module rewritten so that
determined minimal width of repeated subexpression is >0 (an empty line was
not matched in any case).
2013-08-19 22:59:31 +03:00
Ezio Melotti 9a3777e525 #18705: merge with 3.3. 2013-08-17 15:53:55 +03:00
Ezio Melotti 30b9d5d3af #18705: fix a number of typos. Patch by Févry Thibault. 2013-08-17 15:50:46 +03:00
R David Murray 5707d508e1 #11390: convert doctest CLI to argparse and add -o and -f options.
This provides a way to specify arbitrary doctest options when using
the CLI interface to process test files, just as one can when calling
testmod or testfile programmatically.
2013-06-23 14:24:13 -04:00