Skip to content
Prev Previous commit
Next Next commit
add test for pyscript version when calling wrap with file instead of cmd
  • Loading branch information
fpliger committed Jan 11, 2023
commit acbd25bcaf8376035bc5130a1fbe99bfe9b4117e
42 changes: 42 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,48 @@ def test_wrap_pyscript_version(
assert css_version_str in html_text


@pytest.mark.parametrize(
"version, expected_version",
[(None, LATEST_PYSCRIPT_VERSION), ("2022.9.1", "2022.9.1")],
)
def test_wrap_pyscript_version_file(
invoke_cli: CLIInvoker,
version: Optional[str],
expected_version: str,
tmp_path: Path,
) -> None:
command = 'print("Hello World!")'
input_file = tmp_path / "hello.py"
with input_file.open("w") as fp:
fp.write(command)

args = ["wrap", str(input_file), "-o", "output.html"]

if version is not None:
args.extend(["--pyscript-version", version])
result = invoke_cli(*args)
assert result.exit_code == 0

expected_html_path = tmp_path / "output.html"
assert expected_html_path.exists()

with expected_html_path.open() as fp:
html_text = fp.read()

assert f"<py-script>\n{command}\n</py-script>" in html_text

version_str = (
f'<script defer src="https://pyscript.net/releases/{expected_version}'
'/pyscript.js"></script>'
)
css_version_str = (
'<link rel="stylesheet" href="https://pyscript.net/releases/'
f'{expected_version}/pyscript.css"/>'
)
assert version_str in html_text
assert css_version_str in html_text


@pytest.mark.parametrize(
"create_args, expected_version",
[
Expand Down