Skip to content

Commit

Permalink
[cli] Enable job test command to read materialized config file
Browse files Browse the repository at this point in the history
  • Loading branch information
fallonchen committed Mar 17, 2021
1 parent a697308 commit 1bd8582
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
17 changes: 14 additions & 3 deletions cli/src/klio_cli/commands/job/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ class TestPipeline(base.BaseDockerizedPipeline):

def __init__(self, job_dir, klio_config, docker_runtime_config):
super().__init__(job_dir, klio_config, docker_runtime_config)
self.requires_config_file = False
self.requires_config_file = True

def _get_environment(self):
envs = super()._get_environment()
envs["KLIO_TEST_MODE"] = "true"
return envs

def _get_command(self, pytest_args):
return ["test"] + pytest_args
def _get_command(self, *args, **kwargs):
return ["test"]

def _add_pytest_args(self, cmd, pytest_args):
if pytest_args:
cmd.extend(pytest_args)

def _get_docker_runflags(self, *args, **kwargs):
base_runflags = super()._get_docker_runflags(*args, **kwargs)
# add pytest args *after* the base command flags are added
pytest_args = kwargs.get("pytest_args", [])
self._add_pytest_args(base_runflags["command"], pytest_args)
return base_runflags
28 changes: 26 additions & 2 deletions cli/tests/commands/job/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,32 @@ def test_get_environment(test_pipeline):


def test_get_command(test_pipeline):
assert ["test", "py", "args"] == test_pipeline._get_command(["py", "args"])
assert ["test"] == test_pipeline._get_command()


def test_add_pytest_args(test_pipeline):
docker_runflags = {"command": ["cmd"]}
test_pipeline._add_pytest_args(docker_runflags["command"], ["py", "args"])
assert ["cmd", "py", "args"] == docker_runflags["command"]


def test_get_docker_runflags(mocker, monkeypatch, test_pipeline):
mock_base_docker_runflags = mocker.Mock()
mock_base_docker_runflags.return_value = {
"command": ["test", "--config-file", "x"]
}
monkeypatch.setattr(
test_job.base.BaseDockerizedPipeline,
"_get_docker_runflags",
mock_base_docker_runflags,
)
actual_runflags = test_pipeline._get_docker_runflags(
pytest_args=["py", "args"]
)

expected = ["test", "--config-file", "x", "py", "args"]
assert expected == actual_runflags["command"]


def test_requires_config_setting(test_pipeline):
assert not test_pipeline.requires_config_file
assert test_pipeline.requires_config_file

0 comments on commit 1bd8582

Please sign in to comment.