def test_spdx_info_of_also_covered_by_dep5(fake_repository): """A file contains all SPDX information, but .reuse/dep5 also provides information on this file. Use both. """ (fake_repository / "doc/foo.py").write_text( dedent(""" SPDX-License-Identifier: MIT SPDX-FileCopyrightText: in file""")) project = Project(fake_repository) spdx_info = project.spdx_info_of("doc/foo.py") assert LicenseSymbol("MIT") in spdx_info.spdx_expressions assert LicenseSymbol("CC0-1.0") in spdx_info.spdx_expressions assert "SPDX-FileCopyrightText: in file" in spdx_info.copyright_lines assert "2017 Mary Sue" in spdx_info.copyright_lines
def read_symbols(self, translations_files): symbols = [] symbols_map = {} for translations_file in translations_files.split(): #print("reading translation file: " + str(translations_file)) translation_data = read_translations(translations_file) for lic_key in translation_data: #print("lic_key: \"" + str(lic_key) + "\"") #print(" lic_alias: " + str(translation_data[lic_key] )) if lic_key not in symbols_map: symbols_map[lic_key] = set() for val in translation_data[lic_key]: symbols_map[lic_key].add(val) #lic_aliases = tuple(translation_data[lic_key]) #symbols.append(LicenseSymbol(key=key, aliases=lic_aliases)) for key, value in symbols_map.items(): #print("Adding to symbols: " + key) #print(" - " + str(value)) symbols.append(LicenseSymbol(key=key, aliases=tuple(value))) # debugging #print("Symbols") #for sym in symbols: #print(" sym: " + (str(sym.key))) #print(" aliases : " + (str(sym.aliases))) #l = Licensing([sym]) #print(" licensing: " + (str(l))) #print("symbols: " + str(symbols)) return symbols
def test_spdx_info_of_binary_succeeds(fake_repository): """spdx_info_of succeeds when the target is covered by dep5.""" shutil.copy(RESOURCES_DIRECTORY / "fsfe.png", fake_repository / "doc/fsfe.png") project = Project(fake_repository) spdx_info = project.spdx_info_of("doc/fsfe.png") assert LicenseSymbol("CC0-1.0") in spdx_info.spdx_expressions
def test_license_file_detected(empty_directory): """Test whether---when given a file and a license file---the license file is detected and read. """ (empty_directory / "foo.py").touch() (empty_directory / "foo.py.license").write_text( "SPDX-Copyright: 2017 Mary Sue\nSPDX-License-Identifier: MIT\n") project = Project(empty_directory) spdx_info = project.spdx_info_of("foo.py") assert "2017 Mary Sue" in spdx_info.copyright_lines assert LicenseSymbol("MIT") in spdx_info.spdx_expressions
def read_symbols(self, translations_files): symbols_map = {} self.translations = [] for translations_file in translations_files.split(): translation_data = read_translations(translations_file) self.translations.append(translation_data) for lic_key in translation_data: if lic_key not in symbols_map: symbols_map[lic_key] = set() for val in translation_data[lic_key]: symbols_map[lic_key].add(val) return [LicenseSymbol(key=key, aliases=tuple(value)) for key, value in symbols_map.items()]
def test_spdx_info_of_no_duplicates(empty_directory): """A file contains the same lines twice. The SpdxInfo only contains those lines once. """ spdx_line = "SPDX-License-Identifier: GPL-3.0-or-later\n" copyright_line = "SPDX-Copyright: 2017 Free Software Foundation Europe\n" text = spdx_line + copyright_line (empty_directory / "foo.py").write_text(text * 2) project = Project(empty_directory) spdx_info = project.spdx_info_of("foo.py") assert len(spdx_info.spdx_expressions) == 1 assert LicenseSymbol("GPL-3.0-or-later") in spdx_info.spdx_expressions assert len(spdx_info.copyright_lines) == 1 assert "2017 Free Software Foundation Europe" in spdx_info.copyright_lines
def test_copyright_from_dep5(copyright): """Verify that the glob in the dep5 file is matched.""" result = _util._copyright_from_dep5("doc/foo.rst", copyright) assert LicenseSymbol("CC0-1.0") in result.spdx_expressions assert "2017 Mary Sue" in result.copyright_lines