Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BIP
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
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
FSL
BIP
Commits
8d83e1dc
Commit
8d83e1dc
authored
2 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test Config dict properties
parent
85c49cea
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
BIP configuration system
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bip/tests/__init__.py
+4
-2
4 additions, 2 deletions
bip/tests/__init__.py
bip/tests/test_bip_utils_config.py
+51
-1
51 additions, 1 deletion
bip/tests/test_bip_utils_config.py
with
55 additions
and
3 deletions
bip/tests/__init__.py
+
4
−
2
View file @
8d83e1dc
...
...
@@ -11,12 +11,14 @@ import tempfile
def
touch
(
fpath
):
"""
Create a dummy file at fpath.
"""
with
open
(
fpath
,
'
wt
'
)
as
f
:
f
.
write
(
fpath
)
@contextlib.contextmanager
def
tempdir
():
"""
Create and change into a temp directory, deleting it afterwards.
"""
prevdir
=
os
.
getcwd
()
with
tempfile
.
TemporaryDirectory
()
as
td
:
os
.
chdir
(
td
)
...
...
@@ -28,6 +30,7 @@ def tempdir():
@contextlib.contextmanager
def
mock_directory
(
contents
):
"""
Create a temp directory with dummy contents.
"""
with
tempdir
()
as
td
:
for
c
in
contents
:
touch
(
c
)
...
...
@@ -35,8 +38,7 @@ def mock_directory(contents):
def
dicts_equal
(
da
,
db
):
"""
Compare two dicts, ignoring order.
"""
da
=
{
k
:
da
[
k
]
for
k
in
sorted
(
da
.
keys
())}
db
=
{
k
:
db
[
k
]
for
k
in
sorted
(
db
.
keys
())}
print
(
da
)
print
(
db
)
return
da
==
db
This diff is collapsed.
Click to expand it.
bip/tests/test_bip_utils_config.py
+
51
−
1
View file @
8d83e1dc
...
...
@@ -245,6 +245,10 @@ def test_Config_create():
for
k
,
v
in
exp
.
items
():
assert
cfg
[
k
]
==
v
with
tempdir
():
cfg
=
config
.
Config
(
'
.
'
)
assert
len
(
cfg
)
==
0
def
test_Config_overrides
():
configtoml
=
tw
.
dedent
(
"""
...
...
@@ -315,4 +319,50 @@ def test_Config_overrides():
def
test_Config_access
():
pass
configtoml
=
tw
.
dedent
(
"""
param1 = 1
param2 =
'
abc
'
param3 = [1, 2, 3]
[abc]
param1 = true
param2 = 0.4
"""
).
strip
()
exp
=
{
'
param1
'
:
1
,
'
param2
'
:
'
abc
'
,
'
param3
'
:
[
1
,
2
,
3
],
'
abc_param1
'
:
True
,
'
abc_param2
'
:
0.4
,
}
with
tempdir
()
as
td
:
open
(
'
config.toml
'
,
'
wt
'
).
write
(
configtoml
)
cfg
=
config
.
Config
(
'
.
'
)
assert
cfg
.
cfgdir
==
td
assert
len
(
cfg
)
==
len
(
exp
)
assert
sorted
(
cfg
.
keys
())
==
sorted
(
exp
.
keys
())
assert
sorted
(
cfg
.
items
())
==
sorted
(
exp
.
items
())
# Order of exp is intentional, to
# match config construction order.
assert
[
v1
==
v2
for
v1
,
v2
in
zip
(
cfg
.
values
(),
exp
.
values
())]
for
k
,
v
in
exp
.
items
():
assert
k
in
cfg
assert
cfg
[
k
]
==
v
assert
getattr
(
cfg
,
k
)
==
v
assert
cfg
.
get
(
k
)
==
v
assert
cfg
.
getall
(
param1
=
0
,
param2
=
1
,
param4
=
3
)
==
\
{
'
param1
'
:
1
,
'
param2
'
:
'
abc
'
,
'
param4
'
:
3
}
assert
cfg
.
gettuple
(
param1
=
0
,
param2
=
1
,
param4
=
3
)
==
(
1
,
'
abc
'
,
3
)
assert
cfg
.
getall
(
'
abc
'
,
param1
=
0
,
param2
=
1
,
param3
=
3
)
==
\
{
'
param1
'
:
True
,
'
param2
'
:
0.4
,
'
param3
'
:
3
}
assert
cfg
.
gettuple
(
'
abc
'
,
param1
=
0
,
param2
=
1
,
param4
=
3
)
==
\
(
True
,
0.4
,
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