1 From 3e50054d836b655b0868520bae8b85a3c18967ef Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
3 Date: Wed, 8 Nov 2023 17:12:16 +0100
4 Subject: [PATCH] Replace the commentjson test dependency with re.sub
6 While at it, only open the json files once.
8 Co-authored-by: Maxwell G <maxwell@gtmx.me>
11 .../cocoapods/test_resolvers_cocoapods.py | 19 +++++++++++--------
12 2 files changed, 11 insertions(+), 9 deletions(-)
14 diff --git a/setup.cfg b/setup.cfg
15 index 5eddf2f..e080991 100644
18 @@ -44,7 +44,6 @@ lint =
26 diff --git a/tests/functional/cocoapods/test_resolvers_cocoapods.py b/tests/functional/cocoapods/test_resolvers_cocoapods.py
27 index 12dff46..f54e27d 100644
28 --- a/tests/functional/cocoapods/test_resolvers_cocoapods.py
29 +++ b/tests/functional/cocoapods/test_resolvers_cocoapods.py
34 -import commentjson # type: ignore
37 from resolvelib import AbstractProvider, ResolutionImpossible, Resolver
38 @@ -124,14 +123,18 @@ def _version_in_specset(version, specset):
41 def _safe_json_load(filename):
42 - # Some fixtures has comments so the stdlib implementation doesn't work.
43 - # We only use commentjson if we absolutely need to because it's SLOW.
45 - with open(filename) as f:
46 + # Some fixtures have comments so they are not valid json.
47 + # We could use commentjson/json5 to load them,
48 + # but it's easier to strip the comments.
49 + # We only do it when json.load() fails to avoid unnecessary loading
50 + # all the json files to strings.
51 + with open(filename) as f:
55 - with open(filename) as f:
56 - data = commentjson.load(f)
59 + strippedjson = re.sub(r"//.*$", "", f.read(), flags=re.MULTILINE)
60 + data = json.loads(strippedjson)