Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Python Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Tools
Python Toolbox
Commits
2448a5bd
Verified
Commit
2448a5bd
authored
3 months ago
by
Yoann Schneider
Browse files
Options
Downloads
Patches
Plain Diff
Correctly handle null values for arguments
parent
bfabe321
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!22
Correctly handle null values for arguments
Pipeline
#202624
passed
3 months ago
Stage: build
Changes
2
Pipelines
8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
teklia_toolbox/config.py
+1
-2
1 addition, 2 deletions
teklia_toolbox/config.py
tests/test_config.py
+21
-0
21 additions, 0 deletions
tests/test_config.py
with
22 additions
and
2 deletions
teklia_toolbox/config.py
+
1
−
2
View file @
2448a5bd
...
...
@@ -95,9 +95,8 @@ class ConfigParser:
for
name
in
data
:
if
name
not
in
self
.
options
:
errors
[
name
]
=
"
This option does not exist
"
for
name
,
option
in
self
.
options
.
items
():
if
name
i
n
data
:
if
data
.
get
(
name
)
i
s
not
None
:
value
=
data
[
name
]
elif
option
.
default
is
UNSET
:
errors
[
name
]
=
"
This option is required
"
...
...
This diff is collapsed.
Click to expand it.
tests/test_config.py
+
21
−
0
View file @
2448a5bd
...
...
@@ -82,3 +82,24 @@ class TestConfigParser(TestCase):
"
unknownthing
"
:
"
This option does not exist
"
,
},
)
def
test_parse_null_no_default
(
self
):
parser
=
ConfigParser
()
parser
.
add_option
(
"
something
"
,
type
=
str
)
with
self
.
assertRaises
(
ConfigurationError
)
as
context
:
parser
.
parse_data
({
"
something
"
:
None
})
self
.
assertDictEqual
(
context
.
exception
.
errors
,
{
"
something
"
:
"
This option is required
"
,
},
)
def
test_parse_null_with_default
(
self
):
parser
=
ConfigParser
()
parser
.
add_option
(
"
something
"
,
type
=
str
,
default
=
None
)
self
.
assertDictEqual
(
parser
.
parse_data
({
"
something
"
:
None
}),
{
"
something
"
:
None
},
)
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