import argparse from pathlib import Path import unittest from checks import ALL_CHECKS, BarcodeCheck, LyricsCheck, ReplayGainCheck, RequestedByCheck from cli import build_parser, resolve_active_checks, resolve_target_directory from models import CheckResult, ScanIssue, ScanSummary, TrackMetadata from 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()