Skip to content

Commit

Permalink
Use cached_example for test_everest_entry
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Jan 6, 2025
1 parent 839610b commit c37e346
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions tests/everest/functional/test_main_everest_entry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from textwrap import dedent

import pytest
Expand All @@ -15,7 +16,6 @@
from everest.detached import ServerStatus, everserver_status

CONFIG_FILE_MINIMAL = "config_minimal.yml"
WELL_ORDER = "everest/model/config.yml"

pytestmark = pytest.mark.xdist_group(name="starts_everest")

Expand Down Expand Up @@ -81,12 +81,13 @@ def test_everest_main_entry_bad_command():
@pytest.mark.flaky(reruns=5)
@pytest.mark.fails_on_macos_github_workflow
@pytest.mark.integration_test
def test_everest_entry_run(copy_math_func_test_data_to_tmp):
def test_everest_entry_run(cached_example):
_, config_file, _ = cached_example("math_func/config_minimal.yml")
# Setup command line arguments
with capture_streams():
start_everest(["everest", "run", CONFIG_FILE_MINIMAL])
start_everest(["everest", "run", config_file])

config = EverestConfig.load_file(CONFIG_FILE_MINIMAL)
config = EverestConfig.load_file(config_file)
status = everserver_status(
ServerConfig.get_everserver_status_path(config.output_dir)
)
Expand All @@ -103,9 +104,9 @@ def test_everest_entry_run(copy_math_func_test_data_to_tmp):
assert best_settings.objective_value == pytest.approx(0.0, abs=0.0005)

with capture_streams():
start_everest(["everest", "monitor", CONFIG_FILE_MINIMAL])
start_everest(["everest", "monitor", config_file])

config = EverestConfig.load_file(CONFIG_FILE_MINIMAL)
config = EverestConfig.load_file(config_file)
status = everserver_status(
ServerConfig.get_everserver_status_path(config.output_dir)
)
Expand All @@ -114,11 +115,12 @@ def test_everest_entry_run(copy_math_func_test_data_to_tmp):


@pytest.mark.integration_test
def test_everest_entry_monitor_no_run(copy_math_func_test_data_to_tmp):
def test_everest_entry_monitor_no_run(cached_example):
_, config_file, _ = cached_example("math_func/config_minimal.yml")
with capture_streams():
start_everest(["everest", "monitor", CONFIG_FILE_MINIMAL])
start_everest(["everest", "monitor", config_file])

config = EverestConfig.load_file(CONFIG_FILE_MINIMAL)
config = EverestConfig.load_file(config_file)
status = everserver_status(
ServerConfig.get_everserver_status_path(config.output_dir)
)
Expand All @@ -127,32 +129,34 @@ def test_everest_entry_monitor_no_run(copy_math_func_test_data_to_tmp):


@pytest.mark.integration_test
def test_everest_main_export_entry(copy_math_func_test_data_to_tmp):
def test_everest_main_export_entry(cached_example):
# Setup command line arguments
_, config_file, _ = cached_example("math_func/config_minimal.yml")
with capture_streams():
start_everest(["everest", "export", CONFIG_FILE_MINIMAL])
start_everest(["everest", "export", config_file])
assert os.path.exists(os.path.join("everest_output", "config_minimal.csv"))


@pytest.mark.integration_test
def test_everest_main_lint_entry(copy_math_func_test_data_to_tmp):
def test_everest_main_lint_entry(cached_example):
# Setup command line arguments
_, config_file, _ = cached_example("math_func/config_minimal.yml")
with capture_streams() as (out, err):
start_everest(["everest", "lint", CONFIG_FILE_MINIMAL])
start_everest(["everest", "lint", config_file])
assert "config_minimal.yml is valid" in out.getvalue()

# Make the config invalid
with open(CONFIG_FILE_MINIMAL, encoding="utf-8") as f:
with open(config_file, encoding="utf-8") as f:
raw_config = YAML(typ="safe", pure=True).load(f)
raw_config["controls"][0]["initial_guess"] = "invalid"
with open(CONFIG_FILE_MINIMAL, "w", encoding="utf-8") as f:
with open(config_file, "w", encoding="utf-8") as f:
yaml = YAML(typ="safe", pure=True)
yaml.indent = 2
yaml.default_flow_style = False
yaml.dump(raw_config, f)

with capture_streams() as (out, err), pytest.raises(SystemExit):
start_everest(["everest", "lint", CONFIG_FILE_MINIMAL])
start_everest(["everest", "lint", config_file])

type_ = "(type=float_parsing)"
validation_msg = dedent(
Expand All @@ -170,10 +174,17 @@ def test_everest_main_lint_entry(copy_math_func_test_data_to_tmp):
@skipif_no_everest_models
@pytest.mark.everest_models_test
@pytest.mark.integration_test
def test_everest_main_configdump_entry(copy_egg_test_data_to_tmp):
def test_everest_main_configdump_entry(cached_example):
# Setup command line arguments
config_path, config_file, _ = cached_example("egg/everest/model/config.yml")

config_abspath = Path(config_path) / config_file
project_path = Path(config_path) / ".." / ".."
os.chdir(project_path)

with capture_streams() as (out, _):
start_everest(["everest", "render", WELL_ORDER])
start_everest(["everest", "render", str(config_abspath)])

yaml = YAML(typ="safe", pure=True)
render_dict = yaml.load(out.getvalue())

Expand Down

0 comments on commit c37e346

Please sign in to comment.