Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NTRfC
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
TFD - Institut für Turbomaschinen und Fluid-Dynamik
tools
NTRfC
Commits
9f2b9b5e
Commit
9f2b9b5e
authored
2 years ago
by
Malte Nyhuis
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
a43e2927
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!10
Merge recent changes in master to we_ahrens
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/dictutils/test_ntrfc_dictutils.py
+13
-9
13 additions, 9 deletions
tests/dictutils/test_ntrfc_dictutils.py
with
13 additions
and
9 deletions
tests/dictutils/test_ntrfc_dictutils.py
+
13
−
9
View file @
9f2b9b5e
from
ntrfc.dictutils.dict_utils
import
nested_dict_pairs_iterator
,
delete_keys_from_dict
,
compare_dictionaries
,
\
set_in_dict
,
get_from_dict
,
merge
def
test_nested_dict_pairs_iterator
():
"""
tests if nested_dict_pairs_iterator returns the right list for a nested dict
nested_dict_pairs_iterator is used for returning a nested dict as a list
which comes in handy when handling nested directories with files
"""
from
ntrfc.dictutils.dict_utils
import
nested_dict_pairs_iterator
test_dictionary
=
{
"
0
"
:
{
"
0
"
:
0
,
"
1
"
:
1
},
"
1
"
:
1
}
check
=
[(
'
0
'
,
'
0
'
,
0
),
(
'
0
'
,
'
1
'
,
1
),
(
'
1
'
,
1
)]
assert
check
==
list
(
nested_dict_pairs_iterator
(
test_dictionary
)),
"
error
"
def
test_delete_keys_from_dict
():
from
ntrfc.dictutils.dict_utils
import
delete_keys_from_dict
test_dictionary
=
{
"
a
"
:
0
,
"
b
"
:
1
}
delete_keys_from_dict
(
test_dictionary
,
"
a
"
)
assert
"
a
"
not
in
test_dictionary
.
keys
()
...
...
@@ -22,6 +20,7 @@ def test_delete_keys_from_dict():
def
test_compare_dictionaries
():
from
ntrfc.dictutils.dict_utils
import
compare_dictionaries
d1
=
{
"
name
"
:
{
"
param_1
"
:
0
,
"
param_2
"
:
3
}}
d2
=
{
"
name
"
:
{
"
param_1
"
:
4
,
"
param_2
"
:
1
}}
ke
,
ve
=
compare_dictionaries
(
d1
,
d2
)
...
...
@@ -30,9 +29,10 @@ def test_compare_dictionaries():
def
test_setInDict
():
dict
=
{
"
toplevel
"
:
{
"
value_1
"
:
0
,
"
value_2
"
:
2
}}
set_in_dict
(
dict
,
[
"
toplevel
"
,
"
value_2
"
],
3
)
assert
dict
[
"
toplevel
"
][
"
value_2
"
]
==
3
from
ntrfc.dictutils.dict_utils
import
set_in_dict
dictionary
=
{
"
toplevel
"
:
{
"
value_1
"
:
0
,
"
value_2
"
:
2
}}
set_in_dict
(
dictionary
,
[
"
toplevel
"
,
"
value_2
"
],
3
)
assert
dictionary
[
"
toplevel
"
][
"
value_2
"
]
==
3
def
test_getFromDict
():
...
...
@@ -41,12 +41,16 @@ def test_getFromDict():
dataDict: dictionary
mapList: list of keys to access value
"""
dict
=
{
"
toplevel
"
:
{
"
midlevel
"
:
{
"
value_1
"
:
1
,
"
value_2
"
:
0
}}}
from
ntrfc.dictutils.dict_utils
import
get_from_dict
assert
get_from_dict
(
dict
,
[
"
toplevel
"
,
"
midlevel
"
,
"
value_2
"
])
==
0
dictionary
=
{
"
toplevel
"
:
{
"
midlevel
"
:
{
"
value_1
"
:
1
,
"
value_2
"
:
0
}}}
assert
get_from_dict
(
dictionary
,
[
"
toplevel
"
,
"
midlevel
"
,
"
value_2
"
])
==
0
def
test_merge
():
from
ntrfc.dictutils.dict_utils
import
merge
dict_1
=
{
"
toplevel_1
"
:
{
"
value_11
"
:
0
}}
dict_2
=
{
"
toplevel_1
"
:
{
"
value_12
"
:
1
},
"
toplevel_2
"
:
{
"
value_21
"
:
3
}}
assert
merge
(
dict_1
,
dict_2
)
==
{
'
toplevel_1
'
:
{
'
value_11
'
:
0
,
'
value_12
'
:
1
},
'
toplevel_2
'
:
{
'
value_21
'
:
3
}}
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