Skip to content

Commit

Permalink
Work around valohai-yaml compat bug
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Nov 3, 2021
1 parent 39ed969 commit 2d4a184
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
12 changes: 5 additions & 7 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import pytest
from valohai_yaml import parse

from tests.utils import read_yaml_test_data
from tests.utils import compare_yaml, read_yaml_test_data
from valohai.internals.pipeline import get_pipeline_from_source
from valohai.yaml import config_to_yaml


@pytest.mark.parametrize(
"original_yaml, source_python, expected_yaml",
"original_yaml, source_python, expected_yaml_filename",
read_yaml_test_data("tests/test_pipeline_yaml"),
)
def test_yaml_update_from_source(tmpdir, original_yaml, source_python, expected_yaml):
def test_pipeline_yaml_update_from_source(tmpdir, original_yaml, source_python, expected_yaml_filename):
yaml_path = os.path.join(tmpdir, "valohai.yaml")
source_path = os.path.join(tmpdir, "test.py")

Expand All @@ -33,6 +32,5 @@ def test_yaml_update_from_source(tmpdir, original_yaml, source_python, expected_
new_config = old_config.merge_with(new_config)

# Check against expected result
with open(expected_yaml) as expected_yaml:
new_yaml = config_to_yaml(new_config)
assert new_yaml == expected_yaml.read()
with open(expected_yaml_filename) as fp:
compare_yaml(new_config, fp.read())
12 changes: 5 additions & 7 deletions tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import pytest
from valohai_yaml import parse

from tests.utils import read_yaml_test_data
from tests.utils import compare_yaml, read_yaml_test_data
from valohai.internals.merge import python_to_yaml_merge_strategy
from valohai.internals.yaml import generate_step, parse_config_from_source
from valohai.yaml import config_to_yaml


@pytest.mark.parametrize(
"original_yaml, source_python, expected_yaml",
"original_yaml, source_python, expected_yaml_filename",
read_yaml_test_data("tests/test_yaml"),
)
def test_yaml_update_from_source(tmpdir, original_yaml, source_python, expected_yaml):
def test_yaml_update_from_source(tmpdir, original_yaml, source_python, expected_yaml_filename):
yaml_path = os.path.join(tmpdir, "valohai.yaml")
filename, file_extension = os.path.splitext(source_python)
source_path = os.path.join(tmpdir, f"test{file_extension}")
Expand All @@ -38,9 +37,8 @@ def test_yaml_update_from_source(tmpdir, original_yaml, source_python, expected_
new_config = old_config.merge_with(new_config, python_to_yaml_merge_strategy)

# Check against expected result
with open(expected_yaml) as expected_yaml:
new_yaml = config_to_yaml(new_config)
assert new_yaml == expected_yaml.read()
with open(expected_yaml_filename) as fp:
compare_yaml(new_config, fp.read())


def test_posix_path_separator(monkeypatch):
Expand Down
12 changes: 12 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import glob
import json
import os
import re

from valohai_yaml.objs import Config

from valohai.yaml import config_to_yaml


def read_source_files(path_without_ext):
Expand Down Expand Up @@ -56,3 +61,10 @@ def read_yaml_test_data(root_path):
)
)
return test_data


def compare_yaml(config: Config, fixture_yaml: str) -> None:
new_yaml = config_to_yaml(config)
# TODO: remove this when https://github.com/valohai/valohai-yaml/pull/59 lands
new_yaml = re.sub(r"\s+actions: \[]", "", new_yaml)
assert new_yaml == fixture_yaml

0 comments on commit 2d4a184

Please sign in to comment.