Skip to content

Commit f571311

Browse files
committed
Add test coverage for CLI --eoap option
1 parent 9cad189 commit f571311

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/test_cli.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import urllib
44
from unittest.mock import patch, ANY, MagicMock
55
import pytest
6+
import yaml
67
from click.testing import CliRunner
78

89
from xcengine.cli import cli
@@ -64,19 +65,26 @@ def test_make_script(
6465

6566
@pytest.mark.parametrize("specify_dir", [False, True])
6667
@pytest.mark.parametrize("specify_env", [False, True])
68+
@pytest.mark.parametrize("specify_eoap", [False, True])
6769
@patch("xcengine.cli.ImageBuilder")
68-
def test_image_build(builder_mock, tmp_path, specify_dir, specify_env):
70+
def test_image_build(
71+
builder_mock, tmp_path, specify_dir, specify_env, specify_eoap
72+
):
6973
(nb_path := tmp_path / "foo.ipynb").touch()
7074
(env_path := tmp_path / "environment.yml").touch()
7175
(build_dir := tmp_path / "build").mkdir()
76+
eoap_path = tmp_path / "eoap.yaml"
7277
runner = CliRunner()
7378
tag = "foo"
7479
instance_mock = builder_mock.return_value = MagicMock()
80+
cwl = {"foo": 42}
81+
instance_mock.create_cwl.return_value = cwl
7582
result = runner.invoke(
7683
cli,
7784
["image", "build", "--tag", tag]
7885
+ (["--build-dir", str(build_dir)] if specify_dir else [])
7986
+ (["--environment", str(env_path)] if specify_env else [])
87+
+ (["--eoap", str(eoap_path)] if specify_eoap else [])
8088
+ [str(nb_path)],
8189
)
8290
assert result.output.startswith("Built image")
@@ -88,6 +96,8 @@ def test_image_build(builder_mock, tmp_path, specify_dir, specify_env):
8896
build_dir=(build_dir if specify_dir else ANY),
8997
)
9098
instance_mock.build.assert_called_once_with(skip_build=False)
99+
if specify_eoap:
100+
assert yaml.safe_load(eoap_path.read_text()) == cwl
91101

92102

93103
@patch("xcengine.cli.ContainerRunner")
@@ -182,6 +192,7 @@ def urlopen(url):
182192
assert passed_url == f"http://localhost:{port}"
183193
open_mock.assert_called_once_with(f"http://localhost:{port}/viewer")
184194

195+
185196
@patch("docker.from_env")
186197
def test_image_skip_build_save_dockerfile_and_env(from_env_mock, tmp_path):
187198
build_dir = tmp_path / "build"
@@ -202,4 +213,3 @@ def test_image_skip_build_save_dockerfile_and_env(from_env_mock, tmp_path):
202213
assert (build_dir / "Dockerfile").is_file()
203214
assert (build_dir / "environment.yml").is_file()
204215
from_env_mock.assert_not_called()
205-

0 commit comments

Comments
 (0)