Added fast tests.

This commit is contained in:
The Wobbler 2025-03-18 17:31:25 +01:00
parent 8554ef8d81
commit d48394a522
3 changed files with 45 additions and 20 deletions

17
tests/conftest.py Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/python3
import pytest
def pytest_addoption(parser):
parser.addoption(
"--fast", action="store_true", help="Run only fast tests")
def pytest_collection_modifyitems(config, items):
if config.getoption("--fast"):
skip_slow = pytest.mark.skip(reason="Runs only without --fast option.")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)

View file

@ -1,15 +1,35 @@
#!/usr/bin/python3
import pytest
from io import BytesIO
from smalltag import SmallTag
# chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ "
def test_written_gets_recognized():
# avoid writing to the real file by using a BytesIO
tag = SmallTag.get("formats/test.mp3", file_obj=BytesIO(b""))
tag.title = "A normal title."
tag.artist = "An artist."
tag.album = "The album."
tag.track = 1234
tag = SmallTag.get("formats/test.mp3", file_obj=BytesIO(tag._compose_id3v2_tag()))
assert tag.title == "A normal title."
assert tag.artist == "An artist."
assert tag.album == "The album."
assert tag.track == 1234
# chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ "
# no "b" because there is a bug in TinyTag 2.1.0 that removes "b"s if they are at the beginning of a string
chars = "acdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 _-"
def test_written_gets_recognized():
@pytest.mark.slow
def test_full_written_gets_recognized():
for char1 in chars:
for char2 in chars:
field_content = f"{char1}{char2}Test{char2}{char1}"
@ -27,15 +47,3 @@ def test_written_gets_recognized():
assert tag.title == field_content
assert tag.artist == field_content
assert tag.album == field_content
def test_int_converted_to_numerical_string():
tag = SmallTag.get("formats/test.mp3")
tag.track = 123
tag.write()
tag = SmallTag.get("formats/test.mp3")
assert tag.track == 123