Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the commentjson test dependency with re.sub #141

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ lint =
isort
types-requests
test =
commentjson
packaging
pytest
release =
Expand Down
16 changes: 8 additions & 8 deletions tests/functional/cocoapods/test_resolvers_cocoapods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import re
import string

import commentjson # type: ignore
import pytest

from resolvelib import AbstractProvider, ResolutionImpossible, Resolver
Expand Down Expand Up @@ -124,14 +123,15 @@ def _version_in_specset(version, specset):


def _safe_json_load(filename):
# Some fixtures has comments so the stdlib implementation doesn't work.
# We only use commentjson if we absolutely need to because it's SLOW.
try:
with open(filename) as f:
# Some fixtures have comments, so strip them if first parse fails.
# We only do this in case of failure to avoid loading all JSON files to strings before parsing.
uranusjr marked this conversation as resolved.
Show resolved Hide resolved
with open(filename) as f:
try:
data = json.load(f)
except ValueError:
with open(filename) as f:
data = commentjson.load(f)
except ValueError:
f.seek(0)
strippedjson = re.sub(r"//.*$", "", f.read(), flags=re.MULTILINE)
data = json.loads(strippedjson)
return data


Expand Down
Loading