8000 Fake server 404 support (#994) · DindyalM/pyscriptErrors@94f2ac6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94f2ac6

Browse files
Fake server 404 support (pyscript#994)
* Fake server 404 support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * 404 test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test fix * [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>
1 parent cc6cb4d commit 94f2ac6

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

pyscriptjs/tests/integration/support.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses
2+
import os
23
import pdb
34
import re
45
import sys
@@ -595,7 +596,10 @@ def _router(self, route):
595596
self.log_request(200, "fake_server", full_url)
596597
assert url.path[0] == "/"
597598
relative_path = url.path[1:]
598-
route.fulfill(status=200, path=relative_path)
599+
if os.path.exists(relative_path):
600+
route.fulfill(status=200, path=relative_path)
601+
else:
602+
route.fulfill(status=404)
599603
return
600604

601605
# network requests might be cached

pyscriptjs/tests/integration/test_00_support.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,12 @@ def test_smartrouter_cache(self):
389389
(200, "fake_server", "http://fake_server/mytest.html"),
390390
(200, "CACHED", URL),
391391
]
392+
393+
def test_404(self):
394+
"""
395+
Test that we capture a 404 in loading a page that does not exist.
396+
"""
397+
self.goto("this_url_does_not_exist.html")
398+
assert [
399+
"Failed to load resource: the server responded with a status of 404 (Not Found)"
400+
] == self.console.all.lines

pyscriptjs/tests/integration/test_01_basic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,12 @@ def test_py_script_src_not_found(self):
180180
self.check_js_errors()
181181

182182
error_msg = str(exc.value)
183+
print(error_msg)
183184
if self.is_fake_server:
184-
assert "Failed to fetch" in error_msg
185+
assert (
186+
"Fetching from URL foo.py failed with error 404 (Not Found)."
187+
in error_msg
188+
)
185189
else:
186190
assert (
187191
"Fetching from URL foo.py failed with error 404 (File not found)"

pyscriptjs/tests/integration/test_py_config.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,10 @@ def test_paths_that_do_not_exist(self):
245245
wait_for_pyscript=False,
246246
)
247247

248-
if self.is_fake_server:
249-
expected = """PyScript: Access to local files
250-
(using "Paths:" in &lt;py-config&gt;)
251-
is not available when directly opening a HTML file;
252-
you must use a webserver to serve the additional files."""
253-
else:
254-
expected = (
255-
"Loading from file <u>./f.py</u> failed with error 404 (File not Found). "
256-
"Are your filename and path are correct?"
257-
)
248+
expected = (
249+
"Loading from file <u>./f.py</u> failed with error 404 (File not Found). "
250+
"Are your filename and path are correct?"
251+
)
258252

259253
inner_html = self.page.locator(".py-error").inner_html()
260254
assert expected in inner_html

0 commit comments

Comments
 (0)
0