Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4ee4eb

Browse files
committed
Rearrange test_socket_ssl so that a skip is expected iff the network
resource isn't enabled or the socket module doesn't support ssl.
1 parent 6ee68d2 commit b4ee4eb

3 files changed

Lines changed: 35 additions & 28 deletions

File tree

Lib/test/regrtest.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ def printlist(x, width=70, indent=4):
534534
# Whether a skip is expected here depends on whether a large test
535535
# input file has been downloaded. test_normalization.skip_expected
536536
# controls that.
537+
# test_socket_ssl
538+
# Controlled by test_socket_ssl.skip_expected. Requires the network
539+
# resource, and a socket module with ssl support.
537540

538541
_expectations = {
539542
'win32':
@@ -565,7 +568,6 @@ def printlist(x, width=70, indent=4):
565568
test_pwd
566569
test_resource
567570
test_signal
568-
test_socket_ssl
569571
test_socketserver
570572
test_sunaudiodev
571573
test_timing
@@ -583,7 +585,6 @@ def printlist(x, width=70, indent=4):
583585
test_largefile
584586
test_nis
585587
test_ntpath
586-
test_socket_ssl
587588
test_socketserver
588589
test_sunaudiodev
589590
test_unicode_file
@@ -618,7 +619,6 @@ def printlist(x, width=70, indent=4):
618619
test_pty
619620
test_pwd
620621
test_signal
621-
test_socket_ssl
622622
test_socketserver
623623
test_sunaudiodev
624624
test_sundry
@@ -736,7 +736,6 @@ def printlist(x, width=70, indent=4):
736736
test_popen2
737737
test_pty
738738
test_pwd
739-
test_socket_ssl
740739
test_socketserver
741740
test_strop
742741
test_sunaudiodev
@@ -769,7 +768,6 @@ def printlist(x, width=70, indent=4):
769768
test_nis
770769
test_ntpath
771770
test_poll
772-
test_socket_ssl
773771
test_socketserver
774772
test_sunaudiodev
775773
test_unicode_file
@@ -792,7 +790,6 @@ def printlist(x, width=70, indent=4):
792790
test_linuxaudiodev
793791
test_mpz
794792
test_openpty
795-
test_socket_ssl
796793
test_socketserver
797794
test_winreg
798795
test_winsound
@@ -820,7 +817,6 @@ def printlist(x, width=70, indent=4):
820817
test_openpty
821818
test_pyexpat
822819
test_sax
823-
test_socket_ssl
824820
test_socketserver
825821
test_sunaudiodev
826822
test_unicode_file
@@ -850,7 +846,6 @@ def printlist(x, width=70, indent=4):
850846
test_poll
851847
test_popen2
852848
test_resource
853-
test_socket_ssl
854849
test_socketserver
855850
test_sunaudiodev
856851
test_unicode_file
@@ -863,6 +858,7 @@ class _ExpectedSkips:
863858
def __init__(self):
864859
import os.path
865860
from test import test_normalization
861+
from test import test_socket_ssl
866862

867863
self.valid = False
868864
if sys.platform in _expectations:
@@ -875,6 +871,9 @@ def __init__(self):
875871
if test_normalization.skip_expected:
876872
self.expected.add('test_normalization')
877873

874+
if test_socket_ssl.skip_expected:
875+
self.expected.add('test_socket_ssl')
876+
878877
self.valid = True
879878

880879
def isvalid(self):

Lib/test/test_socket_ssl.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
# Test just the SSL support in the socket module, in a moderately bogus way.
22

33
from test import test_support
4+
import socket
45

5-
# Optionally test SSL support. This currently requires the 'network' resource
6-
# as given on the regrtest command line. If not available, nothing after this
7-
# line will be executed.
8-
test_support.requires('network')
6+
# Optionally test SSL support. This requires the 'network' resource as given
7+
# on the regrtest command line.
8+
skip_expected = not (test_support.is_resource_enabled('network') and
9+
hasattr(socket, "ssl"))
910

10-
import socket
11-
if not hasattr(socket, "ssl"):
12-
raise test_support.TestSkipped("socket module has no ssl support")
11+
def test_main():
12+
test_support.requires('network')
13+
if not hasattr(socket, "ssl"):
14+
raise test_support.TestSkipped("socket module has no ssl support")
15+
16+
import urllib
1317

14-
import urllib
18+
socket.RAND_status()
19+
try:
20+
socket.RAND_egd(1)
21+
except TypeError:
22+
pass
23+
else:
24+
print "didn't raise TypeError"
25+
socket.RAND_add("this is a random string", 75.0)
1526

16-
socket.RAND_status()
17-
try:
18-
socket.RAND_egd(1)
19-
except TypeError:
20-
pass
21-
else:
22-
print "didn't raise TypeError"
23-
socket.RAND_add("this is a random string", 75.0)
27+
f = urllib.urlopen('https://sf.net')
28+
buf = f.read()
29+
f.close()
2430

25-
f = urllib.urlopen('https://sf.net')
26-
buf = f.read()
27-
f.close()
31+
if __name__ == "__main__":
32+
test_main()

Lib/test/test_support.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ def forget(modname):
5050
except os.error:
5151
pass
5252

53+
def is_resource_enabled(resource):
54+
return use_resources is not None and resource in use_resources
55+
5356
def requires(resource, msg=None):
54-
if use_resources is not None and resource not in use_resources:
57+
if not is_resource_enabled(resource):
5558
if msg is None:
5659
msg = "Use of the `%s' resource not enabled" % resource
5760
raise TestSkipped(msg)

0 commit comments

Comments
 (0)