Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
py-namelist
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Claus
py-namelist
Commits
44901c89
Commit
44901c89
authored
Oct 04, 2018
by
Martin Claus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Full code coverage
parent
dc77c8b5
Pipeline
#1896
passed with stage
in 47 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
namelist/namelist.py
namelist/namelist.py
+4
-3
tests/test_parsing.py
tests/test_parsing.py
+21
-5
No files found.
namelist/namelist.py
View file @
44901c89
...
...
@@ -165,12 +165,13 @@ def parse_namelist_string(in_string):
if
match
:
pname
=
match
.
group
(
1
)
index
=
match
.
group
(
3
)
if
index
is
not
None
:
# index assignment
try
:
# index assignment
index
=
int
(
index
)
if
pname
not
in
nml
:
nml
[
pname
]
=
DictClass
()
e
lse
:
e
xcept
TypeError
:
# index is None
nml
[
pname
]
=
[]
continue
continue
# pragma no cover
if
re
.
match
(
namlistend
,
item
):
continue
...
...
tests/test_parsing.py
View file @
44901c89
...
...
@@ -150,7 +150,7 @@ def test_val_conversion(string, val):
@
pytest
.
mark
.
parametrize
(
"string"
,
[
"&nml3 val1=34, val2=35 &end"
,
"&nml3 val1
=34 val2=
35 &end"
,
"&nml3 val1
= 34 val2 =
35 &end"
,
"&nml3
\n
val1=34
\n
val2=35
\n
&end"
,
]
)
...
...
@@ -215,15 +215,31 @@ def test_var_array(string, arr):
assert
type
(
a
)
==
type
(
b
)
@
pytest
.
mark
.
parametrize
(
"string"
,
[
"&nml {} /"
])
@
pytest
.
mark
.
parametrize
(
"d"
,
[{
1
:
'lalal'
,
2
:
35
},])
def
test_index_assignment
(
string
,
d
):
@
pytest
.
mark
.
parametrize
(
"string"
,
[
"&nml {} /"
,
"&nml {} val2=34 /"
])
@
pytest
.
mark
.
parametrize
(
"val1"
,
[
"lala"
,
"((1 + 2) + 3)"
,
3
,
3.0
,
3e6
,
".T."
])
@
pytest
.
mark
.
parametrize
(
"d"
,
[{
1
:
None
,
2
:
35
},{
1
:
None
}])
def
test_index_assignment
(
string
,
val1
,
d
):
val_str
=
""
try
:
int
(
eval
(
val1
))
is_expression
=
True
except
:
is_expression
=
False
is_bool
=
(
val1
==
".T."
)
d
[
1
]
=
val1
for
k
,
v
in
d
.
items
():
val_str
+=
"val({}) = {} "
.
format
(
k
,
v
)
if
is_expression
|
is_bool
:
val_str
+=
"val({}) = {} "
.
format
(
k
,
v
)
else
:
val_str
+=
"val({}) = {} "
.
format
(
k
,
repr
(
v
))
if
is_expression
:
d
[
1
]
=
eval
(
d
[
1
])
if
is_bool
:
d
[
1
]
=
(
val1
==
".T."
)
nml_string
=
string
.
format
(
val_str
)
nml
=
namelist
.
parse_namelist_string
(
nml_string
)[
"nml"
]
print
(
nml_string
)
print
(
repr
(
nml
),
d
)
assert
nml
[
"val"
]
==
d
@
pytest
.
mark
.
parametrize
(
"string"
,
[
"&nml val= {}, val2='lsl'/"
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment