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

View file

@ -27,12 +27,6 @@ class _ID3(SmallTag, tinytag._ID3):
def write(self, file_obj: BinaryIO=None):
should_close_file = self._set_filehandler_for_writing(file_obj)
# change keys to values in the mapping dict
self._ID3_WRITE_MAPPING = {} # noqa
for frame_id, name in self._ID3_MAPPING.items():
if len(frame_id) == 4:
self._ID3_WRITE_MAPPING[name] = frame_id
new_tag = self._compose_id3v2_tag()
size, extended, major = self._parse_id3v2_header(self._filehandler)
@ -48,6 +42,12 @@ class _ID3(SmallTag, tinytag._ID3):
self._filehandler.close()
def _compose_id3v2_tag(self) -> bytes:
# change keys to values in the mapping dict
self._ID3_WRITE_MAPPING = {} # noqa
for frame_id, name in self._ID3_MAPPING.items():
if len(frame_id) == 4:
self._ID3_WRITE_MAPPING[name] = frame_id
frames = self._compose_id3v2_frames()
frame_size = len(frames)

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