From 6ed98d9e0d273e9bd8aa0d7866e2406b84f480ec Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Mon, 30 Oct 2023 08:05:30 -0400 Subject: [PATCH] Replace pkg_resources in test_load 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: https://github.com/python/importlib_resources/issues/60 --- pint/testsuite/test_unit.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pint/testsuite/test_unit.py b/pint/testsuite/test_unit.py index c1a2704b5..7beebb534 100644 --- a/pint/testsuite/test_unit.py +++ b/pint/testsuite/test_unit.py @@ -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()