Skip to content

Commit

Permalink
Add podman unit tests (#312)
Browse files Browse the repository at this point in the history
Podman unit tests for docker runner.
  • Loading branch information
dfeddema authored Aug 7, 2023
1 parent e9b5844 commit e31985b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions runners/mlcube_docker/mlcube_docker/tests/test_docker_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from mlcube.shell import Shell

_HAVE_DOCKER: bool = Shell.run(["docker", "--version"], on_error="ignore") == 0
_HAVE_PODMAN: bool = Shell.run(["podman", "--version"], on_error="ignore") == 0


_MLCUBE_DEFAULT_ENTRY_POINT = """
docker:
Expand Down Expand Up @@ -54,13 +56,13 @@ def setUp(self) -> None:
def tearDown(self) -> None:
Shell.sync_workspace = self.sync_workspace

@unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.")
def test_mlcube_default_entrypoints(self):
def default_entry_points(self, executable: str) -> None:
with patch("io.open", mock_open(read_data=_MLCUBE_DEFAULT_ENTRY_POINT)):
mlcube: DictConfig = MLCubeConfig.create_mlcube_config(
"/some/path/to/mlcube.yaml",
runner_config=Config.DEFAULT,
runner_cls=DockerRun,
mlcube_cli_args=OmegaConf.create({"docker": {"docker": executable}}),
)
self.assertEqual(mlcube.runner.image, "ubuntu:18.04")
self.assertDictEqual(
Expand All @@ -76,13 +78,13 @@ def test_mlcube_default_entrypoints(self):
DockerRun(mlcube, task="ls").run()
DockerRun(mlcube, task="pwd").run()

@unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.")
def test_mlcube_custom_entrypoints(self):
def custom_entry_points(self, executable: str) -> None:
with patch("io.open", mock_open(read_data=_MLCUBE_CUSTOM_ENTRY_POINTS)):
mlcube: DictConfig = MLCubeConfig.create_mlcube_config(
"/some/path/to/mlcube.yaml",
runner_config=Config.DEFAULT,
runner_cls=DockerRun,
mlcube_cli_args=OmegaConf.create({"docker": {"docker": executable}}),
)
self.assertEqual(mlcube.runner.image, "ubuntu:18.04")
self.assertDictEqual(
Expand All @@ -100,3 +102,19 @@ def test_mlcube_custom_entrypoints(self):
self._check_inspect_output(DockerRun(mlcube, task=None).inspect())
DockerRun(mlcube, task="ls").run()
DockerRun(mlcube, task="free").run()

@unittest.skipUnless(_HAVE_PODMAN, reason="No podman available.")
def test_default_entrypoints_with_podman(self):
self.default_entry_points("podman")

@unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.")
def test_default_entrypoints_with_docker(self):
self.default_entry_points("docker")

@unittest.skipUnless(_HAVE_PODMAN, reason="No podman available.")
def test_custom_entrypoints_with_podman(self):
self.custom_entry_points("podman")

@unittest.skipUnless(_HAVE_DOCKER, reason="No docker available.")
def test_custom_entrypoints_with_docker(self):
self.custom_entry_points("docker")

0 comments on commit e31985b

Please sign in to comment.