Skip to content

Commit

Permalink
Add test for the out.osw
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Nov 15, 2023
1 parent 6989e08 commit ad85c1a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
9 changes: 9 additions & 0 deletions resources/workflow/output_test/in.osw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"measure_paths": ["../measures/"],
"steps": [
{
"measure_dir_name": "FakeReport",
"arguments": {}
}
]
}
5 changes: 5 additions & 0 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ if(BUILD_TESTING)
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/resources/workflow/outdated_measures/"
)

add_test(NAME OpenStudioCLI.test_output_files
COMMAND ${Python_EXECUTABLE} -m pytest --verbose --os-cli-path $<TARGET_FILE:openstudio> "${CMAKE_CURRENT_SOURCE_DIR}/test/test_output_files.py"
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/resources/workflow/output_test/"
)

else()
# TODO: Remove. Fallback on these for now, as I don't know if CI has pytest installed
add_test(NAME OpenStudioCLI.Classic.test_logger_rb
Expand Down
107 changes: 107 additions & 0 deletions src/cli/test/test_output_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import json
from pathlib import Path

import pytest

from workflow_helpers import run_workflow


@pytest.fixture(scope="module", params=[True, False], ids=["labs", "classic"])
def runWorkflow(osclipath, request):
is_labs = request.param
suffix = "labs" if is_labs else "classic"
runDir, r = run_workflow(
osclipath=osclipath,
base_osw_name="in.osw",
suffix=suffix,
is_labs=is_labs,
verbose=False,
debug=False,
post_process_only=True,
)
r.check_returncode()
return runDir, is_labs


@pytest.mark.parametrize(
"is_labs",
[pytest.param(True, id="labs"), pytest.param(False, id="classic")],
)
def test_(osclipath, is_labs: bool):
suffix = "labs" if is_labs else "classic"
runDir, r = run_workflow(
osclipath=osclipath,
base_osw_name="in.osw",
suffix=suffix,
is_labs=is_labs,
verbose=False,
debug=True,
post_process_only=True,
)
r.check_returncode()
out_osw_path = Path(f"out_in_{suffix}.osw")
assert out_osw_path.is_file()
out = json.loads(out_osw_path.read_text())

assert out["completed_status"] == "Success"
assert out["current_step"] == 1

EXPECTED_TOPLEVEL_KEYS = {
"completed_at",
"completed_status",
"current_step",
"file_paths",
"hash",
"measure_paths",
"out_name",
"run_directory",
"started_at",
"steps",
"updated_at",
}
if is_labs:
EXPECTED_TOPLEVEL_KEYS.add("run_options")
assert out.keys() == EXPECTED_TOPLEVEL_KEYS

assert len(out["steps"]) == 1
step = out["steps"][0]
step.keys() == {"arguments", "measure_dir_name", "result"}
assert step["arguments"] == {}
assert step["measure_dir_name"] == "FakeReport"

step_result = step["result"]
assert step_result.keys() == {
"completed_at",
"measure_class_name",
"measure_display_name",
"measure_name",
"measure_taxonomy",
"measure_type",
"measure_uid",
"measure_version_id",
"measure_version_modified",
"measure_xml_checksum",
"started_at",
"stderr",
"stdout",
"step_errors",
"step_files",
"step_final_condition",
"step_info",
"step_result",
"step_values",
"step_warnings",
}

assert step_result["step_result"] == "Success"

assert len(step_result["step_info"]) == 1
assert len(step_result["step_warnings"]) == 1
assert not step_result["step_errors"]

len(step_result["step_values"]) == 3
assert {x["name"] for x in step_result["step_values"]} == {
"fake_report",
"net_site_energy",
"something_with_invalid_chars",
}
1 change: 1 addition & 0 deletions src/cli/test/workflow_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def run_workflow(
osw_path = base_osw_path.parent / f"{base_osw_path.stem}_{suffix}.osw"
runDir = base_osw_path.parent / f"run_{osw_path.stem}"
osw["run_directory"] = str(runDir)
osw["out_name"] = f"out_{osw_path.stem}.osw"
if runDir.is_dir():
shutil.rmtree(runDir)
runDir.mkdir(exist_ok=False)
Expand Down

0 comments on commit ad85c1a

Please sign in to comment.