diff -rupN a/pyroma/tests.py b/pyroma/tests.py --- a/pyroma/tests.py 2023-02-25 12:57:28.000000000 +0000 +++ b/pyroma/tests.py 2026-03-31 22:59:57.210000000 +0000 @@ -3,13 +3,14 @@ import json import os import unittest import unittest.mock -from pkg_resources import resource_filename, resource_string +from importlib.resources import as_file, files from xmlrpc import client as xmlrpclib from pyroma import projectdata, distributiondata, pypidata from pyroma.ratings import rate -long_description = resource_string(__name__, os.path.join("testdata", "complete", "README.txt")) +ld_ref = files(__name__).joinpath("testdata", "complete", "README.txt") +long_description = ld_ref.read_bytes() if not isinstance(long_description, str): long_description = long_description.decode() # Translate newlines to universal format @@ -44,10 +45,11 @@ COMPLETE = { class ProxyStub: def set_debug_context(self, dataname, real_class, developmode): - filename = resource_filename(__name__, os.path.join("testdata", "xmlrpcdata", dataname)) + rf = files(__name__).joinpath("testdata", "xmlrpcdata", dataname) data = {} - with open(filename, encoding="UTF-8") as f: - exec(f.read(), None, data) + with as_file(rf) as path: + with open(path, encoding="UTF-8") as f: + exec(f.read(), None, data) self.args = data["args"] self.kw = data["kw"] self._data = data["data"] @@ -104,9 +106,10 @@ class RatingsTest(unittest.TestCase): maxDiff = None def _get_file_rating(self, dirname): - directory = resource_filename(__name__, os.path.join("testdata", dirname)) - data = projectdata.get_data(directory) - return rate(data) + rf = files(__name__).joinpath("testdata", dirname) + with as_file(rf) as directory: + data = projectdata.get_data(directory) + return rate(data) def test_complete(self): rating = self._get_file_rating("complete") @@ -267,9 +270,10 @@ class PyPITest(unittest.TestCase): @unittest.mock.patch("xmlrpc.client.ServerProxy", proxystub) @unittest.mock.patch("pyroma.pypidata._get_project_data") def test_distribute(self, projectdatamock): - datafile = resource_filename(__name__, os.path.join("testdata", "jsondata", "distribute.json")) - with open(datafile, "rt", encoding="UTF-8") as file: - projectdatamock.return_value = json.load(file) + rf = files(__name__).joinpath("testdata", "jsondata", "distribute.json") + with as_file(rf) as datafile: + with open(datafile, "rt", encoding="UTF-8") as file: + projectdatamock.return_value = json.load(file) proxystub.set_debug_context("distributedata.py", xmlrpclib.ServerProxy, False) @@ -297,9 +301,10 @@ class PyPITest(unittest.TestCase): @unittest.mock.patch("xmlrpc.client.ServerProxy", proxystub) @unittest.mock.patch("pyroma.pypidata._get_project_data") def test_complete(self, projectdatamock): - datafile = resource_filename(__name__, os.path.join("testdata", "jsondata", "complete.json")) - with open(datafile, "rt", encoding="UTF-8") as file: - projectdatamock.return_value = json.load(file) + rf = files(__name__).joinpath("testdata", "jsondata", "complete.json") + with as_file(rf) as datafile: + with open(datafile, "rt", encoding="UTF-8") as file: + projectdatamock.return_value = json.load(file) proxystub.set_debug_context("completedata.py", xmlrpclib.ServerProxy, False) @@ -314,10 +319,10 @@ class ProjectDataTest(unittest.TestCase) maxDiff = None def test_complete(self): - directory = resource_filename(__name__, os.path.join("testdata", "complete")) - - data = projectdata.get_data(directory) - self.assertEqual(data, COMPLETE) + rf = files(__name__).joinpath("testdata", "complete") + with as_file(rf) as directory: + data = projectdata.get_data(directory) + self.assertEqual(data, COMPLETE) class DistroDataTest(unittest.TestCase): @@ -325,9 +330,9 @@ class DistroDataTest(unittest.TestCase): maxDiff = None def test_complete(self): - directory = resource_filename(__name__, os.path.join("testdata", "distributions")) - - for filename in os.listdir(directory): - if filename.startswith("complete"): - data = distributiondata.get_data(os.path.join(directory, filename)) - self.assertEqual(data, COMPLETE) + rf = files(__name__).joinpath("testdata", "distributions") + with as_file(rf) as directory: + for filename in os.listdir(directory): + if filename.startswith("complete"): + data = distributiondata.get_data(os.path.join(directory, filename)) + self.assertEqual(data, COMPLETE)