Skip to content

Commit

Permalink
Test with real binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 9, 2024
1 parent 353834f commit 801f389
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dest = "docs/cli.rst"
python_files = "*_test.py"

[tool.pytest.ini_options]
markers = ["only", "legacy"]
markers = ["only", "legacy", "slow"]

[tool.pyright]
reportPrivateUsage = false
Expand Down
15 changes: 15 additions & 0 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
test_dir = os.path.dirname(os.path.abspath(__file__))
ini_file = os.path.join(test_dir, "mscxyz.ini")

mscore_executable: str | None = shutil.which("mscore")


def get_path(filename: str, version: int = 2) -> Path:
"""
Expand Down Expand Up @@ -108,6 +110,19 @@ def read_file(filename: str | Path) -> str:
return output


def get_file_type(file: str | Path) -> str:
"""Get the type of a file using the `file` command."""
output: str = subprocess.check_output(
("file", "--brief", "--mime", file), encoding="utf-8"
)
return output.split(";")[0]


def assert_file_type(file: str | Path, expected: str) -> None:
"""Assert that the type of a file is equal to the expected type."""
assert get_file_type(file) == expected


CliArg = Union[str, Path, Score]


Expand Down
50 changes: 49 additions & 1 deletion tests/test_how_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

from __future__ import annotations

from tests.helper import stdout, sysexit
from pathlib import Path

import pytest

from tests import helper
from tests.helper import assert_file_type, cli, stdout, sysexit


class TestSpecifyMusescoreFiles:
Expand Down Expand Up @@ -95,3 +100,46 @@ def test_tcsh(self) -> None:
assert "# AUTOMATICALLY GENERATED by `shtab`" in sysexit(
"--print-completion", "tcsh"
)


@pytest.mark.slow
@pytest.mark.skipif(
helper.mscore_executable is None, reason="mscore executable not found"
)
@pytest.mark.parametrize(
"extension, expected",
[
("mscz", "application/zip"),
("mscx", "text/xml"),
("spos", "text/xml"),
("mpos", "text/xml"),
("pdf", "application/pdf"),
("svg", "image/svg+xml"),
("png", "image/png"),
("wav", "audio/x-wav"),
("mp3", "audio/mpeg"),
("ogg", "audio/ogg"),
("flac", "audio/flac"),
("mid", "audio/midi"),
("midi", "audio/midi"),
("kar", "audio/midi"),
("musicxml", "text/xml"),
("xml", "text/xml"),
("mxl", "application/zip"),
("brf", "text/plain"),
("mei", "text/xml"),
],
)
def test_export(extension: str, expected: str) -> None:
score = helper.get_score("simple.mscz", version=4)
cli("--export", extension, score)
numbering = ""
if extension in ("svg", "png"):
numbering = "-1"

dest = score.change_path(suffix=numbering, extension=extension)

dest = Path(str(score.path).replace(".mscz", f"{numbering}.{extension}"))
assert dest.exists()

assert_file_type(dest, expected)
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ isolated_build = True
deps =
pytest==7.4.4
commands = pytest
passenv = XDG_RUNTIME_DIR
passenv =
XDG_RUNTIME_DIR
DISPLAY
XAUTHORITY

[testenv:format]
deps =
Expand Down

0 comments on commit 801f389

Please sign in to comment.