dropping support for pype repositories as zip files

This commit is contained in:
Ondřej Samohel 2021-01-07 19:21:13 +01:00 committed by Ondrej Samohel
parent e5d39665d8
commit a6bbee9abf
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
5 changed files with 559 additions and 153 deletions

View file

@ -2,9 +2,13 @@
"""Test suite for repos bootstrapping (install)."""
import os
import sys
from collections import namedtuple
from pathlib import Path
import pytest
from zipfile import ZipFile
import appdirs
import pytest
from igniter.bootstrap_repos import BootstrapRepos
from igniter.bootstrap_repos import PypeVersion
from pype.lib import PypeSettingsRegistry
@ -116,6 +120,20 @@ def test_get_version_path_from_list():
assert path == Path("/bar/baz")
def test_search_string_for_pype_version(printer):
strings = [
("3.0.1", True),
("foo-3.0", False),
("foo-3.0.1", True),
("3", False),
("foo-3.0.1-staging-client", True),
("foo-3.0.1-bar-baz", True)
]
for ver_string in strings:
printer(f"testing {ver_string[0]} should be {ver_string[1]}")
assert PypeVersion.version_in_str(ver_string[0])[0] == ver_string[1]
def test_install_live_repos(fix_bootstrap, printer):
rf = fix_bootstrap.install_live_repos()
sep = os.path.sep
@ -125,8 +143,7 @@ def test_install_live_repos(fix_bootstrap, printer):
f"{rf}{sep}avalon-unreal-integration",
f"{rf}{sep}maya-look-assigner",
f"{rf}{sep}pyblish-base",
f"{rf}{sep}pype",
f"{rf}{sep}pype-config"
f"{rf}{sep}pype"
]
printer("testing zip creation")
assert os.path.exists(rf), "zip archive was not created"
@ -147,92 +164,186 @@ def test_install_live_repos(fix_bootstrap, printer):
def test_find_pype(fix_bootstrap, tmp_path_factory, monkeypatch, printer):
test_pype = namedtuple("Pype", "prefix version suffix type valid")
test_versions_1 = [
"pype-repositories-v5.5.1.zip",
"pype-repositories-v5.5.2-client.zip",
"pype-repositories-v5.5.3-client-strange.zip",
"pype-repositories-v5.5.4-staging.zip",
"pype-repositories-v5.5.5-staging-client.zip",
"pype-repositories-v5.6.3.zip",
"pype-repositories-v5.6.3-staging.zip"
test_pype(prefix="foo-v", version="5.5.1",
suffix=".zip", type="zip", valid=False),
test_pype(prefix="bar-v", version="5.5.2-client",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="baz-v", version="5.5.3-client-strange",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="bum-v", version="5.5.4-staging",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="zum-v", version="5.5.5-staging-client",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="fam-v", version="5.6.3",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="foo-v", version="5.6.3-staging",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="fim-v", version="5.6.3",
suffix=".zip", type="zip", valid=False),
test_pype(prefix="foo-v", version="5.6.4",
suffix=".txt", type="txt", valid=False),
test_pype(prefix="foo-v", version="5.7.1",
suffix="", type="dir", valid=False),
]
test_versions_2 = [
"pype-repositories-v7.2.6.zip",
"pype-repositories-v7.2.7-client.zip",
"pype-repositories-v7.2.8-client-strange.zip",
"pype-repositories-v7.2.9-staging.zip",
"pype-repositories-v7.2.10-staging-client.zip",
"pype-repositories-v7.0.1.zip",
test_pype(prefix="foo-v", version="10.0.0",
suffix=".txt", type="txt", valid=False),
test_pype(prefix="lom-v", version="7.2.6",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="bom-v", version="7.2.7-client",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="woo-v", version="7.2.8-client-strange",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="loo-v", version="7.2.10-staging-client",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="kok-v", version="7.0.1",
suffix=".zip", type="zip", valid=True)
]
test_versions_3 = [
"pype-repositories-v3.0.0.zip",
"pype-repositories-v3.0.1.zip",
"pype-repositories-v4.1.0.zip",
"pype-repositories-v4.1.2.zip",
"pype-repositories-v3.0.1-client.zip",
"pype-repositories-v3.0.1-client-strange.zip",
"pype-repositories-v3.0.1-staging.zip",
"pype-repositories-v3.0.1-staging-client.zip",
"pype-repositories-v3.2.0.zip",
test_pype(prefix="foo-v", version="3.0.0",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="goo-v", version="3.0.1",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="hoo-v", version="4.1.0",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="foo-v", version="4.1.2",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="foo-v", version="3.0.1-client",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="foo-v", version="3.0.1-client-strange",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="foo-v", version="3.0.1-staging",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="foo-v", version="3.0.1-staging-client",
suffix=".zip", type="zip", valid=True),
test_pype(prefix="foo-v", version="3.2.0",
suffix=".zip", type="zip", valid=True)
]
def _create_invalid_zip(path: Path):
with ZipFile(path, "w") as zf:
zf.writestr("test.foo", "test")
def _create_valid_zip(path: Path, version: str):
with ZipFile(path, "w") as zf:
zf.writestr(
"pype/pype/version.py", f"__version__ = '{version}'\n\n")
def _create_invalid_dir(path: Path):
path.mkdir(parents=True, exist_ok=True)
with open(path / "invalid", "w") as fp:
fp.write("invalid")
def _create_valid_dir(path: Path, version: str):
pype_path = path / "pype"
version_path = path / "pype" / "version.py"
pype_path.mkdir(parents=True, exist_ok=True)
with open(version_path, "w") as fp:
fp.write(f"__version__ = '{version}'\n\n")
def _build_test_item(path, item):
test_path = path / "{}{}{}".format(item.prefix,
item.version,
item.suffix)
if item.type == "zip":
if item.valid:
_create_valid_zip(test_path, item.version)
else:
_create_invalid_zip(test_path)
elif item.type == "dir":
if item.valid:
_create_valid_dir(test_path, item.version)
else:
_create_invalid_dir(test_path)
else:
with open(test_path, "w") as fp:
fp.write("foo")
# in PYPE_PATH
e_path = tmp_path_factory.mktemp("environ")
# create files and directories for test
for test_file in test_versions_1:
with open(e_path / test_file, "w") as fp:
fp.write(test_file)
_build_test_item(e_path, test_file)
# in pypePath registry
r_path = tmp_path_factory.mktemp("pypePath")
p_path = tmp_path_factory.mktemp("pypePath")
for test_file in test_versions_2:
with open(r_path / test_file, "w") as fp:
fp.write(test_file)
_build_test_item(p_path, test_file)
# in data dir
for test_file in test_versions_3:
with open(os.path.join(fix_bootstrap.data_dir, test_file), "w") as fp:
fp.write(test_file)
d_path = tmp_path_factory.mktemp("dataPath")
for test_file in test_versions_2:
_build_test_item(d_path, test_file)
result = fix_bootstrap.find_pype()
# in provided path
g_path = tmp_path_factory.mktemp("providedPath")
for test_file in test_versions_3:
_build_test_item(g_path, test_file)
result = fix_bootstrap.find_pype(g_path, True)
# we should have results as file were created
assert result is not None, "no Pype version found"
# latest item in `result` should be latest version found.
assert result[-1].path == Path(
fix_bootstrap.data_dir / test_versions_3[3]
), "not a latest version of Pype 3"
expected_path = Path(
g_path / "{}{}{}".format(
test_versions_3[3].prefix,
test_versions_3[3].version,
test_versions_3[3].suffix
)
)
assert result[-1].path == expected_path, "not a latest version of Pype 3"
monkeypatch.setenv("PYPE_PATH", e_path.as_posix())
result = fix_bootstrap.find_pype()
result = fix_bootstrap.find_pype(include_zips=True)
# we should have results as file were created
assert result is not None, "no Pype version found"
# latest item in `result` should be latest version found.
assert result[-1].path == Path(
e_path / test_versions_1[5]
), "not a latest version of Pype 1"
expected_path = Path(
e_path / "{}{}{}".format(
test_versions_1[5].prefix,
test_versions_1[5].version,
test_versions_1[5].suffix
)
)
assert result[-1].path == expected_path, "not a latest version of Pype 1"
monkeypatch.delenv("PYPE_PATH", raising=False)
# mock appdirs user_data_dir
def mock_user_data_dir(*args, **kwargs):
return r_path.as_posix()
return d_path.as_posix()
monkeypatch.setattr(appdirs, "user_data_dir", mock_user_data_dir)
fix_bootstrap.registry = PypeSettingsRegistry()
fix_bootstrap.registry.set_item("pypePath", r_path.as_posix())
fix_bootstrap.registry.set_item("pypePath", d_path.as_posix())
result = fix_bootstrap.find_pype()
result = fix_bootstrap.find_pype(include_zips=True)
# we should have results as file were created
assert result is not None, "no Pype version found"
# latest item in `result` should be latest version found.
assert result[-1].path == Path(
r_path / test_versions_2[4]
), "not a latest version of Pype 2"
expected_path = Path(
d_path / "{}{}{}".format(
test_versions_2[4].prefix,
test_versions_2[4].version,
test_versions_2[4].suffix
)
)
assert result[-1].path == expected_path, "not a latest version of Pype 2"
result = fix_bootstrap.find_pype(e_path)
result = fix_bootstrap.find_pype(e_path, True)
assert result is not None, "no Pype version found"
assert result[-1].path == Path(
e_path / test_versions_1[5]
), "not a latest version of Pype 1"
expected_path = Path(
e_path / "{}{}{}".format(
test_versions_1[5].prefix,
test_versions_1[5].version,
test_versions_1[5].suffix
)
)
assert result[-1].path == expected_path, "not a latest version of Pype 1"