Commit c0e835b7 authored by Wez's avatar Wez Committed by Commit Bot

Add support for appending list values in mixins.

Introduce a new $mixin_append key to mixins. Values in the $mixin_append
dictionary must be lists, and will be appended to any existing items in
the corresponding key of the test specification.

Bug: 879806
Change-Id: Ibd51c679df1944bcc9f34a4acba47ee39a5f871d
Reviewed-on: https://chromium-review.googlesource.com/c/1306352
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarStephen Martinis <martiniss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603705}
parent 14e9c760
......@@ -756,9 +756,6 @@ class BBJSONGenerator(object):
is then applied to every dimension set in the test.
"""
# TODO(martiniss): Maybe make lists extend, possibly on a case by case
# basis. Motivation is 'args', where you want a common base, and then
# different mixins adding different sets of args.
new_test = copy.deepcopy(test)
mixin = copy.deepcopy(mixin)
......@@ -777,6 +774,23 @@ class BBJSONGenerator(object):
new_test['swarming'].update(swarming_mixin)
del mixin['swarming']
if '$mixin_append' in mixin:
# Values specified under $mixin_append should be appended to existing
# lists, rather than replacing them.
mixin_append = mixin['$mixin_append']
for key in mixin_append:
new_test.setdefault(key, [])
if not isinstance(mixin_append[key], list):
raise BBGenErr(
'Key "' + key + '" in $mixin_append must be a list.')
if not isinstance(new_test[key], list):
raise BBGenErr(
'Cannot apply $mixin_append to non-list "' + key + '".')
new_test[key].extend(mixin_append[key])
if 'args' in mixin_append:
new_test['args'] = self.maybe_fixup_args_array(new_test['args'])
del mixin['$mixin_append']
new_test.update(mixin)
return new_test
......
......@@ -2145,6 +2145,36 @@ SWARMING_MIXINS = """\
}
"""
SWARMING_MIXINS_APPEND = """\
{
'builder_mixin': {
'$mixin_append': {
'args': [ '--mixin-argument' ],
},
},
}
"""
SWARMING_MIXINS_APPEND_NOT_LIST = """\
{
'builder_mixin': {
'$mixin_append': {
'args': 'I am not a list',
},
},
}
"""
SWARMING_MIXINS_APPEND_TO_SWARMING = """\
{
'builder_mixin': {
'$mixin_append': {
'swarming': [ 'swarming!' ],
},
},
}
"""
SWARMING_MIXINS_DUPLICATED = """\
{
'builder_mixin': {
......@@ -2296,6 +2326,27 @@ BUILDER_MIXIN_NON_SWARMING_WATERFALL_OUTPUT = """\
}
"""
BUILDER_MIXIN_APPEND_ARGS_WATERFALL_OUTPUT = """\
{
"AAAAA1 AUTOGENERATED FILE DO NOT EDIT": {},
"AAAAA2 See generate_buildbot_json.py to make changes": {},
"Fake Tester": {
"gtest_tests": [
{
"args": [
"--c_arg",
"--mixin-argument"
],
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "foo_test"
}
]
}
}
"""
TEST_MIXIN_WATERFALL_OUTPUT = """\
{
"AAAAA1 AUTOGENERATED FILE DO NOT EDIT": {},
......@@ -2530,6 +2581,39 @@ class MixinTests(unittest.TestCase):
'<snip>',
])
def test_mixin_append_args(self):
fbb = FakeBBGen(FOO_GTESTS_BUILDER_MIXIN_WATERFALL,
FOO_TEST_SUITE_WITH_ARGS,
EMPTY_PYL_FILE,
SWARMING_MIXINS_APPEND,
LUCI_MILO_CFG)
fbb.files['chromium.test.json'] = BUILDER_MIXIN_APPEND_ARGS_WATERFALL_OUTPUT
fbb.check_output_file_consistency(verbose=True)
self.assertFalse(fbb.printed_lines)
def test_mixin_append_mixin_field_not_list(self):
fbb = FakeBBGen(FOO_GTESTS_BUILDER_MIXIN_WATERFALL,
FOO_TEST_SUITE_WITH_ARGS,
EMPTY_PYL_FILE,
SWARMING_MIXINS_APPEND_NOT_LIST,
LUCI_MILO_CFG)
with self.assertRaisesRegexp(
generate_buildbot_json.BBGenErr,
'Key "args" in \$mixin_append must be a list.'):
fbb.check_output_file_consistency(verbose=True)
self.assertFalse(fbb.printed_lines)
def test_mixin_append_test_field_not_list(self):
fbb = FakeBBGen(FOO_GTESTS_BUILDER_MIXIN_WATERFALL,
FOO_TEST_SUITE,
EMPTY_PYL_FILE,
SWARMING_MIXINS_APPEND_TO_SWARMING,
LUCI_MILO_CFG)
with self.assertRaisesRegexp(
generate_buildbot_json.BBGenErr,
'Cannot apply \$mixin_append to non-list "swarming".'):
fbb.check_output_file_consistency(verbose=True)
self.assertFalse(fbb.printed_lines)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment