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
d0cba1fc
Commit
d0cba1fc
authored
2 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: test config file templating, and attribute assignment restriction
parent
74b21b0e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
ENH: Config file templating
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bip/tests/test_bip_utils_config.py
+58
-19
58 additions, 19 deletions
bip/tests/test_bip_utils_config.py
with
58 additions
and
19 deletions
bip/tests/test_bip_utils_config.py
+
58
−
19
View file @
d0cba1fc
...
@@ -189,6 +189,39 @@ def test_Config_load_config_file():
...
@@ -189,6 +189,39 @@ def test_Config_load_config_file():
assert
result
[
k
]
==
v
assert
result
[
k
]
==
v
def
test_Config_load_config_file_jinja2_vars
():
configtoml
=
tw
.
dedent
(
"""
param1 = 1
param2 = {{VAR0}}
[abc]
param3 = {{VAR1}}
param4 = 4
[def]
param5 = 5
{{VAR2}} = 6
"""
).
strip
()
env
=
{
'
VAR0
'
:
'
2
'
,
'
VAR1
'
:
'
3
'
,
'
VAR2
'
:
'
param6
'
,
}
exp
=
{
'
param1
'
:
'
1
'
,
'
param2
'
:
'
2
'
,
'
abc_param3
'
:
'
3
'
,
'
abc_param4
'
:
'
4
'
,
'
def_param5
'
:
'
5
'
,
'
def_param6
'
:
'
6
'
,
}
with
tempdir
():
open
(
'
config.toml
'
,
'
wt
'
).
write
(
configtoml
)
cfg
=
config
.
Config
.
load_config_file
(
'
config.toml
'
,
env
=
env
)
def
test_Config_load_config_file_main_relabelling
():
def
test_Config_load_config_file_main_relabelling
():
configtoml
=
tw
.
dedent
(
"""
configtoml
=
tw
.
dedent
(
"""
param1 = 1
param1 = 1
...
@@ -349,28 +382,34 @@ def test_Config_access():
...
@@ -349,28 +382,34 @@ def test_Config_access():
cfg
=
config
.
Config
(
'
.
'
)
cfg
=
config
.
Config
(
'
.
'
)
assert
cfg
.
cfgdir
==
td
assert
cfg
.
cfgdir
==
td
assert
len
(
cfg
)
==
len
(
exp
)
assert
len
(
cfg
)
==
len
(
exp
)
assert
sorted
(
cfg
.
keys
())
==
sorted
(
exp
.
keys
())
assert
sorted
(
cfg
.
keys
())
==
sorted
(
exp
.
keys
())
assert
sorted
(
cfg
.
items
())
==
sorted
(
exp
.
items
())
assert
sorted
(
cfg
.
items
())
==
sorted
(
exp
.
items
())
# Order of exp is intentional, to
# Order of exp is intentional, to
# match config construction order.
# match config construction order.
assert
[
v1
==
v2
for
v1
,
v2
in
zip
(
cfg
.
values
(),
exp
.
values
())]
assert
[
v1
==
v2
for
v1
,
v2
in
zip
(
cfg
.
values
(),
exp
.
values
())]
for
k
,
v
in
exp
.
items
():
for
k
,
v
in
exp
.
items
():
assert
k
in
cfg
assert
k
in
cfg
assert
cfg
[
k
]
==
v
assert
cfg
[
k
]
==
v
assert
getattr
(
cfg
,
k
)
==
v
assert
getattr
(
cfg
,
k
)
==
v
assert
cfg
.
get
(
k
)
==
v
assert
cfg
.
get
(
k
)
==
v
assert
cfg
.
getall
(
param1
=
0
,
param2
=
1
,
param4
=
3
)
==
\
{
'
param1
'
:
1
,
'
param2
'
:
'
abc
'
,
'
param4
'
:
3
}
assert
cfg
.
getall
(
param1
=
0
,
param2
=
1
,
param4
=
3
)
==
\
assert
cfg
.
gettuple
(
param1
=
0
,
param2
=
1
,
param4
=
3
)
==
(
1
,
'
abc
'
,
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
)
assert
cfg
.
getall
(
'
abc
'
,
param1
=
0
,
param2
=
1
,
param3
=
3
)
==
\
# Can add new attributes as normal
{
'
param1
'
:
True
,
'
param2
'
:
0.4
,
'
param3
'
:
3
}
cfg
.
new_param
=
12345
assert
cfg
.
gettuple
(
'
abc
'
,
param1
=
0
,
param2
=
1
,
param4
=
3
)
==
\
# But cannot override old attributes
(
True
,
0.4
,
3
)
with
pytest
.
raises
(
config
.
ConfigError
):
cfg
.
param1
=
6
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