| 2067 | self.assertEqual(s.type, socket.SOCK_STREAM) |
| 2068 | |
| 2069 | def test_unknown_socket_family_repr(self): |
| 2070 | # Test that when created with a family that's not one of the known |
| 2071 | # AF_*/SOCK_* constants, socket.family just returns the number. |
| 2072 | # |
| 2073 | # To do this we fool socket.socket into believing it already has an |
| 2074 | # open fd because on this path it doesn't actually verify the family and |
| 2075 | # type and populates the socket object. |
| 2076 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 2077 | fd = sock.detach() |
| 2078 | unknown_family = max(socket.AddressFamily.__members__.values()) + 1 |
| 2079 | |
| 2080 | unknown_type = max( |
| 2081 | kind |
| 2082 | for name, kind in socket.SocketKind.__members__.items() |
| 2083 | if name not in {'SOCK_NONBLOCK', 'SOCK_CLOEXEC'} |
| 2084 | ) + 1 |
| 2085 | |
| 2086 | with socket.socket( |
| 2087 | family=unknown_family, type=unknown_type, proto=23, |
| 2088 | fileno=fd) as s: |
| 2089 | self.assertEqual(s.family, unknown_family) |
| 2090 | self.assertEqual(s.type, unknown_type) |
| 2091 | # some OS like macOS ignore proto |
| 2092 | self.assertIn(s.proto, {0, 23}) |
| 2093 | |
| 2094 | @unittest.skipUnless(hasattr(os, 'sendfile'), 'test needs os.sendfile()') |
| 2095 | def test__sendfile_use_sendfile(self): |