Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1fbb060

Browse files
authored
gh-131178: remove runtime tests forhttp.server CLI (#134287)
The runtime behavior of `http.server` CLI is hard to test on an arbitrary platform.As such, tests asserting the correctness of `python -m http.server` are temporarilyremoved and will be rewritten later once a universal solution has been found.
1 parent8421b03 commit1fbb060

File tree

1 file changed

+0
-83
lines changed

1 file changed

+0
-83
lines changed

‎Lib/test/test_httpservers.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
importhtml
2222
importhttp,http.client
2323
importurllib.parse
24-
importurllib.request
2524
importtempfile
2625
importtime
2726
importdatetime
@@ -34,8 +33,6 @@
3433
fromtest.supportimport (
3534
is_apple,import_helper,os_helper,threading_helper
3635
)
37-
fromtest.support.script_helperimportkill_python,spawn_python
38-
fromtest.support.socket_helperimportfind_unused_port
3936

4037
try:
4138
importssl
@@ -1455,86 +1452,6 @@ def test_unknown_flag(self, _):
14551452
self.assertIn('error',stderr.getvalue())
14561453

14571454

1458-
classCommandLineRunTimeTestCase(unittest.TestCase):
1459-
served_data=os.urandom(32)
1460-
served_file_name='served_filename'
1461-
tls_cert=certdata_file('ssl_cert.pem')
1462-
tls_key=certdata_file('ssl_key.pem')
1463-
tls_password='somepass'
1464-
1465-
defsetUp(self):
1466-
super().setUp()
1467-
withopen(self.served_file_name,'wb')asf:
1468-
f.write(self.served_data)
1469-
self.addCleanup(os_helper.unlink,self.served_file_name)
1470-
self.tls_password_file=tempfile.mktemp()
1471-
withopen(self.tls_password_file,'wb')asf:
1472-
f.write(self.tls_password.encode())
1473-
self.addCleanup(os_helper.unlink,self.tls_password_file)
1474-
1475-
deffetch_file(self,path):
1476-
context=ssl.create_default_context()
1477-
# allow self-signed certificates
1478-
context.check_hostname=False
1479-
context.verify_mode=ssl.CERT_NONE
1480-
req=urllib.request.Request(path,method='GET')
1481-
withurllib.request.urlopen(req,context=context)asres:
1482-
returnres.read()
1483-
1484-
defparse_cli_output(self,output):
1485-
matches=re.search(r'\((https?)://([^/:]+):(\d+)/?\)',output)
1486-
ifmatchesisNone:
1487-
returnNone,None,None
1488-
returnmatches.group(1),matches.group(2),int(matches.group(3))
1489-
1490-
defwait_for_server(self,proc,protocol,port,bind,timeout=50):
1491-
"""Check the server process output.
1492-
1493-
Return True if the server was successfully started
1494-
and is listening on the given port and bind address.
1495-
"""
1496-
whiletimeout>0:
1497-
line=proc.stdout.readline()
1498-
ifnotline:
1499-
time.sleep(0.1)
1500-
timeout-=1
1501-
continue
1502-
protocol_,host_,port_=self.parse_cli_output(line)
1503-
ifnotprotocol_ornothost_ornotport_:
1504-
time.sleep(0.1)
1505-
timeout-=1
1506-
continue
1507-
ifprotocol_==protocolandhost_==bindandport_==port:
1508-
returnTrue
1509-
break
1510-
returnFalse
1511-
1512-
deftest_http_client(self):
1513-
port=find_unused_port()
1514-
bind='127.0.0.1'
1515-
proc=spawn_python('-u','-m','http.server',str(port),'-b',bind,
1516-
bufsize=1,text=True)
1517-
self.addCleanup(kill_python,proc)
1518-
self.addCleanup(proc.terminate)
1519-
self.assertTrue(self.wait_for_server(proc,'http',port,bind))
1520-
res=self.fetch_file(f'http://{bind}:{port}/{self.served_file_name}')
1521-
self.assertEqual(res,self.served_data)
1522-
1523-
deftest_https_client(self):
1524-
port=find_unused_port()
1525-
bind='127.0.0.1'
1526-
proc=spawn_python('-u','-m','http.server',str(port),'-b',bind,
1527-
'--tls-cert',self.tls_cert,
1528-
'--tls-key',self.tls_key,
1529-
'--tls-password-file',self.tls_password_file,
1530-
bufsize=1,text=True)
1531-
self.addCleanup(kill_python,proc)
1532-
self.addCleanup(proc.terminate)
1533-
self.assertTrue(self.wait_for_server(proc,'https',port,bind))
1534-
res=self.fetch_file(f'https://{bind}:{port}/{self.served_file_name}')
1535-
self.assertEqual(res,self.served_data)
1536-
1537-
15381455
defsetUpModule():
15391456
unittest.addModuleCleanup(os.chdir,os.getcwd())
15401457

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp