Skip to content

Commit

Permalink
Merge pull request #495 from manics/test-config-relative
Browse files Browse the repository at this point in the history
test config: use path relative to file
  • Loading branch information
yuvipanda authored Aug 29, 2024
2 parents 44db8ee + 8fa9275 commit 3d0eac5
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions tests/resources/jupyter_server_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sys
from pathlib import Path

HERE = Path(__file__).parent.resolve()

sys.path.append(str(HERE))
def _get_path(*args):
"""Resolve a path relative to this file"""
return str(Path(__file__).parent.resolve().joinpath(*args))


sys.path.append(_get_path())

# load the config object for traitlets based configuration
c = get_config() # noqa
Expand Down Expand Up @@ -49,51 +53,51 @@ def my_env():

c.ServerProxy.servers = {
"python-http": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
},
"python-http-abs": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"absolute_url": True,
},
"python-http-port54321": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"port": 54321,
},
"python-http-mappath": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"mappath": {
"/": "/index.html",
},
},
"python-http-mappathf": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"mappath": mappathf,
},
"python-http-callable-env": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"environment": my_env,
},
"python-websocket": {
"command": [sys.executable, "./tests/resources/websocket.py", "--port={port}"],
"command": [sys.executable, _get_path("websocket.py"), "--port={port}"],
"request_headers_override": {
"X-Custom-Header": "pytest-23456",
},
},
"python-eventstream": {
"command": [sys.executable, "./tests/resources/eventstream.py", "--port={port}"]
"command": [sys.executable, _get_path("eventstream.py"), "--port={port}"]
},
"python-unix-socket-true": {
"command": [
sys.executable,
"./tests/resources/httpinfo.py",
_get_path("httpinfo.py"),
"--unix-socket={unix_socket}",
],
"unix_socket": True,
},
"python-unix-socket-file": {
"command": [
sys.executable,
"./tests/resources/httpinfo.py",
_get_path("httpinfo.py"),
"--unix-socket={unix_socket}",
],
"unix_socket": "/tmp/jupyter-server-proxy-test-socket",
Expand All @@ -104,38 +108,38 @@ def my_env():
"unix_socket": "/tmp/jupyter-server-proxy-test-socket",
},
"python-request-headers": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"request_headers_override": {
"X-Custom-Header": "pytest-23456",
},
},
"python-gzipserver": {
"command": [sys.executable, "./tests/resources/gzipserver.py", "{port}"],
"command": [sys.executable, _get_path("gzipserver.py"), "{port}"],
},
"python-http-rewrite-response": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"rewrite_response": translate_ciao,
"port": 54323,
},
"python-chained-rewrite-response": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"rewrite_response": [translate_ciao, hello_to_foo],
},
"python-cats-only-rewrite-response": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"rewrite_response": [dog_to_cat, cats_only],
},
"python-dogs-only-rewrite-response": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"rewrite_response": [cats_only, dog_to_cat],
},
"python-proxyto54321-no-command": {"port": 54321},
"python-rawsocket-tcp": {
"command": [sys.executable, "./tests/resources/rawsocket.py", "{port}"],
"command": [sys.executable, _get_path("rawsocket.py"), "{port}"],
"raw_socket_proxy": True,
},
"python-rawsocket-unix": {
"command": [sys.executable, "./tests/resources/rawsocket.py", "{unix_socket}"],
"command": [sys.executable, _get_path("rawsocket.py"), "{unix_socket}"],
"unix_socket": True,
"raw_socket_proxy": True,
},
Expand Down

0 comments on commit 3d0eac5

Please sign in to comment.