diff options
-rw-r--r-- | src/pkgcore/ebuild/repo_objs.py | 8 | ||||
-rw-r--r-- | tests/ebuild/test_repository.py | 22 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/pkgcore/ebuild/repo_objs.py b/src/pkgcore/ebuild/repo_objs.py index 3359305b..47422dc1 100644 --- a/src/pkgcore/ebuild/repo_objs.py +++ b/src/pkgcore/ebuild/repo_objs.py @@ -526,11 +526,13 @@ class Licenses(metaclass=WeakInstMeta): d = read_dict(self.license_groups_path, splitter=" ") for k, v in d.items(): d[k] = set(v.split()) - except EnvironmentError: - return mappings.ImmutableDict() + except EnvironmentError as e: + if e.errno != errno.ENOENT: + logger.error(f"failed reading parsing license_groups: {e}") + d = {} except BashParseError as pe: logger.error(f"failed parsing license_groups: {pe}") - return mappings.ImmutableDict() + d = {} for li in self._license_instances: for k, v in li.groups.items(): if k in d: diff --git a/tests/ebuild/test_repository.py b/tests/ebuild/test_repository.py index 71366ba2..10c0b93b 100644 --- a/tests/ebuild/test_repository.py +++ b/tests/ebuild/test_repository.py @@ -296,7 +296,7 @@ class TestSlavedTree(TestUnconfiguredTree): repo = self.mk_tree(slave_repo) assert set(repo.licenses) == set(master_licenses + slave_licenses) - def test_license_groups(self, master_repo, slave_repo): + def test_license_groups(self, master_repo, slave_repo, caplog): master_licenses = ("GPL-2", "BSD") slave_licenses = ("BSD-2", "MIT") @@ -324,6 +324,26 @@ class TestSlavedTree(TestUnconfiguredTree): } assert "BSD" in repo.licenses.groups["MISC-FREE"] + # verify it warns when parsing fails + (slave_repo / "profiles" / "license_groups").write_text('X"') + caplog.clear() + repo = self.mk_tree(slave_repo) + assert set(repo.licenses.groups) == {"FREE", "OSI-APPROVED"} + assert caplog.text + + # verify it warns when the file exists but it can't read it. + (slave_repo / "profiles" / "license_groups").write_text("") + (slave_repo / "profiles" / "license_groups").chmod(000) + caplog.clear() + repo = self.mk_tree(slave_repo) + assert set(repo.licenses.groups) == {"FREE", "OSI-APPROVED"} + assert caplog.text + + # verify it handles a missing license group. + (slave_repo / "profiles" / "license_groups").unlink() + repo = self.mk_tree(slave_repo) + assert set(repo.licenses.groups) == {"FREE", "OSI-APPROVED"} + def test_package_deprecated(self, slave_repo, master_repo): (master_repo / "profiles" / "package.deprecated").write_text( textwrap.dedent( |