def test_parsing_valid_file(self): content = """\ NAME=foobar LICENSE=GPLv2 FILENAME=foobar.tgz SHA1=eacf34ef.... ORIGIN=http://foobar.com USAGE=Unrestricted END_HEADER notes text notes text END_NOTES attribution text attribution text END_ATTRIBUTION """ file_path = self.create_file("3PPLICENSE", content) parser = LicenseParser(file_path, OpenSourceNoticeConfigMock()) info = parser.get_license_info() info.check_completeness() self.assertEqual("foobar", info.get_name()) self.assertEqual("GPLv2", info.get_license()) self.assertEqual({"": "foobar.tgz"}, info.get_file_names()) self.assertEqual({"": "eacf34ef...."}, info.get_sha1_checksums()) self.assertEqual("http://foobar.com", info.get_origin()) self.assertEqual("Unrestricted", info.get_usage()) self.assertEqual("attribution text\nattribution text", info.get_attribution()) os.remove(file_path)
def test_parsing_valid_file_with_embedded_attribution(self): content = """\ %s EMBEDDED_NAME[0]=giraffe EMBEDDED_VERSION[0]=1.0.1 EMBEDDED_LICENSE[0]=GPLv2 EMBEDDED_NAME[1]=lion EMBEDDED_LICENSE[1]=Custom END_HEADER foobar attribution text END_ATTRIBUTION giraffe attribution text END_ATTRIBUTION_giraffe lion attribution text END_ATTRIBUTION_lion """ % self.REQUIRED_SET file_path = self.create_file("3PPLICENSE", content) parser = LicenseParser(file_path, OpenSourceNoticeConfigMock()) info = parser.get_license_info() info.check_completeness() self.assertDictEqual({"0": "giraffe", "1": "lion"}, info.get_embedded_names()) self.assertDictEqual({"0": "1.0.1"}, info.get_embedded_versions()) self.assertDictEqual({"0": "GPLv2", "1": "Custom"}, info.get_embedded_licenses()) self.assertEqual("foobar attribution text", info.get_attribution()) self.assertEqual("giraffe attribution text", info.get_embedded_attribution("giraffe")) self.assertEqual("lion attribution text", info.get_embedded_attribution("lion")) embedded_info = info.get_embedded_license_info() order = (0, 1) if embedded_info[0].get_name() == "giraffe" else (1, 0) self.assertEqual("giraffe", embedded_info[order[0]].get_name()) self.assertEqual("1.0.1", embedded_info[order[0]].get_version()) self.assertEqual("GPLv2", embedded_info[order[0]].get_license()) self.assertEqual("giraffe attribution text", embedded_info[order[0]].get_attribution()) self.assertEqual("lion", embedded_info[order[1]].get_name()) self.assertEqual("", embedded_info[order[1]].get_version()) self.assertEqual("Custom", embedded_info[order[1]].get_license()) self.assertEqual("lion attribution text", embedded_info[order[1]].get_attribution()) os.remove(file_path)
def test_empty_license_info(self): content = """\ %s END_HEADER END_ATTRIBUTION """ % self.REQUIRED_SET file_path = self.create_file("3PPLICENSE", content) parser = LicenseParser(file_path, OpenSourceNoticeConfigMock()) info = parser.get_license_info() self.assertListEqual([], info.get_embedded_license_info()) os.remove(file_path)
def test_parsing_with_missing_attribute_raises_error(self): content = """\ NAME=foobar END_HEADER END_ATTRIBUTION """ file_path = self.create_file("KTVLICENSE", content) parser = LicenseParser(file_path, OpenSourceNoticeConfigMock()) info = parser.get_license_info() self.assertRaisesRegexp( ParserError, "attribute .* is missing", info.check_completeness) os.remove(file_path)
def test_license_index_not_paired_with_name_index_raises_error(self): content = """\ %s EMBEDDED_LICENSE[0]=Custom END_HEADER END_ATTRIBUTION """ % self.REQUIRED_SET file_path = self.create_file("3PPLICENSE", content) parser = LicenseParser(file_path, OpenSourceNoticeConfigMock()) info = parser.get_license_info() self.assertRaisesRegexp( ParserError, "found EMBEDDED_LICENSE\[0\] but EMBEDDED_NAME\[0\] is missing", info.check_completeness) os.remove(file_path)
def test_filename_index_not_paired_with_sha1_index_raises_error(self): content = """\ NAME=foobar LICENSE=GPLv2 FILENAME[0]=foobar.tgz SHA1[1]=eacf34ef.... ORIGIN=http://foobar.com USAGE=Unrestricted END_HEADER END_ATTRIBUTION """ file_path = self.create_file("3PPLICENSE", content) parser = LicenseParser(file_path, OpenSourceNoticeConfigMock()) info = parser.get_license_info() self.assertRaisesRegexp( ParserError, "found FILENAME\[0\] but SHA1\[0\] is missing", info.check_completeness) os.remove(file_path)
def test_parsing_with_missing_index_raises_error(self): content = """\ NAME=foobar LICENSE=GPLv2 FILENAME[0]=foobar.tgz FILENAME=foobar2.tgz SHA1[0]=eacf34ef.... SHA1=eacf456f.... ORIGIN=http://foobar.com USAGE=Unrestricted END_HEADER END_ATTRIBUTION """ file_path = self.create_file("3PPLICENSE", content) parser = LicenseParser(file_path, OpenSourceNoticeConfigMock()) info = parser.get_license_info() self.assertRaisesRegexp( ParserError, "missing index for attribute FILENAME", info.check_completeness) os.remove(file_path)