import subprocess import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "tools")) import check_fat32 # noqa: E402 def problems(name): return check_fat32.problems_with(Path(name)) def test_a_reserved_character_is_a_problem(): assert any("reserved" in p for p in problems("Album/Motherf**ker.mp3")) def test_a_trailing_dot_or_space_is_a_problem(): """FAT eats them silently, so the name round-trips as a different name.""" assert any("trailing" in p for p in problems("Trailing Dot./x.mp3")) assert any("trailing" in p for p in problems("Space /x.mp3")) def test_an_ordinary_name_is_fine(): assert problems("Artist/Album/01 Fine Track.mp3") == [] def test_accents_are_fine(): assert problems("Mötley Crüe/Album/Track.mp3") == [] def test_an_over_long_path_is_a_problem(): deep = "/".join("d" * 40 for _ in range(10)) + "/track.mp3" assert any("path of" in p for p in problems(deep)) def test_case_collisions_are_reported(tmp_path): album = tmp_path / "Album" album.mkdir() (album / "Song.mp3").write_bytes(b"x") (album / "SONG.mp3").write_bytes(b"x") completed = subprocess.run( [sys.executable, str(Path(check_fat32.__file__)), str(tmp_path)], capture_output=True, text=True, ) assert completed.returncode == 1 assert "collides case-insensitively" in completed.stdout def test_a_clean_tree_exits_zero(tmp_path): (tmp_path / "Album").mkdir() (tmp_path / "Album" / "Fine.mp3").write_bytes(b"x") completed = subprocess.run( [sys.executable, str(Path(check_fat32.__file__)), str(tmp_path)], capture_output=True, text=True, ) assert completed.returncode == 0 assert "0 problems" in completed.stderr