Skip to content

Commit

Permalink
fix: apply Max's workaround for pkg_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
tomli380576 committed Dec 4, 2024
1 parent 59f7015 commit d6bc8a5
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@
from checkbox_support.parsers.v4l2_compliance import parse_v4l2_compliance
import unittest as ut
from unittest.mock import patch, MagicMock
from pkg_resources import resource_filename

try:
# new in python 3.9
from importlib import resources

def read_file_as_str(name: str):
resource = "parsers/tests/v4l2_compliance_data/{}.txt".format(name)
filename = resource_filename("checkbox_support", resource)
with open(filename) as f:
return f.read()
def read_file_as_str(name: str):
resource_path = "parsers/tests/v4l2_compliance_data/{}.txt".format(
name
)
ref = resources.files("checkbox_support")
file_ref = ref.joinpath(resource_path)
with file_ref.open("r") as f:
return f.read()

except ImportError:
# 3.5 fallback
from pkg_resources import resource_filename

def read_file_as_str(name: str):
resource = "parsers/tests/v4l2_compliance_data/{}.txt".format(name)
filename = resource_filename("checkbox_support", resource)
with open(filename) as f:
return f.read()


class TestV4L2ComplianceParser(ut.TestCase):
Expand Down

0 comments on commit d6bc8a5

Please sign in to comment.