|
1 | | -from unittest.mock import patch, ANY |
| 1 | +from unittest.mock import patch, ANY, MagicMock |
2 | 2 | import pytest |
3 | 3 | from click.testing import CliRunner |
4 | 4 |
|
@@ -59,14 +59,33 @@ def test_make_script( |
59 | 59 | assert result.exit_code == 0 |
60 | 60 |
|
61 | 61 |
|
62 | | -@patch("xcengine.core.ImageBuilder.__init__") |
63 | | -@patch("xcengine.core.ImageBuilder.build") |
64 | | -def test_image_build(build_mock, init_mock, tmp_path): |
| 62 | +@patch("xcengine.cli.ImageBuilder") |
| 63 | +def test_image_build(builder_mock, tmp_path): |
65 | 64 | nb_path = tmp_path / "foo.ipynb" |
66 | 65 | nb_path.touch() |
67 | 66 | runner = CliRunner() |
68 | 67 | tag = "foo" |
| 68 | + instance_mock = builder_mock.return_value = MagicMock() |
69 | 69 | result = runner.invoke(cli, ["image", "build", "--tag", tag, str(nb_path)]) |
70 | | - init_mock.assert_called_once_with( |
| 70 | + assert result.exit_code == 0 |
| 71 | + builder_mock.assert_called_once_with( |
71 | 72 | notebook=nb_path, environment=None, tag=tag, build_dir=ANY |
72 | 73 | ) |
| 74 | + instance_mock.build.assert_called_once_with() |
| 75 | + |
| 76 | +@patch("xcengine.cli.ContainerRunner") |
| 77 | +def test_image_run(runner_mock): |
| 78 | + cli_runner = CliRunner() |
| 79 | + instance_mock = runner_mock.return_value = MagicMock() |
| 80 | + result = cli_runner.invoke( |
| 81 | + cli, |
| 82 | + ["image", "run", "foo"] |
| 83 | + ) |
| 84 | + runner_mock.assert_called_once_with(image="foo", output_dir=None) |
| 85 | + assert result.exit_code == 0 |
| 86 | + instance_mock.run.assert_called_once_with( |
| 87 | + run_batch=False, |
| 88 | + host_port=None, |
| 89 | + from_saved=False, |
| 90 | + keep=False, |
| 91 | + ) |
0 commit comments