Skip to content

Commit 7b2491a

Browse files
marco-buttuberkerpeksag
authored andcommitted
bpo-27200: Fix pathlib, ssl, turtle and weakref doctests (GH-616)
1 parent d1dc65d commit 7b2491a

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

Doc/library/pathlib.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ property:
271271
Methods and properties
272272
^^^^^^^^^^^^^^^^^^^^^^
273273

274+
.. testsetup::
275+
276+
from pathlib import PurePosixPath, PureWindowsPath
277+
274278
Pure paths provide the following methods and properties:
275279

276280
.. data:: PurePath.drive
@@ -657,6 +661,8 @@ call fails (for example because the path doesn't exist):
657661
Return information about this path (similarly to :func:`os.stat`).
658662
The result is looked up at each call to this method.
659663

664+
::
665+
660666
>>> p = Path('setup.py')
661667
>>> p.stat().st_size
662668
956
@@ -948,7 +954,7 @@ call fails (for example because the path doesn't exist):
948954
.. method:: Path.rglob(pattern)
949955

950956
This is like calling :meth:`Path.glob` with "``**``" added in front of the
951-
given *pattern*:
957+
given *pattern*::
952958

953959
>>> sorted(Path().rglob("*.py"))
954960
[PosixPath('build/lib/pathlib.py'),
@@ -972,6 +978,8 @@ call fails (for example because the path doesn't exist):
972978
An :exc:`OSError` can be raised if either file cannot be accessed for some
973979
reason.
974980

981+
::
982+
975983
>>> p = Path('spam')
976984
>>> q = Path('eggs')
977985
>>> p.samefile(q)
@@ -988,6 +996,8 @@ call fails (for example because the path doesn't exist):
988996
*target_is_directory* must be true (default ``False``) if the link's target
989997
is a directory. Under POSIX, *target_is_directory*'s value is ignored.
990998

999+
::
1000+
9911001
>>> p = Path('mylink')
9921002
>>> p.symlink_to('setup.py')
9931003
>>> p.resolve()

Doc/library/ssl.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ Random generation
369369
Certificate handling
370370
^^^^^^^^^^^^^^^^^^^^
371371

372+
.. testsetup::
373+
374+
import ssl
375+
372376
.. function:: match_hostname(cert, hostname)
373377

374378
Verify that *cert* (in decoded format as returned by
@@ -415,10 +419,10 @@ Certificate handling
415419

416420
>>> import ssl
417421
>>> timestamp = ssl.cert_time_to_seconds("Jan 5 09:34:43 2018 GMT")
418-
>>> timestamp
422+
>>> timestamp # doctest: +SKIP
419423
1515144883
420424
>>> from datetime import datetime
421-
>>> print(datetime.utcfromtimestamp(timestamp))
425+
>>> print(datetime.utcfromtimestamp(timestamp)) # doctest: +SKIP
422426
2018-01-05 09:34:43
423427

424428
"notBefore" or "notAfter" dates must use GMT (:rfc:`5280`).
@@ -1378,6 +1382,7 @@ to speed up repeated connections from the same clients.
13781382
'strength_bits': 128}]
13791383

13801384
On OpenSSL 1.1 and newer the cipher dict contains additional fields::
1385+
13811386
>>> ctx.get_ciphers() # OpenSSL 1.1+
13821387
[{'aead': True,
13831388
'alg_bits': 256,
@@ -1638,7 +1643,7 @@ to speed up repeated connections from the same clients.
16381643
.. versionchanged:: 3.6
16391644
:attr:`SSLContext.options` returns :class:`Options` flags:
16401645

1641-
>>> ssl.create_default_context().options
1646+
>>> ssl.create_default_context().options # doctest: +SKIP
16421647
<Options.OP_ALL|OP_NO_SSLv3|OP_NO_SSLv2|OP_NO_COMPRESSION: 2197947391>
16431648

16441649
.. attribute:: SSLContext.protocol
@@ -1658,7 +1663,7 @@ to speed up repeated connections from the same clients.
16581663
.. versionchanged:: 3.6
16591664
:attr:`SSLContext.verify_flags` returns :class:`VerifyFlags` flags:
16601665

1661-
>>> ssl.create_default_context().verify_flags
1666+
>>> ssl.create_default_context().verify_flags # doctest: +SKIP
16621667
<VerifyFlags.VERIFY_X509_TRUSTED_FIRST: 32768>
16631668

16641669
.. attribute:: SSLContext.verify_mode
@@ -2259,6 +2264,8 @@ recommended to use :const:`PROTOCOL_TLS_CLIENT` or
22592264
:const:`PROTOCOL_TLS_SERVER` as the protocol version. SSLv2 and SSLv3 are
22602265
disabled by default.
22612266

2267+
::
2268+
22622269
>>> client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
22632270
>>> client_context.options |= ssl.OP_NO_TLSv1
22642271
>>> client_context.options |= ssl.OP_NO_TLSv1_1

Doc/library/turtle.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,9 @@ Color control
936936
>>> turtle.fillcolor("violet")
937937
>>> turtle.fillcolor()
938938
'violet'
939-
>>> col = turtle.pencolor()
940-
>>> col
939+
>>> turtle.pencolor()
941940
(50.0, 193.0, 143.0)
942-
>>> turtle.fillcolor(col)
941+
>>> turtle.fillcolor((50, 193, 143)) # Integers, not floats
943942
>>> turtle.fillcolor()
944943
(50.0, 193.0, 143.0)
945944
>>> turtle.fillcolor('#ffffff')

Doc/library/weakref.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ the constructor when it was created.
478478
>>> obj = Object()
479479
>>> f = weakref.finalize(obj, callback, 1, 2, z=3)
480480
>>> f.detach() #doctest:+ELLIPSIS
481-
(<__main__.Object object ...>, <function callback ...>, (1, 2), {'z': 3})
481+
(<...Object object ...>, <function callback ...>, (1, 2), {'z': 3})
482482
>>> newobj, func, args, kwargs = _
483483
>>> assert not f.alive
484484
>>> assert newobj is obj

0 commit comments

Comments
 (0)