Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Supervised MultiModal Integration Tool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Baptiste Bauvin
Supervised MultiModal Integration Tool
Commits
da09599b
Commit
da09599b
authored
Sep 20, 2019
by
Baptiste Bauvin
Browse files
Options
Downloads
Patches
Plain Diff
Forgot to add the files
parent
7f42a6d1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
multiview_platform/MonoMultiViewClassifiers/utils/configuration.py
+37
-0
37 additions, 0 deletions
..._platform/MonoMultiViewClassifiers/utils/configuration.py
multiview_platform/Tests/Test_utils/test_configuration.py
+71
-0
71 additions, 0 deletions
multiview_platform/Tests/Test_utils/test_configuration.py
with
108 additions
and
0 deletions
multiview_platform/MonoMultiViewClassifiers/utils/configuration.py
0 → 100644
+
37
−
0
View file @
da09599b
import
configparser
import
builtins
from
distutils.util
import
strtobool
as
tobool
def
get_the_args
(
path_to_config_file
=
"
../config_files/config.ini
"
):
"""
This is the main function for extracting the args for a
'
.ini
'
file
"""
config_parser
=
configparser
.
ConfigParser
(
comment_prefixes
=
(
'
#
'
))
config_parser
.
read
(
path_to_config_file
)
config_dict
=
{}
for
section
in
config_parser
:
config_dict
[
section
]
=
{}
for
key
in
config_parser
[
section
]:
value
=
format_raw_arg
(
config_parser
[
section
][
key
])
config_dict
[
section
][
key
]
=
value
return
config_dict
def
format_raw_arg
(
raw_arg
):
"""
This function is used to convert the raw arg in a types value.
For example,
'
list_int ; 10 20
'
will be formatted in [10,20]
"""
function_name
,
raw_value
=
raw_arg
.
split
(
"
;
"
)
if
function_name
.
startswith
(
"
list
"
):
function_name
=
function_name
.
split
(
"
_
"
)[
1
]
raw_values
=
raw_value
.
split
(
"
"
)
value
=
[
getattr
(
builtins
,
function_name
)(
raw_value
)
if
function_name
!=
"
bool
"
else
bool
(
tobool
(
raw_value
))
for
raw_value
in
raw_values
]
else
:
if
raw_value
==
"
None
"
:
value
=
None
else
:
if
function_name
==
"
bool
"
:
value
=
bool
(
tobool
(
raw_value
))
else
:
value
=
getattr
(
builtins
,
function_name
)(
raw_value
)
return
value
This diff is collapsed.
Click to expand it.
multiview_platform/Tests/Test_utils/test_configuration.py
0 → 100644
+
71
−
0
View file @
da09599b
import
os
import
unittest
import
numpy
as
np
from
...MonoMultiViewClassifiers.utils
import
configuration
class
Test_get_the_args
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
path_to_config_file
=
"
multiview_platform/Tests/tmp_tests/config_temp.ini
"
os
.
mkdir
(
"
multiview_platform/Tests/tmp_tests
"
)
config_file
=
open
(
self
.
path_to_config_file
,
"
w
"
)
config_file
.
write
(
"
[Base]
\n
first_arg = int ; 10
\n
second_arg = list_float ; 12.5 1e-06
\n
[Classification]
\n
third_arg = bool ; yes
"
)
config_file
.
close
()
def
tearDown
(
self
):
os
.
remove
(
"
multiview_platform/Tests/tmp_tests/config_temp.ini
"
)
os
.
rmdir
(
"
multiview_platform/Tests/tmp_tests
"
)
def
test_file_loading
(
self
):
config_dict
=
configuration
.
get_the_args
(
self
.
path_to_config_file
)
self
.
assertEqual
(
type
(
config_dict
),
dict
)
def
test_dict_format
(
self
):
config_dict
=
configuration
.
get_the_args
(
self
.
path_to_config_file
)
self
.
assertIn
(
"
Base
"
,
config_dict
)
self
.
assertIn
(
"
Classification
"
,
config_dict
)
self
.
assertIn
(
"
first_arg
"
,
config_dict
[
"
Base
"
])
self
.
assertIn
(
"
third_arg
"
,
config_dict
[
"
Classification
"
])
def
test_arguments
(
self
):
config_dict
=
configuration
.
get_the_args
(
self
.
path_to_config_file
)
self
.
assertEqual
(
config_dict
[
"
Base
"
][
"
first_arg
"
],
10
)
self
.
assertEqual
(
config_dict
[
"
Base
"
][
"
second_arg
"
],
[
12.5
,
1e-06
])
self
.
assertEqual
(
config_dict
[
"
Classification
"
][
"
third_arg
"
],
True
)
class
Test_format_the_args
(
unittest
.
TestCase
):
def
test_bool
(
self
):
value
=
configuration
.
format_raw_arg
(
"
bool ; yes
"
)
self
.
assertEqual
(
value
,
True
)
def
test_int
(
self
):
value
=
configuration
.
format_raw_arg
(
"
int ; 1
"
)
self
.
assertEqual
(
value
,
1
)
def
test_float
(
self
):
value
=
configuration
.
format_raw_arg
(
"
float ; 1.5
"
)
self
.
assertEqual
(
value
,
1.5
)
def
test_string
(
self
):
value
=
configuration
.
format_raw_arg
(
"
str ; chicken_is_heaven
"
)
self
.
assertEqual
(
value
,
"
chicken_is_heaven
"
)
def
test_list_bool
(
self
):
value
=
configuration
.
format_raw_arg
(
"
list_bool ; yes no yes yes
"
)
self
.
assertEqual
(
value
,
[
True
,
False
,
True
,
True
])
def
test_list_int
(
self
):
value
=
configuration
.
format_raw_arg
(
"
list_int ; 1 2 3 4
"
)
self
.
assertEqual
(
value
,
[
1
,
2
,
3
,
4
])
def
test_list_float
(
self
):
value
=
configuration
.
format_raw_arg
(
"
list_float ; 1.5 1.6 1.7
"
)
self
.
assertEqual
(
value
,
[
1.5
,
1.6
,
1.7
])
def
test_list_string
(
self
):
value
=
configuration
.
format_raw_arg
(
"
list_str ; list string
"
)
self
.
assertEqual
(
value
,
[
"
list
"
,
"
string
"
])
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