diff options
author | shadchin <shadchin@yandex-team.com> | 2024-02-09 11:05:14 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2024-02-09 11:16:07 +0300 |
commit | 24a348987aa5112cad623b5e54700ac0df8214cc (patch) | |
tree | e6bbd207e1d7b5ade8dd0de458a53db738da14d9 /library/python/runtime_py3/test/test_resources.py | |
parent | d6b336cea28df9edc2760b96c20400f8af70dcd5 (diff) | |
download | ydb-24a348987aa5112cad623b5e54700ac0df8214cc.tar.gz |
Rework joinpath for importlib.resources
Diffstat (limited to 'library/python/runtime_py3/test/test_resources.py')
-rw-r--r-- | library/python/runtime_py3/test/test_resources.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/library/python/runtime_py3/test/test_resources.py b/library/python/runtime_py3/test/test_resources.py index 059cc039e6..75c1eb3549 100644 --- a/library/python/runtime_py3/test/test_resources.py +++ b/library/python/runtime_py3/test/test_resources.py @@ -71,3 +71,43 @@ def test_read_text_missing(): ) def test_contents_good_path(package, expected): assert sorted(ir.contents(package)) == sorted(expected) + + +def test_files_joinpath(): + assert ir.files("resources") / "submodule" + assert ir.files("resources") / "foo.txt" + assert ir.files("resources") / "submodule" / "bar.txt" + assert ir.files("resources.submodule") / "bar.txt" + + +@pytest.mark.parametrize( + "package, resource, expected", + ( + ("resources", "foo.txt", b"bar"), + ("resources.submodule", "bar.txt", b"foo"), + ), +) +def test_files_read_bytes(package, resource, expected): + assert (ir.files(package) / resource).read_bytes() == expected + + +@pytest.mark.parametrize( + "package, resource, expected", + ( + ("resources", "foo.txt", "bar"), + ("resources.submodule", "bar.txt", "foo"), + ), +) +def test_files_read_text(package, resource, expected): + assert (ir.files(package) / resource).read_text() == expected + + +@pytest.mark.parametrize( + "package, expected", + ( + ("resources", ("foo.txt", "submodule")), + ("resources.submodule", ("bar.txt",)), + ), +) +def test_files_iterdir(package, expected): + assert tuple(resource.name for resource in ir.files(package).iterdir()) == expected |