def normalize_license_expression(license_text_raw) -> str: if license_text_raw is None: return "" license_text, normalized = normalize(f"{license_text_raw}") try: license = licensing.parse(license_text) except ExpressionError: return license_text if license is None: return "" if license.isliteral: normalized_license, normalized = normalize(license.render()) return normalized_license operator = license.operator.strip() return "({})".format(f" {operator} ".join( map(normalize_license_expression, license.args)))
def test_license_with_space_instead_of_dash(self): license = "MPL 1.0" self.assertEqual(("MPL-1.0", True), normalize(license))
def test_normalized_license_returned_self(self): license = "MIT" self.assertEqual(("MIT", False), normalize(license))
def test_license_identified_by_long_name(self): license = "GNU Free Documentation License v1.1" self.assertEqual(("GFDL-1.1", True), normalize(license))
def test_license_identified_by_long_name_uppercase_problem(self): license = "ISC license" self.assertEqual(("ISC", True), normalize(license))
def test_complex_license(self): license = "M AND I AND T" self.assertEqual(("MIT", True), normalize(license))
def test_lowercase_license(self): license = "mit" self.assertEqual(("MIT", True), normalize(license))
def test_unknown_license(self): license = "Whatever very weird license" self.assertEqual((license, False), normalize(license))
def test_normalized_license(self): license = "Apache2" self.assertEqual(("Apache-2.0", True), normalize(license))
def test_dot_o_license(self): license = "Apache-2.0" self.assertEqual(("Apache-2.0", False), normalize(license))