Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
panacota
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Amandine PERRIN
panacota
Commits
3d6dbaa5
Commit
3d6dbaa5
authored
3 years ago
by
Amandine PERRIN
Browse files
Options
Downloads
Patches
Plain Diff
add tests for clean_str in config parser
parent
318321a2
No related branches found
No related tags found
No related merge requests found
Pipeline
#62556
failed
3 years ago
Stage: test
Stage: coverage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
PanACoTA/utils_argparse.py
+1
-0
1 addition, 0 deletions
PanACoTA/utils_argparse.py
test/data/utils/configfile-str.ini
+25
-0
25 additions, 0 deletions
test/data/utils/configfile-str.ini
test/test_unit/test_utils-argparse.py
+60
-1
60 additions, 1 deletion
test/test_unit/test_utils-argparse.py
with
86 additions
and
1 deletion
PanACoTA/utils_argparse.py
+
1
−
0
View file @
3d6dbaa5
...
...
@@ -244,6 +244,7 @@ class Conf_all_parser(configparser.ConfigParser):
for
param
in
self
.
sec_dicts
[
section
]:
initial
=
self
.
sec_dicts
[
section
][
param
]
self
.
sec_dicts
[
section
][
param
]
=
initial
.
strip
(
'"'
)
self
[
section
][
param
]
=
initial
.
strip
(
'"'
)
def
get_section_dict
(
self
,
section
):
"""
...
...
This diff is collapsed.
Click to expand it.
test/data/utils/configfile-str.ini
0 → 100644
+
25
−
0
View file @
3d6dbaa5
[DEFAULT]
param1
=
3
param2
=
10
[sec2]
param2
=
myval
=
"parameter"
param3
=
myparameter
paramint
=
"2"
[sec3]
[sec_bool]
bool
num_false
=
0
bool_num_true
=
1
bool_f
=
"off"
bool_t
=
ON
bool_n
=
no
bool_y
=
YES
bool_false
=
FalSe
bool_true
=
tRUE
[sec_float]
float_param
=
"0.12"
float_param2
=
1e5
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/test_unit/test_utils-argparse.py
+
60
−
1
View file @
3d6dbaa5
...
...
@@ -271,6 +271,25 @@ def test_conf_parser_init():
"
sec4
"
:
{}}
# But sec4 dict is empty (no param given in configfile)
def
test_conf_parser_init_noCleanStr
():
"""
Test config parser with a given config file. Do not clean str (keep surounding
""
)
"""
# configfile but no section
cfg_file
=
os
.
path
.
join
(
"
test
"
,
"
data
"
,
"
utils
"
,
"
configfile-str.ini
"
)
c
=
autils
.
Conf_all_parser
(
cfg_file
,
clean_str
=
False
)
assert
c
[
"
sec2
"
][
"
param1
"
]
==
"
3
"
assert
c
[
"
sec2
"
][
"
param2
"
]
==
''
assert
c
[
"
sec2
"
][
"
myval
"
]
==
'"
parameter
"'
assert
c
[
"
sec2
"
][
"
param3
"
]
==
'
myparameter
'
assert
c
[
"
sec3
"
][
"
param1
"
]
==
"
3
"
assert
c
[
"
sec3
"
][
"
param2
"
]
==
"
10
"
assert
c
[
"
sec_bool
"
][
"
bool num_false
"
]
==
"
0
"
assert
c
[
"
sec_bool
"
][
"
bool_t
"
]
==
"
ON
"
assert
c
[
"
sec_bool
"
][
"
bool_f
"
]
==
'"
off
"'
assert
c
.
sec_dicts
==
{}
def
test_conf_parser_clean_str
(
capsys
):
"""
Check that surounding
""
are removed
...
...
@@ -279,7 +298,7 @@ def test_conf_parser_clean_str(capsys):
c
=
autils
.
Conf_all_parser
(
cfg_file
,
[
"
sec2
"
,
"
sec_bool
"
])
assert
c
.
get_section_dict
(
"
sec2
"
)
==
{
"
param2
"
:
""
,
"
myval
"
:
"
parameter
"
,
'
param3
'
:
"
myparameter
"
,
"
param1
"
:
"
3
"
}
"
param1
"
:
"
3
"
,
"
paramint
"
:
"
2
"
}
assert
c
.
get_section_dict
(
"
sec_bool
"
)
==
{
"
bool num_false
"
:
"
0
"
,
"
bool_num_true
"
:
"
1
"
,
"
bool_f
"
:
"
off
"
,
"
bool_t
"
:
"
ON
"
,
"
bool_n
"
:
"
no
"
,
"
bool_y
"
:
"
YES
"
,
...
...
@@ -395,6 +414,21 @@ def test_conf_parser_setbool(capsys):
assert
c1
[
"
sec_bool
"
][
"
bool_true
"
]
==
"
tRUE
"
assert
c1
.
sec_dicts
[
"
sec_bool
"
][
"
bool_true
"
]
==
True
# With a boolean called with "", not cleaned
cfg_file
=
os
.
path
.
join
(
"
test
"
,
"
data
"
,
"
utils
"
,
"
configfile-str.ini
"
)
c_str
=
autils
.
Conf_all_parser
(
cfg_file
,
[
"
sec_bool
"
],
clean_str
=
False
)
with
pytest
.
raises
(
SystemExit
):
c_str
.
set_boolean
(
"
sec_bool
"
,
"
bool_f
"
)
out
,
err
=
capsys
.
readouterr
()
assert
(
'
ERROR: bool_f must be a boolean. Wrong value:
"
off
"
.
'
)
in
out
# With a boolean called with "" but cleaned
cfg_file
=
os
.
path
.
join
(
"
test
"
,
"
data
"
,
"
utils
"
,
"
configfile-str.ini
"
)
c_str
=
autils
.
Conf_all_parser
(
cfg_file
,
[
"
sec_bool
"
])
c_str
.
set_boolean
(
"
sec_bool
"
,
"
bool_f
"
)
assert
c1
[
"
sec_bool
"
][
"
bool_f
"
]
==
'
off
'
assert
c1
.
sec_dicts
[
"
sec_bool
"
][
"
bool_f
"
]
==
False
# error
with
pytest
.
raises
(
SystemExit
):
c1
.
set_boolean
(
'
sec1
'
,
"
param1
"
)
...
...
@@ -411,6 +445,14 @@ def test_conf_parser_setint(capsys):
assert
c1
[
"
sec1
"
][
"
param1
"
]
==
"
10
"
assert
c1
.
sec_dicts
[
"
sec1
"
][
"
param1
"
]
==
10
# With an int called with "" but cleaned
cfg_file
=
os
.
path
.
join
(
"
test
"
,
"
data
"
,
"
utils
"
,
"
configfile-str.ini
"
)
c_str
=
autils
.
Conf_all_parser
(
cfg_file
,
[
"
sec2
"
])
assert
c_str
.
sec_dicts
[
"
sec2
"
][
"
paramint
"
]
==
"
2
"
c_str
.
set_int
(
"
sec2
"
,
"
paramint
"
)
assert
c_str
[
"
sec2
"
][
"
paramint
"
]
==
"
2
"
assert
c_str
.
sec_dicts
[
"
sec2
"
][
"
paramint
"
]
==
2
with
pytest
.
raises
(
SystemExit
):
c1
.
set_int
(
"
sec1
"
,
"
toto
"
)
out
,
err
=
capsys
.
readouterr
()
...
...
@@ -436,3 +478,20 @@ def test_conf_parser_setfloat(capsys):
c1
.
set_float
(
"
sec1
"
,
"
toto
"
)
out
,
err
=
capsys
.
readouterr
()
assert
(
'
ERROR: toto must be a float. Wrong value: parameter.
'
)
in
out
# With a fload called with "" but cleaned
cfg_file
=
os
.
path
.
join
(
"
test
"
,
"
data
"
,
"
utils
"
,
"
configfile-str.ini
"
)
c_str
=
autils
.
Conf_all_parser
(
cfg_file
,
[
"
sec_float
"
])
assert
c_str
.
sec_dicts
[
"
sec_float
"
][
"
float_param
"
]
==
"
0.12
"
c_str
.
set_float
(
"
sec_float
"
,
"
float_param
"
)
assert
c_str
[
"
sec_float
"
][
"
float_param
"
]
==
"
0.12
"
assert
c_str
.
sec_dicts
[
"
sec_float
"
][
"
float_param
"
]
==
0.12
# With a fload called with "" not cleaned
cfg_file
=
os
.
path
.
join
(
"
test
"
,
"
data
"
,
"
utils
"
,
"
configfile-str.ini
"
)
c_str
=
autils
.
Conf_all_parser
(
cfg_file
,
[
"
sec_float
"
],
clean_str
=
False
)
assert
c_str
.
sec_dicts
[
"
sec_float
"
][
"
float_param
"
]
==
'"
0.12
"'
with
pytest
.
raises
(
SystemExit
):
c_str
.
set_float
(
"
sec_float
"
,
"
float_param
"
)
out
,
err
=
capsys
.
readouterr
()
assert
(
'
ERROR: float_param must be a float. Wrong value:
"
0.12
"
.
'
)
in
out
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment