mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 03:35:31 -05:00
* fix tests by changing serving dir * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
40 lines
948 B
Python
40 lines
948 B
Python
"""All data required for testing examples"""
|
|
import threading
|
|
from http.server import HTTPServer as SuperHTTPServer
|
|
from http.server import SimpleHTTPRequestHandler
|
|
|
|
import pytest
|
|
|
|
|
|
class HTTPServer(SuperHTTPServer):
|
|
"""
|
|
Class for wrapper to run SimpleHTTPServer on Thread.
|
|
Ctrl +Only Thread remains dead when terminated with C.
|
|
Keyboard Interrupt passes.
|
|
"""
|
|
|
|
def run(self):
|
|
try:
|
|
self.serve_forever()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
self.server_close()
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def http_server():
|
|
host, port = "127.0.0.1", 8080
|
|
base_url = f"http://{host}:{port}"
|
|
|
|
# serve_Run forever under thread
|
|
server = HTTPServer((host, port), SimpleHTTPRequestHandler)
|
|
thread = threading.Thread(None, server.run)
|
|
thread.start()
|
|
|
|
yield base_url # Transition to test here
|
|
|
|
# End thread
|
|
server.shutdown()
|
|
thread.join()
|