projects/aports·blob master · refs

108 lines · 4.8 KiB

1diff -rupN a/pyroma/tests.py b/pyroma/tests.py
2--- a/pyroma/tests.py 2023-02-25 12:57:28.000000000 +0000
3+++ b/pyroma/tests.py 2026-03-31 22:59:57.210000000 +0000
4@@ -3,13 +3,14 @@ import json
5 import os
6 import unittest
7 import unittest.mock
8-from pkg_resources import resource_filename, resource_string
9+from importlib.resources import as_file, files
10 from xmlrpc import client as xmlrpclib
11
12 from pyroma import projectdata, distributiondata, pypidata
13 from pyroma.ratings import rate
14
15-long_description = resource_string(__name__, os.path.join("testdata", "complete", "README.txt"))
16+ld_ref = files(__name__).joinpath("testdata", "complete", "README.txt")
17+long_description = ld_ref.read_bytes()
18 if not isinstance(long_description, str):
19 long_description = long_description.decode()
20 # Translate newlines to universal format
21@@ -44,10 +45,11 @@ COMPLETE = {
22
23 class ProxyStub:
24 def set_debug_context(self, dataname, real_class, developmode):
25- filename = resource_filename(__name__, os.path.join("testdata", "xmlrpcdata", dataname))
26+ rf = files(__name__).joinpath("testdata", "xmlrpcdata", dataname)
27 data = {}
28- with open(filename, encoding="UTF-8") as f:
29- exec(f.read(), None, data)
30+ with as_file(rf) as path:
31+ with open(path, encoding="UTF-8") as f:
32+ exec(f.read(), None, data)
33 self.args = data["args"]
34 self.kw = data["kw"]
35 self._data = data["data"]
36@@ -104,9 +106,10 @@ class RatingsTest(unittest.TestCase):
37 maxDiff = None
38
39 def _get_file_rating(self, dirname):
40- directory = resource_filename(__name__, os.path.join("testdata", dirname))
41- data = projectdata.get_data(directory)
42- return rate(data)
43+ rf = files(__name__).joinpath("testdata", dirname)
44+ with as_file(rf) as directory:
45+ data = projectdata.get_data(directory)
46+ return rate(data)
47
48 def test_complete(self):
49 rating = self._get_file_rating("complete")
50@@ -267,9 +270,10 @@ class PyPITest(unittest.TestCase):
51 @unittest.mock.patch("xmlrpc.client.ServerProxy", proxystub)
52 @unittest.mock.patch("pyroma.pypidata._get_project_data")
53 def test_distribute(self, projectdatamock):
54- datafile = resource_filename(__name__, os.path.join("testdata", "jsondata", "distribute.json"))
55- with open(datafile, "rt", encoding="UTF-8") as file:
56- projectdatamock.return_value = json.load(file)
57+ rf = files(__name__).joinpath("testdata", "jsondata", "distribute.json")
58+ with as_file(rf) as datafile:
59+ with open(datafile, "rt", encoding="UTF-8") as file:
60+ projectdatamock.return_value = json.load(file)
61
62 proxystub.set_debug_context("distributedata.py", xmlrpclib.ServerProxy, False)
63
64@@ -297,9 +301,10 @@ class PyPITest(unittest.TestCase):
65 @unittest.mock.patch("xmlrpc.client.ServerProxy", proxystub)
66 @unittest.mock.patch("pyroma.pypidata._get_project_data")
67 def test_complete(self, projectdatamock):
68- datafile = resource_filename(__name__, os.path.join("testdata", "jsondata", "complete.json"))
69- with open(datafile, "rt", encoding="UTF-8") as file:
70- projectdatamock.return_value = json.load(file)
71+ rf = files(__name__).joinpath("testdata", "jsondata", "complete.json")
72+ with as_file(rf) as datafile:
73+ with open(datafile, "rt", encoding="UTF-8") as file:
74+ projectdatamock.return_value = json.load(file)
75
76 proxystub.set_debug_context("completedata.py", xmlrpclib.ServerProxy, False)
77
78@@ -314,10 +319,10 @@ class ProjectDataTest(unittest.TestCase)
79 maxDiff = None
80
81 def test_complete(self):
82- directory = resource_filename(__name__, os.path.join("testdata", "complete"))
83-
84- data = projectdata.get_data(directory)
85- self.assertEqual(data, COMPLETE)
86+ rf = files(__name__).joinpath("testdata", "complete")
87+ with as_file(rf) as directory:
88+ data = projectdata.get_data(directory)
89+ self.assertEqual(data, COMPLETE)
90
91
92 class DistroDataTest(unittest.TestCase):
93@@ -325,9 +330,9 @@ class DistroDataTest(unittest.TestCase):
94 maxDiff = None
95
96 def test_complete(self):
97- directory = resource_filename(__name__, os.path.join("testdata", "distributions"))
98-
99- for filename in os.listdir(directory):
100- if filename.startswith("complete"):
101- data = distributiondata.get_data(os.path.join(directory, filename))
102- self.assertEqual(data, COMPLETE)
103+ rf = files(__name__).joinpath("testdata", "distributions")
104+ with as_file(rf) as directory:
105+ for filename in os.listdir(directory):
106+ if filename.startswith("complete"):
107+ data = distributiondata.get_data(os.path.join(directory, filename))
108+ self.assertEqual(data, COMPLETE)