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

Add test to check if logger works from embedded Python code #4441

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ if(ENABLE_ECL_OUTPUT)
tests/SPE1CASE2_RESTART_SKIPREST.DATA
tests/SPE1CASE2.X0060
tests/PYACTION.DATA
tests/logger.py
tests/0A4_GRCTRL_LRAT_LRAT_GGR_BASE_MODEL2_MSW_ALL.DATA
tests/MOD4_TEST_IGRP-DATA.DATA
tests/2_WLIFT_MODEL5_NOINC.DATA
Expand Down
10 changes: 10 additions & 0 deletions tests/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The python code in this file does the same as ACT-01 to ACT-05 of opm-tests/actionx/ACTIONX_WCONPROD.DATA
import opm_embedded

opm_embedded.OpmLog.info("Info from logger.py!")
opm_embedded.OpmLog.warning("Warning from logger.py!")
opm_embedded.OpmLog.error("Error from logger.py!")
opm_embedded.OpmLog.problem("Problem from logger.py!")
opm_embedded.OpmLog.bug("Bug from logger.py!")
opm_embedded.OpmLog.debug("Debug from logger.py!")
opm_embedded.OpmLog.note("Note from logger.py!")
34 changes: 34 additions & 0 deletions tests/parser/PYACTION.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <opm/input/eclipse/Schedule/Schedule.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>

#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/StreamLog.hpp>

using namespace Opm;

BOOST_AUTO_TEST_CASE(ParsePYACTION) {
Expand Down Expand Up @@ -86,5 +89,36 @@ BOOST_AUTO_TEST_CASE(ParsePYACTION_ModuleMissing) {
BOOST_CHECK_THROW(Action::PyAction(python , "ACT2", run_count, missing_module), std::invalid_argument);
}

BOOST_AUTO_TEST_CASE(PYACTION_Log) {
std::ostringstream log_stream; // Custom stream for capturing log messages
std::shared_ptr<Opm::StreamLog> stream_log = std::make_shared<Opm::StreamLog>(log_stream, Opm::Log::DefaultMessageTypes);

OpmLog::addBackend( "STREAM" , stream_log);

Parser parser;
auto deck = parser.parseFile("PYACTION.DATA");
const std::string& logger_module = deck.makeDeckPath("logger.py");

auto python = std::make_shared<Python>();
Action::PyAction pyaction(python , "ACT3", Action::PyAction::RunCount::unlimited, logger_module);

const std::function<void(const std::string&, const std::vector<std::string>&)> actionx_callback;
EclipseState state;
Schedule schedule;
SummaryState summary_state;

pyaction.run(state, schedule, 0, summary_state, actionx_callback);
std::string log_output = log_stream.str();

BOOST_CHECK(log_output.find("Info from logger.py!") != std::string::npos);
BOOST_CHECK(log_output.find("Warning from logger.py!") != std::string::npos);
BOOST_CHECK(log_output.find("Error from logger.py!") != std::string::npos);
BOOST_CHECK(log_output.find("Problem from logger.py!") != std::string::npos);
BOOST_CHECK(log_output.find("Bug from logger.py!") != std::string::npos);
BOOST_CHECK(log_output.find("Debug from logger.py!") != std::string::npos);
BOOST_CHECK(log_output.find("Note from logger.py!") != std::string::npos);

}

#endif