-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Pytest for #10718 and register it as a CTest
- Loading branch information
Showing
5 changed files
with
86 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
def validate_file(arg): | ||
if (filepath := Path(arg).expanduser()).is_file(): | ||
return filepath | ||
else: | ||
raise FileNotFoundError(arg) | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--ep-cli-path", type=validate_file, help="Path to the E+ CLI") # , required=True | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def epclipath(request): | ||
cli_path = request.config.getoption("--ep-cli-path") | ||
if cli_path is None: | ||
raise ValueError("You must supply --ep-cli-path [Path]") | ||
return cli_path | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def testfiles_dir(): | ||
return Path(__file__).parent / "../../testfiles" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def chig_epw(): | ||
return Path(__file__).parent / "../../weather/USA_IL_Chicago-OHare_TMY2.epw" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import re | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def prepare_idf_with_xml(tmp_path: Path, testfiles_dir: Path): # tmp_path is a built-in pytest fixture | ||
RE_TABLE = re.compile(r"(?P<Prefix>OutputControl:Table:Style.*)HTML;", re.DOTALL) | ||
idf_file_path = testfiles_dir / "DXCoilSystemAuto.idf" | ||
assert idf_file_path.is_file() | ||
content = idf_file_path.read_text() | ||
content = RE_TABLE.sub(r"\g<1>XMLandHTML;", content) | ||
mod_idf_file_path = tmp_path / "in.idf" | ||
mod_idf_file_path.write_text(content) | ||
return mod_idf_file_path | ||
|
||
|
||
def test_xml_with_standard_ratings_is_valid(epclipath, prepare_idf_with_xml, chig_epw): | ||
lxml = pytest.importorskip("lxml", reason="lxml not found, please `pip install lxml`") | ||
from lxml import etree | ||
|
||
subprocess.check_call( | ||
[str(epclipath), "-w", str(chig_epw)], | ||
stdout=subprocess.DEVNULL, | ||
stderr=subprocess.STDOUT, | ||
cwd=prepare_idf_with_xml.parent, | ||
) | ||
xml_out_path = prepare_idf_with_xml.parent / "eplustbl.xml" | ||
assert xml_out_path.is_file() | ||
root = lxml.etree.fromstring(xml_out_path.read_text(encoding="latin-1")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters