Skip to content

gh-131178: add E2E mockless tests for http.server command-line interface #134279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
automatic deduction
  • Loading branch information
picnixz committed May 19, 2025
commit a46c9c22691c667335a411647bce9fed5de7fb4c
13 changes: 5 additions & 8 deletions Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,10 +1478,10 @@ def fetch_file(self, path, context=None):
return res.read()

def parse_cli_output(self, output):
matches = re.search(r'\((https?)://(\[::\]|[^/:]+):(\d+)/?\)', output)
matches = re.search(r'Serving (HTTP|HTTPS) on (.+) port (\d+)', output)
if matches is None:
return None, None, None
return matches.group(1), matches.group(2), int(matches.group(3))
return matches.group(1).lower(), matches.group(2), int(matches.group(3))

def wait_for_server(self, proc, protocol, port):
"""Extract the server bind address once it has been started."""
Expand All @@ -1496,8 +1496,7 @@ def wait_for_server(self, proc, protocol, port):

def test_http_client(self):
port = find_unused_port()
proc = spawn_python('-u', '-m', 'http.server',
str(port), '-b', 'localhost',
proc = spawn_python('-u', '-m', 'http.server', str(port),
bufsize=1, text=True)
self.addCleanup(kill_python, proc)
self.addCleanup(proc.terminate)
Expand All @@ -1514,9 +1513,8 @@ def test_https_client(self):
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

bind, port = 'localhost', find_unused_port()
proc = spawn_python('-u', '-m', 'http.server',
str(port), '-b', 'localhost',
port = find_unused_port()
proc = spawn_python('-u', '-m', 'http.server', str(port),
'--tls-cert', self.tls_cert,
'--tls-key', self.tls_key,
'--tls-password-file', self.tls_password_file,
Expand All @@ -1525,7 +1523,6 @@ def test_https_client(self):
self.addCleanup(proc.terminate)
bind = self.wait_for_server(proc, 'https', port)
self.assertIsNotNone(bind)
# localhost may be redirected to something else for whatever reason
url = f'https://{bind}:{port}/{self.served_filename}'
res = self.fetch_file(url, context=context)
self.assertEqual(res, self.served_data)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy