Skip to content

Commit

Permalink
Replace pkg_resources in test_load
Browse files Browse the repository at this point in the history
Replace pkg_resources.resource_filename with
importlib.resources.as_file. This removes an implicit dependency on
setuptools (to which pkg_resources belongs); furthermore, the entire
pkg_resources API is deprecated.

Regarding the switch from __file__ to __package__, see:
python/importlib_resources#60
  • Loading branch information
musicinmybrain committed Oct 30, 2023
1 parent f9e139e commit 6ed98d9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pint/testsuite/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ def test_define(self):
assert len(dir(ureg)) > 0

def test_load(self):
import pkg_resources
from importlib.resources import as_file, files

from .. import compat

data = pkg_resources.resource_filename(compat.__name__, "default_en.txt")
ureg1 = UnitRegistry()
ureg2 = UnitRegistry(data)
assert dir(ureg1) == dir(ureg2)
with pytest.raises(FileNotFoundError):
UnitRegistry(None).load_definitions("notexisting")
with as_file(files(compat.__package__).joinpath("default_en.txt")) as data:
ureg1 = UnitRegistry()
ureg2 = UnitRegistry(data)
assert dir(ureg1) == dir(ureg2)
with pytest.raises(FileNotFoundError):
UnitRegistry(None).load_definitions("notexisting")

def test_default_format(self):
ureg = UnitRegistry()
Expand Down

0 comments on commit 6ed98d9

Please sign in to comment.