fix: moves tests
This commit is contained in:
parent
695b0db001
commit
de8ab6afdd
1 changed files with 71 additions and 0 deletions
71
rhodecode/tests/test_lib_migration.py
Normal file
71
rhodecode/tests/test_lib_migration.py
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue