from __future__ import annotations import unittest from scripts.generate_flutter_license_triage import ( candidate_license, license_signatures, ) class FlutterLicenseTriageTests(unittest.TestCase): def test_recognizes_common_license_text_signatures_conservatively(self) -> None: mit = "Permission is hereby granted, free of charge, to any person. The Software is provided AS IS. In no event shall the authors be liable." mpl = "Mozilla Public License Version 2.0" bsd3 = "Redistribution and use in source and binary forms are permitted provided that the following conditions are met. Neither the name of the project nor the names of its contributors may be used to endorse products. THIS SOFTWARE IS PROVIDED AS IS; DISCLAIMER" self.assertEqual(candidate_license(mit)[0], "MIT") self.assertEqual(candidate_license(mpl)[0], "MPL-2.0") self.assertEqual(candidate_license(bsd3)[0], "BSD-3-Clause") def test_keeps_ambiguous_notice_unclassified(self) -> None: self.assertIsNone( candidate_license("Copyright 2026 Example Authors. All rights reserved.")[0] ) mixed = "Mozilla Public License Version 2.0. Apache License Version 2.0." self.assertIsNone(candidate_license(mixed)[0]) self.assertEqual( sorted(license_signatures(mixed)), ["Apache-2.0", "MPL-2.0"], ) def test_detects_license_signatures_in_composite_notice(self) -> None: text = """Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met. Neither the name of the project may be used to endorse products. THIS SOFTWARE IS PROVIDED AS IS; DISCLAIMER. Apache License Version 2.0, January 2004 """ signatures = license_signatures(text) self.assertEqual(sorted(signatures), ["Apache-2.0", "BSD-3-Clause"]) self.assertIsNone(candidate_license(text)[0]) if __name__ == "__main__": unittest.main()