From de8ab6afdd70b46c554bf280bf0cc6c2357727e5 Mon Sep 17 00:00:00 2001 From: ievgenii vdovenko Date: Fri, 3 Oct 2025 15:42:53 +0200 Subject: [PATCH] fix: moves tests --- rhodecode/tests/test_lib_migration.py | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 rhodecode/tests/test_lib_migration.py diff --git a/rhodecode/tests/test_lib_migration.py b/rhodecode/tests/test_lib_migration.py new file mode 100644 index 00000000..3714b201 --- /dev/null +++ b/rhodecode/tests/test_lib_migration.py @@ -0,0 +1,71 @@ +import pkg_resources +import importlib + +import pytest + +from rhodecode.lib.dbmigrate.migrate.versioning.util import load_dotted + + +class TestPkgResourcesLibMigrations: + """ + when pkg_resources is removed, these tests can be safely removed + """ + + @pytest.mark.parametrize( + "module, resource", + [ + ("rc_chat", "static"), + ("deform", "templates"), + ("rhodecode", "templates/forms"), + ], + ) + def test_pkg_resources_resource_filename_lib_migration(self, module, resource): + res = pkg_resources.resource_filename(module, resource) + + with importlib.resources.as_file(importlib.resources.files(module).joinpath(resource)) as static_path: + migrated_res = str(static_path) + + assert res == migrated_res + + def test_pkg_resources_EntryPoint_lib_migration(self): + package_class = "rhodecode.lib.dbmigrate.migrate.versioning.util.keyedinstance:KeyedInstance" + loaded_class = pkg_resources.EntryPoint.parse("x=%s" % package_class).load(False) + loaded_class_migrated = load_dotted(package_class) + assert loaded_class == loaded_class_migrated + + def test_pkg_resources_resource_string_lib_migration(self): + module = "rhodecode" + path = "config/licenses.json" + res = pkg_resources.resource_string(module, path) + + migrated_res = importlib.resources.files(module).joinpath(path).read_bytes() + + assert res == migrated_res + + def test_pkg_resources_working_set_lib_migration(self): + mods = dict( + [(p.project_name, {"version": p.version, "location": p.location}) for p in pkg_resources.working_set] + ) + + migration_mods = { + d.metadata.get("Name"): { + "version": d.version, + "location": str( + next( + ( + p.locate().parent.parent + for p in (d.files or []) + if p.parent.name.endswith((".dist-info", ".egg-info")) + ), + next(iter(d.files)).locate().parent if d.files else None, + ) + ), + } + for d in importlib.metadata.distributions() + } + + mods_keys = sorted(list(mods.keys())) + migration_mods_keys = sorted(list(migration_mods.keys())) + + assert len(mods_keys) == len(migration_mods_keys) + assert mods_keys == migration_mods_keys