testutil: skip tests for missing ThreadingHTTPServer in py36
Only py3.7+ has ThreadingHTTPServer and SimpleHTTPRequestHandler that can take a directory argument. We could reimplement this on py36 (easy for threading, harder for missing directory) but instead this commit just skips tests that try to use a ThreadingHTTPServer. Remove once we no longer support py3.6.
This commit is contained in:
parent
d9a228d3e8
commit
2586a748fd
2 changed files with 19 additions and 5 deletions
|
|
@ -7,6 +7,20 @@ import http.server
|
|||
import socket
|
||||
import threading
|
||||
|
||||
try:
|
||||
from http.server import ThreadingHTTPServer
|
||||
except ImportError:
|
||||
# This fallback is only needed on py3.6. Py3.7+ has ThreadingHTTPServer.
|
||||
# We just import ThreadingHTTPServer here so that the import of "net.py"
|
||||
# on py36 works, the helpers are not usable because the "directory" arg
|
||||
# for SimpleHTTPRequestHandler is also not supported.
|
||||
class ThreadingHTTPServer: # type: ignore
|
||||
def __init__(self, *args, **kwargs): # pylint: disable=unused-argument
|
||||
# pylint: disable=import-outside-toplevel
|
||||
import pytest # type: ignore
|
||||
pytest.skip("python too old to suport ThreadingHTTPServer")
|
||||
|
||||
|
||||
from .atomic import AtomicCounter
|
||||
|
||||
|
||||
|
|
@ -21,7 +35,7 @@ class SilentHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||
pass
|
||||
|
||||
|
||||
class DirHTTPServer(http.server.ThreadingHTTPServer):
|
||||
class DirHTTPServer(ThreadingHTTPServer):
|
||||
def __init__(self, *args, directory=None, simulate_failures=0, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.directory = directory
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
import osbuild.testutil.net
|
||||
from osbuild.testutil.net import http_serve_directory
|
||||
|
||||
SOURCES_NAME = "org.osbuild.curl"
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ def test_curl_download_many_with_retry(tmp_path, sources_service):
|
|||
fake_httpd_root = tmp_path / "fake-httpd-root"
|
||||
|
||||
simulate_failures = 2
|
||||
with osbuild.testutil.net.http_serve_directory(fake_httpd_root, simulate_failures=simulate_failures) as httpd:
|
||||
with http_serve_directory(fake_httpd_root, simulate_failures=simulate_failures) as httpd:
|
||||
test_sources = make_test_sources(fake_httpd_root, httpd.server_port, 5)
|
||||
|
||||
sources_service.cache = tmp_path / "curl-download-dir"
|
||||
|
|
@ -134,7 +134,7 @@ def test_curl_download_many_with_retry(tmp_path, sources_service):
|
|||
def test_curl_download_many_chksum_validate(tmp_path, sources_service):
|
||||
fake_httpd_root = tmp_path / "fake-httpd-root"
|
||||
|
||||
with osbuild.testutil.net.http_serve_directory(fake_httpd_root) as httpd:
|
||||
with http_serve_directory(fake_httpd_root) as httpd:
|
||||
test_sources = make_test_sources(fake_httpd_root, httpd.server_port, 5)
|
||||
# "break" the hash of file "1" by replacing the content to no longer
|
||||
# match the checksum
|
||||
|
|
@ -150,7 +150,7 @@ def test_curl_download_many_chksum_validate(tmp_path, sources_service):
|
|||
def test_curl_download_many_retries(tmp_path, sources_service):
|
||||
fake_httpd_root = tmp_path / "fake-httpd-root"
|
||||
|
||||
with osbuild.testutil.net.http_serve_directory(fake_httpd_root) as httpd:
|
||||
with http_serve_directory(fake_httpd_root) as httpd:
|
||||
test_sources = make_test_sources(fake_httpd_root, httpd.server_port, 5)
|
||||
# remove all the sources
|
||||
shutil.rmtree(fake_httpd_root)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue