1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
From: Ole Streicher <olebole@debian.org>
Date: Fri, 10 Aug 2018 08:35:39 +0200
Subject: Emulate importlib.resources for Python <= 3.6
---
asdf/tests/helpers.py | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/asdf/tests/helpers.py b/asdf/tests/helpers.py
index 24ccb10..8c999b1 100644
--- a/asdf/tests/helpers.py
+++ b/asdf/tests/helpers.py
@@ -50,16 +50,17 @@ __all__ = ['get_test_data_path', 'assert_tree_match', 'assert_roundtrip_tree',
def get_test_data_path(name, module=None):
- if resources is None:
- raise RuntimeError("The importlib_resources package is required to get"
- " test data on systems with Python < 3.7")
-
if module is None:
from . import data as test_data
module = test_data
- with resources.path(module, name) as path:
- return str(path)
+ if resources is not None:
+ with resources.path(module, name) as path:
+ return str(path)
+ elif name:
+ return os.path.join(os.path.dirname(module.__file__), name)
+ else:
+ return os.path.dirname(module.__file__)
def assert_tree_match(old_tree, new_tree, ctx=None,
|