Something went wrong. Try again.
Personal music library metadata validation tool.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import argparsefrom pathlib import Pathimport unittest
from checks import ALL_CHECKS, BarcodeCheck, LyricsCheck, ReplayGainCheck, RequestedByCheckfrom cli import build_parser, resolve_active_checks, resolve_target_directoryfrom models import CheckResult, ScanIssue, ScanSummary, TrackMetadatafrom reporter import format_report
class TestCliResolution(unittest.TestCase): def test_resolveActiveChecks_noFlagsSpecified_enablesAllRegisteredChecks(self): parser = build_parser() args = parser.parse_args([])
checks = resolve_active_checks(args)
check_types = [type(c) for c in checks] self.assertEqual(len(ALL_CHECKS), len(checks)) self.assertIn(LyricsCheck, check_types) self.assertIn(BarcodeCheck, check_types) self.assertIn(RequestedByCheck, check_types) self.assertIn(ReplayGainCheck, check_types)
def test_resolveActiveChecks_lyricsFlagOnly_enablesOnlyLyricsCheck(self): parser = build_parser() args = parser.parse_args(["--lyrics"])
checks = resolve_active_checks(args)
self.assertEqual(1, len(checks)) self.assertIsInstance(checks[0], LyricsCheck)
def test_resolveActiveChecks_reqbyAndBarcodeFlags_enablesRequestedByAndBarcodeChecks(self): parser = build_parser() args = parser.parse_args(["--reqby", "--barcode"])
checks = resolve_active_checks(args)
check_types = [type(c) for c in checks] self.assertEqual(2, len(checks)) self.assertIn(RequestedByCheck, check_types) self.assertIn(BarcodeCheck, check_types)
class TestDirectoryResolution(unittest.TestCase): def test_resolveTargetDirectory_positionalProvided_resolvesPath(self): parser = build_parser() args = parser.parse_args(["tests"])
resolved = resolve_target_directory(args)
self.assertEqual(Path("tests").resolve(), resolved.resolve())
class TestReporter(unittest.TestCase): def test_formatReport_allPassing_showsSuccessMessage(self): summary = ScanSummary(total_scanned=5) checks = [LyricsCheck()]
report = format_report(summary, checks)
self.assertIn("All 5 tracks passed all checks.", report) self.assertIn("Tracks with issues: 0", report)
def test_formatReport_withIssues_listsFailuresAndIncrementsSummaryCounts(self): track = TrackMetadata( path=Path("/music/Artist/Album/01.flac"), artist="Artist", album="Album", title="Song", audio_format="flac", tags={}, ) failure = CheckResult(name="Lyrics", passed=False, message="Missing embedded lyrics") summary = ScanSummary( total_scanned=1, issues=[ScanIssue(track=track, failures=[failure])], check_failure_counts={"Lyrics": 1}, ) checks = [LyricsCheck()]
report = format_report(summary, checks)
self.assertIn("[Issue] /music/Artist/Album/01.flac", report) self.assertIn("Lyrics: Missing embedded lyrics", report) self.assertIn("Tracks with issues: 1", report) self.assertIn("Lyrics 1 failure", report)
if __name__ == "__main__": unittest.main()