Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10718 - DXCoils StandardRatings OutputReportPredefined::addFootNoteSubTable produces invalid XML #10860

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
2 changes: 2 additions & 0 deletions .github/workflows/test_pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
brew reinstall gcc@13
echo "FC=$(brew --prefix gcc@13)/bin/gfortran-13" >> $GITHUB_ENV
echo MACOSX_DEPLOYMENT_TARGET=${{ matrix.macos_dev_target }} >> $GITHUB_ENV
pip install pytest lxml

- name: Install Dependencies for Linux
if: runner.os == 'Linux'
Expand All @@ -72,6 +73,7 @@ jobs:
# https://github.com/actions/runner-images/issues/10025
echo "FC=gfortran-13" >> $GITHUB_ENV
fi
pip install pytest lxml

# BUILD AND TEST INTEGRATION FILES ON THE BASELINE BRANCH

Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,21 @@ if(BUILD_TESTING)
endif()
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) # This avoids all the CTest Nightly, Continuous, etc. tests.
enable_testing()

execute_process(COMMAND ${Python_EXECUTABLE} -m pytest --version
RESULT_VARIABLE _Pytest_STATUS
OUTPUT_VARIABLE Pytest_Version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(_Pytest_STATUS AND NOT _Pytest_STATUS EQUAL 0)
message(AUTHOR_WARNING "Pytest isn't installed on your system python, so some tests won't be run. Run `${Python_EXECUTABLE} -m pip install pytest`")
set(Pytest_AVAILABLE OFF)
else()
message(VERBOSE "Found Pytest: ${Pytest_Version}")
set(Pytest_AVAILABLE ON)
endif()

endif()

if(ENABLE_REGRESSION_TESTING)
Expand Down
13 changes: 0 additions & 13 deletions idd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ set(PREVIOUS_IDD ${PREVIOUS_IDD} PARENT_SCOPE)
install(FILES "${PREVIOUS_IDD}" DESTINATION "PreProcess/IDFVersionUpdater")

if (BUILD_TESTING)
execute_process(COMMAND ${Python_EXECUTABLE} -m pytest --version
RESULT_VARIABLE _Pytest_STATUS
OUTPUT_VARIABLE Pytest_Version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(_Pytest_STATUS AND NOT _Pytest_STATUS EQUAL 0)
message(AUTHOR_WARNING "Pytest isn't installed on your system python, so some tests won't be run. Run `${Python_EXECUTABLE} -m pip install pytest`")
set(Pytest_AVAILABLE OFF)
else()
message(VERBOSE "Found Pytest: ${Pytest_Version}")
set(Pytest_AVAILABLE ON)
endif()

if (Pytest_AVAILABLE)
add_test(NAME idd_schema.test_idd_parser
Expand Down
87 changes: 87 additions & 0 deletions scripts/pytests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# EnergyPlus, Copyright (c) 1996-2024, The Board of Trustees of the University
# of Illinois, The Regents of the University of California, through Lawrence
# Berkeley National Laboratory (subject to receipt of any required approvals
# from the U.S. Dept. of Energy), Oak Ridge National Laboratory, managed by UT-
# Battelle, Alliance for Sustainable Energy, LLC, and other contributors. All
# rights reserved.
#
# NOTICE: This Software was developed under funding from the U.S. Department of
# Energy and the U.S. Government consequently retains certain rights. As such,
# the U.S. Government has been granted for itself and others acting on its
# behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
# Software to reproduce, distribute copies to the public, prepare derivative
# works, and perform publicly and display publicly, and to permit others to do
# so.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the University of California, Lawrence Berkeley
# National Laboratory, the University of Illinois, U.S. Dept. of Energy nor
# the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in
# stand-alone form without changes from the version obtained under this
# License, or (ii) Licensee makes a reference solely to the software
# portion of its product, Licensee must refer to the software as
# "EnergyPlus version X" software, where "X" is the version number Licensee
# obtained under this License and may not use a different name for the
# software. Except as specifically required in this Section (4), Licensee
# shall not use in a company name, a product name, in advertising,
# publicity, or other promotional activities any name, trade name,
# trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or
# confusingly similar designation, without the U.S. Department of Energy's
# prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

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"
2 changes: 2 additions & 0 deletions scripts/pytests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
lxml
87 changes: 87 additions & 0 deletions scripts/pytests/test_xml_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# EnergyPlus, Copyright (c) 1996-2024, The Board of Trustees of the University
# of Illinois, The Regents of the University of California, through Lawrence
# Berkeley National Laboratory (subject to receipt of any required approvals
# from the U.S. Dept. of Energy), Oak Ridge National Laboratory, managed by UT-
# Battelle, Alliance for Sustainable Energy, LLC, and other contributors. All
# rights reserved.
#
# NOTICE: This Software was developed under funding from the U.S. Department of
# Energy and the U.S. Government consequently retains certain rights. As such,
# the U.S. Government has been granted for itself and others acting on its
# behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
# Software to reproduce, distribute copies to the public, prepare derivative
# works, and perform publicly and display publicly, and to permit others to do
# so.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the University of California, Lawrence Berkeley
# National Laboratory, the University of Illinois, U.S. Dept. of Energy nor
# the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in
# stand-alone form without changes from the version obtained under this
# License, or (ii) Licensee makes a reference solely to the software
# portion of its product, Licensee must refer to the software as
# "EnergyPlus version X" software, where "X" is the version number Licensee
# obtained under this License and may not use a different name for the
# software. Except as specifically required in this Section (4), Licensee
# shall not use in a company name, a product name, in advertising,
# publicity, or other promotional activities any name, trade name,
# trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or
# confusingly similar designation, without the U.S. Department of Energy's
# prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

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"))
7 changes: 7 additions & 0 deletions src/EnergyPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,13 @@ if(BUILD_TESTING)
TIMEOUT 10 # This used to timeout! and we expect it NOT to
)
endif()

if(Pytest_AVAILABLE)
add_test(NAME energyplus.TabularXML_IsValid
COMMAND ${Python_EXECUTABLE} -m pytest --verbose --ep-cli-path $<TARGET_FILE:energyplus> "${PROJECT_SOURCE_DIR}/scripts/pytests/test_xml_output.py"
)
endif()

endif()

if(UNIX AND NOT APPLE)
Expand Down
30 changes: 3 additions & 27 deletions src/EnergyPlus/Coils/CoilCoolingDX.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include <EnergyPlus/ReportCoilSelection.hh>
#include <EnergyPlus/ScheduleManager.hh>
#include <EnergyPlus/SimAirServingZones.hh>
#include <EnergyPlus/StandardRatings.hh>
#include <EnergyPlus/WaterManager.hh>

using namespace EnergyPlus;
Expand Down Expand Up @@ -1047,19 +1048,7 @@ void CoilCoolingDX::reportAllStandardRatings(EnergyPlusData &state)
} else {
OutputReportPredefined::PreDefTableEntry(state, state.dataOutRptPredefined->pdchDXCoolCoilIEERIP, coil.name, "N/A");
}
OutputReportPredefined::addFootNoteSubTable(
state,
state.dataOutRptPredefined->pdstDXCoolCoil,
"ANSI/AHRI ratings account for supply air fan heat and electric power. <br/>"
"1 - EnergyPlus object type. <br/>"
"2 - Capacity less than 65K Btu/h (19050 W) - calculated as per AHRI Standard 210/240-2017. <br/>"
"&emsp;&nbsp;Capacity of 65K Btu/h (19050 W) to less than 135K Btu/h (39565 W) - calculated as per AHRI Standard 340/360-2007. "
"<br/>"
"&emsp;&nbsp;Capacity from 135K (39565 W) to 250K Btu/hr (73268 W) - calculated as per AHRI Standard 365-2009 - Ratings not yet "
"supported in EnergyPlus. <br/>"
"3 - SEER (User) is calculated using user-input PLF curve and cooling coefficient of degradation. <br/>"
"&emsp;&nbsp;SEER (Standard) is calculated using the default PLF curve and cooling coefficient of degradation"
"from the appropriate AHRI standard.");
OutputReportPredefined::addFootNoteSubTable(state, state.dataOutRptPredefined->pdstDXCoolCoil, StandardRatings::AHRI2017FOOTNOTE);

// AHRI 2023 Standard SEER2 Calculations
if (state.dataHVACGlobal->StandardRatingsMyCoolOneTimeFlag2) {
Expand Down Expand Up @@ -1125,20 +1114,7 @@ void CoilCoolingDX::reportAllStandardRatings(EnergyPlusData &state)
} else {
OutputReportPredefined::PreDefTableEntry(state, state.dataOutRptPredefined->pdchDXCoolCoilIEERIP_2023, coil.name, "N/A");
}
OutputReportPredefined::addFootNoteSubTable(
state,
state.dataOutRptPredefined->pdstDXCoolCoil_2023,
"ANSI/AHRI ratings account for supply air fan heat and electric power. <br/>"
"1 - EnergyPlus object type. <br/>"
"2 - Capacity less than 65K Btu/h (19050 W) - calculated as per AHRI Standard 210/240-2023. <br/>"
"&emsp;&nbsp;Capacity of 65K Btu/h (19050 W) to less than 135K Btu/h (39565 W) - calculated as per AHRI Standard 340/360-2022. "
"<br/>"
"&emsp;&nbsp;Capacity from 135K (39565 W) to 250K Btu/hr (73268 W) - calculated as per AHRI Standard 365-2009 - Ratings not yet "
"supported in EnergyPlus. <br/>"
"3 - SEER2 (User) is calculated using user-input PLF curve and cooling coefficient of degradation. <br/>"
"&emsp;&nbsp;SEER2 (Standard) is calculated using the default PLF curve and cooling coefficient of degradation"
"from the appropriate AHRI standard. <br/>"
"4 - Value for the Full Speed of the coil.");
OutputReportPredefined::addFootNoteSubTable(state, state.dataOutRptPredefined->pdstDXCoolCoil_2023, StandardRatings::AHRI2023FOOTNOTE);
}
}
state.dataCoilCooingDX->stillNeedToReportStandardRatings = false;
Expand Down
13 changes: 1 addition & 12 deletions src/EnergyPlus/DXCoils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14824,18 +14824,7 @@ void CalcTwoSpeedDXCoilStandardRating(EnergyPlusData &state, int const DXCoilNum
PreDefTableEntry(state, state.dataOutRptPredefined->pdchDXCoolCoilSEERUserIP, thisDXCoil.Name, "N/A");
PreDefTableEntry(state, state.dataOutRptPredefined->pdchDXCoolCoilSEERStandardIP, thisDXCoil.Name, "N/A");

addFootNoteSubTable(
state,
state.dataOutRptPredefined->pdstDXCoolCoil,
"ANSI/AHRI ratings account for supply air fan heat and electric power. <br/>"
"1 - EnergyPlus object type. <br/>"
"2 - Capacity less than 65K Btu/h (19050 W) - calculated as per AHRI Standard 210/240-2017. <br/>"
"&emsp;&nbsp;Capacity of 65K Btu/h (19050 W) to less than 135K Btu/h (39565 W) - calculated as per AHRI Standard 340/360-2007. <br/>"
"&emsp;&nbsp;Capacity from 135K (39565 W) to 250K Btu/hr (73268 W) - calculated as per AHRI Standard 365-2009 - Ratings not yet supported in "
"EnergyPlus. <br/>"
"3 - SEER (User) is calculated using user-input PLF curve and cooling coefficient of degradation. <br/>"
"&emsp;&nbsp;SEER (Standard) is calculated using the default PLF curve and cooling coefficient of degradation"
"from the appropriate AHRI standard.");
addFootNoteSubTable(state, state.dataOutRptPredefined->pdstDXCoolCoil, StandardRatings::AHRI2017FOOTNOTE);

PreDefTableEntry(state, state.dataOutRptPredefined->pdchVAVDXCoolCoilType, thisDXCoil.Name, "Coil:Cooling:DX:TwoSpeed");
if (thisDXCoil.RateWithInternalStaticAndFanObject) {
Expand Down
10 changes: 7 additions & 3 deletions src/EnergyPlus/OutputReportTabular.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3106,8 +3106,8 @@ void OpenOutputTabularFile(EnergyPlusData &state)
tbl_stream << " " << std::setw(2) << ort->td(5) << ':' << std::setw(2) << ort->td(6) << ':' << std::setw(2) << ort->td(7)
<< std::setfill(' ') << '\n';
tbl_stream << " - EnergyPlus</title>\n";
tbl_stream << "</head>\n";
tbl_stream << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
tbl_stream << "</head>\n";
tbl_stream << "<body>\n";
tbl_stream << "<p><a href=\"#toc\" style=\"float: right\">Table of Contents</a></p>\n";
tbl_stream << "<a name=top></a>\n";
Expand Down Expand Up @@ -17188,7 +17188,7 @@ void WriteTable(EnergyPlusData &state,
// end the table
tbl_stream << "</table>\n";
if (!footnoteText.empty()) {
tbl_stream << fmt::format("<i>{}</i>\n", footnoteText);
tbl_stream << fmt::format("<div class=\"footnote\" style=\"font-style: italic;\">{}</div>\n", footnoteText);
}
tbl_stream << "<br><br>\n";
} else if (thisStyle == TableStyle::XML) {
Expand Down Expand Up @@ -17316,7 +17316,11 @@ void WriteTable(EnergyPlusData &state,
}
}
if (!footnoteText.empty()) {
tbl_stream << fmt::format(" <footnote>{}</footnote>\n", footnoteText);
if (footnoteText.find("<br") != std::string_view::npos) {
tbl_stream << fmt::format(" <footnote><![CDATA[{}]]></footnote>\n", footnoteText);
} else {
tbl_stream << fmt::format(" <footnote>{}</footnote>\n", footnoteText);
}
}
}
} else {
Expand Down
Loading
Loading