From bdb579b8db06346f107e945e7b9666368d334b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Gr=C3=B8n=C3=A5s=20Drange?= Date: Thu, 12 Jan 2017 09:43:03 +0100 Subject: [PATCH] added parseData and test --- python/sunbeam/sunbeam.cpp | 2 ++ python/sunbeam/sunbeam.py | 8 ++++++-- tests/parse.py | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/python/sunbeam/sunbeam.cpp b/python/sunbeam/sunbeam.cpp index bdef56659..9c44e45b9 100644 --- a/python/sunbeam/sunbeam.cpp +++ b/python/sunbeam/sunbeam.cpp @@ -143,6 +143,7 @@ py::list get_groups( const Schedule& sch ) { } EclipseState (*parse)( const std::string&, const ParseContext& ) = &Parser::parse; +EclipseState (*parseData) (const std::string &data, const ParseContext& context) = &Parser::parseData; void (ParseContext::*ctx_update)(const std::string&, InputError::Action) = &ParseContext::update; } @@ -161,6 +162,7 @@ py::to_python_converter< const boost::posix_time::ptime, py::register_exception_translator< key_error >( &key_error::translate ); py::def( "parse", parse ); +py::def( "parseData", parseData ); py::class_< EclipseState >( "EclipseState", py::no_init ) .add_property( "title", &EclipseState::getTitle ) diff --git a/python/sunbeam/sunbeam.py b/python/sunbeam/sunbeam.py index 924a950ac..c0ed26948 100644 --- a/python/sunbeam/sunbeam.py +++ b/python/sunbeam/sunbeam.py @@ -1,3 +1,4 @@ +from os.path import isfile import libsunbeam as lib class _delegate(object): @@ -163,5 +164,8 @@ def _parse_context(actions): return ctx -def parse(path, actions = None): - return EclipseState(lib.parse(path, _parse_context(actions))) +def parse(deck, actions = None): + """deck may be a deck string, or a file path""" + if isfile(deck): + return EclipseState(lib.parse(deck, _parse_context(actions))) + return EclipseState(lib.parseData(deck, _parse_context(actions))) diff --git a/tests/parse.py b/tests/parse.py index 6e0b0a762..94f2f5759 100644 --- a/tests/parse.py +++ b/tests/parse.py @@ -3,6 +3,29 @@ import sunbeam class TestParse(unittest.TestCase): + REGIONDATA = """ +START -- 0 +10 MAI 2007 / +RUNSPEC + +DIMENS +2 2 1 / +GRID +DX +4*0.25 / +DY +4*0.25 / +DZ +4*0.25 / +TOPS +4*0.25 / +REGIONS +OPERNUM +3 3 1 2 / +FIPNUM +1 1 2 3 / +""" + def setUp(self): self.spe3fn = 'spe3/SPE3CASE1.DATA' @@ -31,3 +54,7 @@ class TestParse(unittest.TestCase): with self.assertRaises(ValueError): sunbeam.parse(self.spe3fn, "PARSE_RANDOM_SLASH") + + def testData(self): + regtest = sunbeam.parse(self.REGIONDATA) + self.assertEqual([3,3,1,2], regtest.props()['OPERNUM'])