Merge pull request #999 from stefoss23/PYINPUT
Can extract parserkw's in python.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
@@ -42,6 +46,9 @@ namespace {
|
||||
const Json::JsonObject keyword(json_string);
|
||||
parser->addParserKeyword(keyword);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void opmcommon_python::export_Parser(py::module& module) {
|
||||
@@ -52,6 +59,10 @@ void opmcommon_python::export_Parser(py::module& module) {
|
||||
module.def( "create_deck_string", &create_deck_string);
|
||||
|
||||
|
||||
py::class_<ParserKeyword>(module, "ParserKeyword")
|
||||
.def_property_readonly("name", &ParserKeyword::getName);
|
||||
|
||||
|
||||
py::class_<SunbeamState>(module, "SunbeamState")
|
||||
.def("_schedule", &SunbeamState::getSchedule, ref_internal)
|
||||
.def("_state", &SunbeamState::getEclipseState, ref_internal)
|
||||
@@ -65,5 +76,8 @@ void opmcommon_python::export_Parser(py::module& module) {
|
||||
.def("parse" , py::overload_cast<const std::string&, const ParseContext&>(&Parser::parseFile, py::const_))
|
||||
.def("parse_string", py::overload_cast<const std::string&>(&Parser::parseString, py::const_))
|
||||
.def("parse_string", py::overload_cast<const std::string&, const ParseContext&>(&Parser::parseString, py::const_))
|
||||
.def("add_keyword", add_keyword);
|
||||
.def("add_keyword", add_keyword)
|
||||
.def("__getitem__", &Parser::getKeyword, ref_internal);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
# from opm.io.parser import Parser
|
||||
from __future__ import absolute_import
|
||||
from .libopmcommon_python import action
|
||||
from .libopmcommon_python import Parser, ParseContext
|
||||
|
||||
from .libopmcommon_python import Parser, ParseContext, ParserKeyword
|
||||
from .libopmcommon_python import EclipseConfig
|
||||
|
||||
#from .schedule import Well, Connection, Schedule
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from opm._common import action
|
||||
from opm._common import Parser
|
||||
from opm._common import ParseContext
|
||||
from opm._common import ParserKeyword
|
||||
|
||||
from .parser_module import parse, load_deck, load_deck_string, parse_string
|
||||
|
||||
@@ -4,6 +4,8 @@ import sys
|
||||
|
||||
from opm.io.parser import Parser
|
||||
from opm.io.parser import ParseContext
|
||||
from opm.io.parser import ParserKeyword
|
||||
|
||||
|
||||
class TestParser(unittest.TestCase):
|
||||
|
||||
@@ -28,6 +30,17 @@ OPERNUM
|
||||
3 3 1 2 /
|
||||
FIPNUM
|
||||
1 1 2 3 /
|
||||
"""
|
||||
|
||||
MANUALDATA = """
|
||||
START -- 0
|
||||
10 MAI 2007 /
|
||||
RUNSPEC
|
||||
|
||||
DIMENS
|
||||
2 2 1 /
|
||||
|
||||
FIELD
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
@@ -46,6 +59,15 @@ FIPNUM
|
||||
deck = parser.parse_string(string)
|
||||
deck = parser.parse_string(string, context)
|
||||
|
||||
def test_pyinput(self):
|
||||
parser = Parser()
|
||||
deck = parser.parse_string(self.MANUALDATA)
|
||||
with self.assertRaises(ValueError):
|
||||
kw = parser["NOT_A_VALID_KEYWORD"]
|
||||
|
||||
kw = parser["FIELD"]
|
||||
assert(kw.name == "FIELD")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user