Skip to content

Commit c93aca7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 4c8a682 commit c93aca7

File tree

2 files changed

+79
-19
lines changed

2 files changed

+79
-19
lines changed

src/pyscript/plugins/run.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ def end_headers(self):
3737
self.send_header("Cross-Origin-Resource-Policy", "cross-origin")
3838
self.send_header("Cache-Control", "no-cache, must-revalidate")
3939
SimpleHTTPRequestHandler.end_headers(self)
40-
40+
4141
def do_GET(self):
4242
# intercept accesses to nonexistent files; replace them with the default file
4343
# this is to service SPA use cases (see Github Issue #132)
4444
if default_file:
4545
path = Path(self.translate_path(self.path))
4646
if not path.exists():
47-
self.path = f'/{default_file}'
48-
47+
self.path = f"/{default_file}"
48+
4949
return super().do_GET()
5050

5151
return FolderBasedHTTPRequestHandler
@@ -87,7 +87,9 @@ def start_server(path: Path, show: bool, port: int, default_file: Path = None):
8787
socketserver.TCPServer.allow_reuse_address = True
8888

8989
app_folder, filename = split_path_and_filename(path)
90-
CustomHTTPRequestHandler = get_folder_based_http_request_handler(app_folder, default_file=default_file)
90+
CustomHTTPRequestHandler = get_folder_based_http_request_handler(
91+
app_folder, default_file=default_file
92+
)
9193

9294
# Start the server within a context manager to make sure we clean up after
9395
with socketserver.TCPServer(("", port), CustomHTTPRequestHandler) as httpd:
@@ -121,7 +123,9 @@ def run(
121123
),
122124
view: bool = typer.Option(True, help="Open the app in web browser."),
123125
port: int = typer.Option(8000, help="The port that the app will run on."),
124-
default_file: Path = typer.Option(None, help="A default file to serve when a nonexistent file is accessed."),
126+
default_file: Path = typer.Option(
127+
None, help="A default file to serve when a nonexistent file is accessed."
128+
),
125129
):
126130
"""
127131
Creates a local server to run the app on the path and port specified.

tests/test_run_cli_cmd.py

+70-14
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,80 @@ def test_run_server_with_no_view_flag(
8989
(("--no-view",), (Path("."), False, 8000), {"default_file": None}),
9090
((BASEPATH,), (Path(BASEPATH), True, 8000), {"default_file": None}),
9191
(("--port=8001",), (Path("."), True, 8001), {"default_file": None}),
92-
(("--no-view", "--port=8001"), (Path("."), False, 8001), {"default_file": None}),
93-
((BASEPATH, "--no-view"), (Path(BASEPATH), False, 8000), {"default_file": None}),
94-
((BASEPATH, "--port=8001"), (Path(BASEPATH), True, 8001), {"default_file": None}),
95-
((BASEPATH, "--no-view", "--port=8001"), (Path(BASEPATH), False, 8001), {"default_file": None}),
96-
((BASEPATH, "--port=8001"), (Path(BASEPATH), True, 8001), {"default_file": None}),
97-
(("--no-view", "--default-file=index.html"), (Path("."), False, 8000), {"default_file": Path("index.html")}),
98-
((BASEPATH, "--default-file=index.html"), (Path(BASEPATH), True, 8000), {"default_file": Path("index.html")}),
99-
(("--port=8001", "--default-file=index.html"), (Path("."), True, 8001), {"default_file": Path("index.html")}),
100-
(("--no-view", "--port=8001", "--default-file=index.html"), (Path("."), False, 8001), {"default_file": Path("index.html")}),
101-
((BASEPATH, "--no-view", "--default-file=index.html"), (Path(BASEPATH), False, 8000), {"default_file": Path("index.html")}),
102-
((BASEPATH, "--port=8001", "--default-file=index.html"), (Path(BASEPATH), True, 8001), {"default_file": Path("index.html")}),
103-
((BASEPATH, "--no-view", "--port=8001", "--default-file=index.html"), (Path(BASEPATH), False, 8001), {"default_file": Path("index.html")}),
104-
((BASEPATH, "--port=8001", "--default-file=index.html"), (Path(BASEPATH), True, 8001), {"default_file": Path("index.html")}),
92+
(
93+
("--no-view", "--port=8001"),
94+
(Path("."), False, 8001),
95+
{"default_file": None},
96+
),
97+
(
98+
(BASEPATH, "--no-view"),
99+
(Path(BASEPATH), False, 8000),
100+
{"default_file": None},
101+
),
102+
(
103+
(BASEPATH, "--port=8001"),
104+
(Path(BASEPATH), True, 8001),
105+
{"default_file": None},
106+
),
107+
(
108+
(BASEPATH, "--no-view", "--port=8001"),
109+
(Path(BASEPATH), False, 8001),
110+
{"default_file": None},
111+
),
112+
(
113+
(BASEPATH, "--port=8001"),
114+
(Path(BASEPATH), True, 8001),
115+
{"default_file": None},
116+
),
117+
(
118+
("--no-view", "--default-file=index.html"),
119+
(Path("."), False, 8000),
120+
{"default_file": Path("index.html")},
121+
),
122+
(
123+
(BASEPATH, "--default-file=index.html"),
124+
(Path(BASEPATH), True, 8000),
125+
{"default_file": Path("index.html")},
126+
),
127+
(
128+
("--port=8001", "--default-file=index.html"),
129+
(Path("."), True, 8001),
130+
{"default_file": Path("index.html")},
131+
),
132+
(
133+
("--no-view", "--port=8001", "--default-file=index.html"),
134+
(Path("."), False, 8001),
135+
{"default_file": Path("index.html")},
136+
),
137+
(
138+
(BASEPATH, "--no-view", "--default-file=index.html"),
139+
(Path(BASEPATH), False, 8000),
140+
{"default_file": Path("index.html")},
141+
),
142+
(
143+
(BASEPATH, "--port=8001", "--default-file=index.html"),
144+
(Path(BASEPATH), True, 8001),
145+
{"default_file": Path("index.html")},
146+
),
147+
(
148+
(BASEPATH, "--no-view", "--port=8001", "--default-file=index.html"),
149+
(Path(BASEPATH), False, 8001),
150+
{"default_file": Path("index.html")},
151+
),
152+
(
153+
(BASEPATH, "--port=8001", "--default-file=index.html"),
154+
(Path(BASEPATH), True, 8001),
155+
{"default_file": Path("index.html")},
156+
),
105157
],
106158
)
107159
@mock.patch("pyscript.plugins.run.start_server")
108160
def test_run_server_with_valid_combinations(
109-
start_server_mock, invoke_cli: CLIInvoker, run_args, expected_posargs, expected_kwargs # noqa: F811
161+
start_server_mock,
162+
invoke_cli: CLIInvoker,
163+
run_args,
164+
expected_posargs,
165+
expected_kwargs, # noqa: F811
110166
):
111167
"""
112168
Test that when run is called without arguments the command runs with the

0 commit comments

Comments
 (0)