aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3/test/test_resources.py
diff options
context:
space:
mode:
authornkozlovskiy <nmk@ydb.tech>2023-09-29 12:24:06 +0300
committernkozlovskiy <nmk@ydb.tech>2023-09-29 12:41:34 +0300
commite0e3e1717e3d33762ce61950504f9637a6e669ed (patch)
treebca3ff6939b10ed60c3d5c12439963a1146b9711 /library/python/runtime_py3/test/test_resources.py
parent38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff)
downloadydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz
add ydb deps
Diffstat (limited to 'library/python/runtime_py3/test/test_resources.py')
-rw-r--r--library/python/runtime_py3/test/test_resources.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/library/python/runtime_py3/test/test_resources.py b/library/python/runtime_py3/test/test_resources.py
new file mode 100644
index 0000000000..059cc039e6
--- /dev/null
+++ b/library/python/runtime_py3/test/test_resources.py
@@ -0,0 +1,73 @@
+import importlib.resources as ir
+
+import pytest
+
+
+@pytest.mark.parametrize(
+ "package, resource",
+ (
+ ("resources", "foo.txt"),
+ ("resources.submodule", "bar.txt"),
+ ),
+)
+def test_is_resource_good_path(package, resource):
+ assert ir.is_resource(package, resource)
+
+
+@pytest.mark.parametrize(
+ "package, resource",
+ (
+ ("resources", "111.txt"),
+ ("resources.submodule", "222.txt"),
+ ),
+)
+def test_is_resource_missing(package, resource):
+ assert not ir.is_resource(package, resource)
+
+
+def test_is_resource_subresource_directory():
+ # Directories are not resources.
+ assert not ir.is_resource("resources", "submodule")
+
+
+@pytest.mark.parametrize(
+ "package, resource, expected",
+ (
+ ("resources", "foo.txt", b"bar"),
+ ("resources.submodule", "bar.txt", b"foo"),
+ ),
+)
+def test_read_binary_good_path(package, resource, expected):
+ assert ir.read_binary(package, resource) == expected
+
+
+def test_read_binary_missing():
+ with pytest.raises(FileNotFoundError):
+ ir.read_binary("resources", "111.txt")
+
+
+@pytest.mark.parametrize(
+ "package, resource, expected",
+ (
+ ("resources", "foo.txt", "bar"),
+ ("resources.submodule", "bar.txt", "foo"),
+ ),
+)
+def test_read_text_good_path(package, resource, expected):
+ assert ir.read_text(package, resource) == expected
+
+
+def test_read_text_missing():
+ with pytest.raises(FileNotFoundError):
+ ir.read_text("resources", "111.txt")
+
+
+@pytest.mark.parametrize(
+ "package, expected",
+ (
+ ("resources", ["submodule", "foo.txt"]),
+ ("resources.submodule", ["bar.txt"]),
+ ),
+)
+def test_contents_good_path(package, expected):
+ assert sorted(ir.contents(package)) == sorted(expected)