Skip to content

Commit 3f37e5f

Browse files
fix: adapt tests to API changes (#19)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Pinning and asset caching operations are now asynchronous. Plugin implementations and callers must use await for these actions. * Unified caching/pinning terminology replaces prior archiving usage. * **Tests** * Updated tests to exercise asynchronous pinning and caching flows. * Added a dedicated pinning test. * Simplified environment setup in tests with explicit keyword arguments for settings, shell executable, temp directories, and prefixes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 713d909 commit 3f37e5f

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

snakemake_interface_software_deployment_plugins/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class PinnableEnvBase(ABC):
247247
def pinfile_extension(cls) -> str: ...
248248

249249
@abstractmethod
250-
def pin(self) -> None:
250+
async def pin(self) -> None:
251251
"""Pin the environment to potentially more concrete versions than defined.
252252
Only implement this base class if pinning makes sense for your kind of
253253
environment. Pinfile has to be written to self.pinfile.
@@ -269,7 +269,7 @@ class CacheableEnvBase(ABC):
269269
async def get_cache_assets(self) -> Iterable[str]: ...
270270

271271
@abstractmethod
272-
def cache_assets(self) -> None:
272+
async def cache_assets(self) -> None:
273273
"""Determine environment assets and store any associated information or data to
274274
self.cache_path.
275275
"""

snakemake_interface_software_deployment_plugins/tests.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
from abc import ABC, abstractmethod
22
import asyncio
33
from copy import deepcopy
4-
import tempfile
54
from typing import Optional, Type
65
import subprocess as sp
76

87
import pytest
98

109
from snakemake_interface_software_deployment_plugins import (
11-
ArchiveableEnvBase,
10+
CacheableEnvBase,
1211
DeployableEnvBase,
1312
EnvBase,
1413
EnvSpecBase,
1514
EnvSpecSourceFile,
15+
PinnableEnvBase,
1616
SoftwareReport,
1717
)
1818
from snakemake_interface_software_deployment_plugins.settings import (
@@ -52,10 +52,22 @@ def get_test_cmd(self) -> str:
5252
...
5353

5454
@abstractmethod
55-
def get_software_deployment_provider_settings(
55+
def get_settings(
5656
self,
5757
) -> Optional[SoftwareDeploymentSettingsBase]: ...
5858

59+
@abstractmethod
60+
def get_settings_cls(self) -> Optional[Type[SoftwareDeploymentSettingsBase]]: ...
61+
62+
def test_envspec_str(self):
63+
print("env spec", str(self.get_env_spec()))
64+
65+
def test_default_settings(self):
66+
settings_cls = self.get_settings_cls()
67+
if settings_cls is None:
68+
pytest.skip("No settings class defined.")
69+
settings_cls()
70+
5971
def test_shellcmd(self, tmp_path):
6072
env = self._get_env(tmp_path)
6173

@@ -80,13 +92,24 @@ def test_deploy(self, tmp_path):
8092

8193
def test_archive(self, tmp_path):
8294
env = self._get_env(tmp_path)
83-
if not isinstance(env, ArchiveableEnvBase):
84-
pytest.skip("Environment either not deployable or not archiveable.")
95+
if not isinstance(env, CacheableEnvBase):
96+
pytest.skip("Environment either not deployable or not cacheable.")
97+
98+
asyncio.run(env.cache_assets())
8599

86100
self._deploy(env, tmp_path)
87101

88-
asyncio.run(env.archive())
89-
assert any((tmp_path / "archives").iterdir())
102+
assert any(env.cache_path.iterdir())
103+
104+
def test_pin(self, tmp_path):
105+
env = self._get_env(tmp_path)
106+
if not isinstance(env, PinnableEnvBase):
107+
pytest.skip("Environment is not pinnable.")
108+
109+
asyncio.run(env.pin())
110+
assert env.pinfile.exists()
111+
print("Pinfile content:", env.pinfile.read_text(), sep="\n")
112+
self._deploy(env, tmp_path)
90113

91114
def test_report_software(self, tmp_path):
92115
env = self._get_env(tmp_path)
@@ -119,16 +142,25 @@ def _get_cached_env_spec(self):
119142
def _get_env(self, tmp_path) -> EnvBase:
120143
env_cls = self.get_env_cls()
121144
spec = self._get_cached_env_spec()
122-
args = {
123-
"settings": self.get_software_deployment_provider_settings(),
124-
"tempdir": tempfile.gettempdir(),
125-
}
126-
if issubclass(env_cls, DeployableEnvBase):
127-
args["deployment_prefix"] = tmp_path / "deployments"
128-
if issubclass(env_cls, ArchiveableEnvBase):
129-
args["archive_prefix"] = tmp_path / "archives"
145+
146+
tempdir = tmp_path / "temp"
147+
deployment_prefix = tmp_path / "deployments"
148+
cache_prefix = tmp_path / "cache"
149+
pinfile_prefix = tmp_path / "pinfiles"
150+
tempdir.mkdir(parents=True, exist_ok=True)
151+
deployment_prefix.mkdir(parents=True, exist_ok=True)
152+
cache_prefix.mkdir(parents=True, exist_ok=True)
153+
pinfile_prefix.mkdir(parents=True, exist_ok=True)
154+
130155
return env_cls(
131-
spec=spec, within=None, shell_executable=self.shell_executable, **args
156+
spec=spec,
157+
within=None,
158+
settings=self.get_settings(),
159+
shell_executable=self.shell_executable,
160+
tempdir=tempdir,
161+
deployment_prefix=deployment_prefix,
162+
cache_prefix=cache_prefix,
163+
pinfile_prefix=pinfile_prefix,
132164
)
133165

134166
def _deploy(self, env: DeployableEnvBase, tmp_path):

0 commit comments

Comments
 (0)