[Python-checkins] bpo-40066: [Enum] fix tests (GH-30643)

ethanfurman webhook-mailer at python.org
Mon Jan 17 11:52:57 EST 2022


https://github.com/python/cpython/commit/62a6594e66ca955073be2f4e5a40291a39252ef3
commit: 62a6594e66ca955073be2f4e5a40291a39252ef3
branch: main
author: Ethan Furman <ethan at stoneleaf.us>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2022-01-17T08:52:42-08:00
summary:

bpo-40066: [Enum] fix tests (GH-30643)

- skip doctest that changes depending on target system
- skip doctest that only fails on CI
- substitute in values that change depending on target system

files:
M Doc/library/ssl.rst
M Lib/test/test_socket.py
M Lib/test/test_ssl.py

diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index 4d8488a4a28de..151f2546eeb60 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -2081,7 +2081,7 @@ to speed up repeated connections from the same clients.
    .. versionchanged:: 3.6
       :attr:`SSLContext.verify_mode` returns :class:`VerifyMode` enum:
 
-         >>> ssl.create_default_context().verify_mode
+         >>> ssl.create_default_context().verify_mode  # doctest: +SKIP
          <VerifyMode.CERT_REQUIRED: 2>
 
 .. index:: single: certificates
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 56cc23dbbbf4e..53aa5e90fa25c 100755
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1517,11 +1517,11 @@ def testGetaddrinfo(self):
         infos = socket.getaddrinfo(HOST, 80, socket.AF_INET, socket.SOCK_STREAM)
         for family, type, _, _, _ in infos:
             self.assertEqual(family, socket.AF_INET)
-            self.assertEqual(repr(family), '<AddressFamily.AF_INET: 2>')
-            self.assertEqual(str(family), '2')
+            self.assertEqual(repr(family), '<AddressFamily.AF_INET: %r>' % family.value)
+            self.assertEqual(str(family), str(family.value))
             self.assertEqual(type, socket.SOCK_STREAM)
-            self.assertEqual(repr(type), '<SocketKind.SOCK_STREAM: 1>')
-            self.assertEqual(str(type), '1')
+            self.assertEqual(repr(type), '<SocketKind.SOCK_STREAM: %r>' % type.value)
+            self.assertEqual(str(type), str(type.value))
         infos = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM)
         for _, socktype, _, _, _ in infos:
             self.assertEqual(socktype, socket.SOCK_STREAM)
@@ -1795,10 +1795,10 @@ def test_str_for_enums(self):
         # Make sure that the AF_* and SOCK_* constants have enum-like string
         # reprs.
         with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
-            self.assertEqual(repr(s.family), '<AddressFamily.AF_INET: 2>')
-            self.assertEqual(repr(s.type), '<SocketKind.SOCK_STREAM: 1>')
-            self.assertEqual(str(s.family), '2')
-            self.assertEqual(str(s.type), '1')
+            self.assertEqual(repr(s.family), '<AddressFamily.AF_INET: %r>' % s.family.value)
+            self.assertEqual(repr(s.type), '<SocketKind.SOCK_STREAM: %r>' % s.type.value)
+            self.assertEqual(str(s.family), str(s.family.value))
+            self.assertEqual(str(s.type), str(s.type.value))
 
     def test_socket_consistent_sock_type(self):
         SOCK_NONBLOCK = getattr(socket, 'SOCK_NONBLOCK', 0)
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 64f4bce7f7781..543d34a546933 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -373,8 +373,8 @@ def test_str_for_enums(self):
         # Make sure that the PROTOCOL_* constants have enum-like string
         # reprs.
         proto = ssl.PROTOCOL_TLS_CLIENT
-        self.assertEqual(repr(proto), '<_SSLMethod.PROTOCOL_TLS_CLIENT: 16>')
-        self.assertEqual(str(proto), '16')
+        self.assertEqual(repr(proto), '<_SSLMethod.PROTOCOL_TLS_CLIENT: %r>' % proto.value)
+        self.assertEqual(str(proto), str(proto.value))
         ctx = ssl.SSLContext(proto)
         self.assertIs(ctx.protocol, proto)
 



More information about the Python-checkins mailing list