Expand axis params before enumerating values
Change-Id: Ib51c00ae6a000f8c87483fcdc4433a2d0d055942
This commit is contained in:
parent
6d71ade6bd
commit
0f29e2ea3a
jenkins_jobs
tests/yamlparser
@ -14,6 +14,7 @@ import itertools
|
||||
|
||||
from .errors import Context, JenkinsJobsException
|
||||
from .loc_loader import LocList, LocDict
|
||||
from jenkins_jobs.expander import Expander
|
||||
|
||||
|
||||
def _decode_axis_value(axis, value, key_pos, value_pos):
|
||||
@ -43,6 +44,7 @@ def _decode_axis_value(axis, value, key_pos, value_pos):
|
||||
|
||||
|
||||
def enum_dimensions_params(axes, params, defaults):
|
||||
expander = Expander()
|
||||
if not axes:
|
||||
# No axes - instantiate one job/view.
|
||||
yield {}
|
||||
@ -56,7 +58,8 @@ def enum_dimensions_params(axes, params, defaults):
|
||||
value = defaults[axis]
|
||||
except KeyError:
|
||||
continue # May be, value would be received from an another axis values.
|
||||
value = list(_decode_axis_value(axis, value, key_pos, value_pos))
|
||||
expanded_value = expander.expand(value, params)
|
||||
value = list(_decode_axis_value(axis, expanded_value, key_pos, value_pos))
|
||||
dim_values.append(value)
|
||||
for values in itertools.product(*dim_values):
|
||||
yield LocDict.merge(*values)
|
||||
|
@ -106,7 +106,7 @@ deprecated_yaml_tags = [
|
||||
|
||||
# Does not expand string formats. Used in jobs and macros without parameters.
|
||||
class Expander:
|
||||
def __init__(self, config):
|
||||
def __init__(self, config=None):
|
||||
_yaml_object_expanders = {
|
||||
cls: partial(call_expand, self) for cls in yaml_classes_list
|
||||
}
|
||||
|
40
tests/yamlparser/job_fixtures/include-param.xml
Normal file
40
tests/yamlparser/job_fixtures/include-param.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo "param=bar"
|
||||
</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo "param=foo"
|
||||
</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
12
tests/yamlparser/job_fixtures/include-param.yaml
Normal file
12
tests/yamlparser/job_fixtures/include-param.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
- project:
|
||||
name: pj
|
||||
param:
|
||||
!include: include-param.yaml.inc
|
||||
jobs:
|
||||
- a-job-{param}
|
||||
|
||||
- job-template:
|
||||
name: a-job-{param}
|
||||
builders:
|
||||
- shell: |
|
||||
echo "param={param}"
|
2
tests/yamlparser/job_fixtures/include-param.yaml.inc
Normal file
2
tests/yamlparser/job_fixtures/include-param.yaml.inc
Normal file
@ -0,0 +1,2 @@
|
||||
- foo
|
||||
- bar
|
@ -196,11 +196,19 @@ cases = [
|
||||
]
|
||||
|
||||
|
||||
def wrap_with_location(value):
|
||||
if type(value) is dict:
|
||||
return LocDict({key: wrap_with_location(value) for key, value in value.items()})
|
||||
if type(value) is list:
|
||||
return LocList([wrap_with_location(item) for item in value])
|
||||
return value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("axes,params,exclude,expected_dimension_params", cases)
|
||||
def test_dimensions(axes, params, exclude, expected_dimension_params):
|
||||
dimension_params = [
|
||||
p
|
||||
for p in enum_dimensions_params(axes, LocDict(params), defaults={})
|
||||
for p in enum_dimensions_params(axes, wrap_with_location(params), defaults={})
|
||||
if is_point_included(LocList(exclude), p)
|
||||
]
|
||||
assert dimension_params == expected_dimension_params
|
||||
|
Loading…
x
Reference in New Issue
Block a user