|
| 1 | +# This module is used in `test_doctest`. |
| 2 | +# It must not have a docstring. |
| 3 | + |
| 4 | +def func_with_docstring(): |
| 5 | + """Some unrelated info.""" |
| 6 | + |
| 7 | + |
| 8 | +def func_without_docstring(): |
| 9 | + pass |
| 10 | + |
| 11 | + |
| 12 | +def func_with_doctest(): |
| 13 | + """ |
| 14 | + This function really contains a test case. |
| 15 | +
|
| 16 | + >>> func_with_doctest.__name__ |
| 17 | + 'func_with_doctest' |
| 18 | + """ |
| 19 | + return 3 |
| 20 | + |
| 21 | + |
| 22 | +class ClassWithDocstring: |
| 23 | + """Some unrelated class information.""" |
| 24 | + |
| 25 | + |
| 26 | +class ClassWithoutDocstring: |
| 27 | + pass |
| 28 | + |
| 29 | + |
| 30 | +class ClassWithDoctest: |
| 31 | + """This class really has a test case in it. |
| 32 | +
|
| 33 | + >>> ClassWithDoctest.__name__ |
| 34 | + 'ClassWithDoctest' |
| 35 | + """ |
| 36 | + |
| 37 | + |
| 38 | +class MethodWrapper: |
| 39 | + def method_with_docstring(self): |
| 40 | + """Method with a docstring.""" |
| 41 | + |
| 42 | + def method_without_docstring(self): |
| 43 | + pass |
| 44 | + |
| 45 | + def method_with_doctest(self): |
| 46 | + """ |
| 47 | + This has a doctest! |
| 48 | + >>> MethodWrapper.method_with_doctest.__name__ |
| 49 | + 'method_with_doctest' |
| 50 | + """ |
| 51 | + |
| 52 | + @classmethod |
| 53 | + def classmethod_with_doctest(cls): |
| 54 | + """ |
| 55 | + This has a doctest! |
| 56 | + >>> MethodWrapper.classmethod_with_doctest.__name__ |
| 57 | + 'classmethod_with_doctest' |
| 58 | + """ |
| 59 | + |
| 60 | + @property |
| 61 | + def property_with_doctest(self): |
| 62 | + """ |
| 63 | + This has a doctest! |
| 64 | + >>> MethodWrapper.property_with_doctest.__name__ |
| 65 | + 'property_with_doctest' |
| 66 | + """ |
| 67 | + |
| 68 | +# https://github.com/python/cpython/issues/99433 |
| 69 | +str_wrapper = object().__str__ |
| 70 | + |
| 71 | + |
| 72 | +# https://github.com/python/cpython/issues/115392 |
| 73 | +from test.test_doctest.decorator_mod import decorator |
| 74 | + |
| 75 | +@decorator |
| 76 | +@decorator |
| 77 | +def func_with_docstring_wrapped(): |
| 78 | + """Some unrelated info.""" |
| 79 | + |
| 80 | + |
| 81 | +# https://github.com/python/cpython/issues/136914 |
| 82 | +import functools |
| 83 | + |
| 84 | + |
| 85 | +@functools.cache |
| 86 | +def cached_func_with_doctest(value): |
| 87 | + """ |
| 88 | + >>> cached_func_with_doctest(1) |
| 89 | + -1 |
| 90 | + """ |
| 91 | + return -value |
| 92 | + |
| 93 | + |
| 94 | +@functools.cache |
| 95 | +def cached_func_without_docstring(value): |
| 96 | + return value + 1 |
| 97 | + |
| 98 | + |
| 99 | +class ClassWithACachedProperty: |
| 100 | + |
| 101 | + @functools.cached_property |
| 102 | + def cached(self): |
| 103 | + """ |
| 104 | + >>> X().cached |
| 105 | + -1 |
| 106 | + """ |
| 107 | + return 0 |
0 commit comments