Skip to content

Commit

Permalink
CI: Validate on Windows operating system
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Oct 25, 2024
1 parent 3426aa7 commit 106e5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
"ubuntu-latest",
"macos-12",
"macos-latest",
"windows-latest",
]
python-version: [
"3.10",
Expand Down
26 changes: 16 additions & 10 deletions tests/test_responder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import random
import string
import sys
from pathlib import Path

import pytest
import yaml
Expand Down Expand Up @@ -811,7 +813,7 @@ def get(req, resp):
assert r.status_code == 200


def create_asset(static_dir, name=None, parent_dir=None):
def create_asset(static_dir: Path, name=None, parent_dir: str = None) -> Path:
if name is None:
name = random.choices(string.ascii_letters, k=6) # noqa: S311
# :3
Expand All @@ -821,16 +823,20 @@ def create_asset(static_dir, name=None, parent_dir=None):
if parent_dir is None:
parent_dir = static_dir
else:
parent_dir = static_dir.mkdir(parent_dir)
parent_dir = static_dir / parent_dir
parent_dir.mkdir()

asset = parent_dir.join(name)
asset.write("body { color: blue; }")
return asset
asset = parent_dir / name
asset.write_text("body { color: blue; }", encoding="utf-8")
return Path(asset)


@pytest.mark.parametrize("static_route", [None, "/static", "/custom/static/route"])
def test_staticfiles(tmpdir, static_route):
static_dir = tmpdir.mkdir("static")
def test_staticfiles(tmp_path, static_route):
if sys.platform == "win32" and static_route is None:
raise pytest.skip("Route 'None' currently does not work on Windows")
static_dir = tmp_path / "static"
static_dir.mkdir()

asset1 = create_asset(static_dir)
parent_dir = "css"
Expand All @@ -842,10 +848,10 @@ def test_staticfiles(tmpdir, static_route):
static_route = api.static_route

# ok
r = session.get(f"{static_route}/{asset1.basename}")
r = session.get(f"{static_route}/{asset1.name}")
assert r.status_code == api.status_codes.HTTP_200

r = session.get(f"{static_route}/{parent_dir}/{asset2.basename}")
r = session.get(f"{static_route}/{parent_dir}/{asset2.name}")
assert r.status_code == api.status_codes.HTTP_200

# Asset not found
Expand All @@ -871,7 +877,7 @@ def test_staticfiles_none_dir(tmpdir):
static_route = api.static_route

# ok
r = session.get(f"{static_route}/{asset.basename}")
r = session.get(f"{static_route}/{asset.name}")
assert r.status_code == api.status_codes.HTTP_404

# dir listing
Expand Down

0 comments on commit 106e5e9

Please sign in to comment.