Catch block validation

Change-Id: Ia1fe0c8648e4ef904e227e91b3374f603111c5e7
This commit is contained in:
sslypushenko 2016-09-30 17:14:06 +03:00
parent 80a6886e81
commit 5d2576410c
2 changed files with 26 additions and 8 deletions

View File

@ -37,16 +37,9 @@ CODE_STRUCTURE = {
'Try': {
'keywords': {
'Try': check_req('codeblock'),
'Catch': check_req('codeblock'),
'Catch': check_req('catchblock'),
'Else': check_req('codeblock', False),
'Finally': check_req('codeblock', False)}},
'As': {
'keywords': {
'As': check_req('string'),
'With': check_req('string', False),
'Do': check_req('codeblock'),
}
},
'Parallel': {
'keywords': {
'Limit': check_req('codeblock', False),
@ -114,6 +107,7 @@ class CheckCodeStructure(object):
def __init__(self):
self._check_mappings = {
'codeblock': self.codeblock,
'catchblock': self.catchblock,
'predicate': self.yaql,
'empty': self.empty,
'expression': self.yaql,
@ -139,6 +133,22 @@ class CheckCodeStructure(object):
yield error.report.W202('"{0}" is not valid yaql expression'
''.format(value), value)
def catchblock(self, catchblock):
if isinstance(catchblock, list):
for block in catchblock:
yield self._single_catchblock(block)
else:
yield self._single_catchblock(catchblock)
def _single_catchblock(self, catchblock):
do = catchblock.get('Do')
if not do:
yield error.report.E204('Catch is missing "Do" block', catchblock)
else:
yield self.codeblock(do)
yield self.string(catchblock.get('With', ''))
yield self.string(catchblock.get('As', ''))
def codeblock(self, codeblocks):
if isinstance(codeblocks, list):
for block in codeblocks:

View File

@ -150,6 +150,14 @@ class CodeStructureTest(helpers.BaseValidatorTestClass):
self.assertIn('Value of "213" should be a string',
next(self.g).message)
def test_try_only_do(self):
MULTILINE_BODY = [
{'Try': ['$port.deploy()'],
'Catch': [{
'Do': ['$.string()']}]}
]
self.g = self._checker.codeblock(MULTILINE_BODY)
def test_yaql_accept_bool(self):
self.g = self._checker.yaql(True)