Skip to content

Commit

Permalink
Merge pull request #2426 from hjoliver/2417.directive-internal-spaces
Browse files Browse the repository at this point in the history
Fail __MANY__ names with consecutive spaces.
  • Loading branch information
dvalters committed Sep 12, 2017
2 parents b841bc9 + a4a93cc commit 9dacc55
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/parsec/validate.py
Expand Up @@ -71,8 +71,11 @@ def __init__(self, vtype, keys, value, exc=None):


class IllegalItemError(ValidationError):
def __init__(self, keys, key):
self.msg = 'Illegal item: %s' % itemstr(keys, key)
def __init__(self, keys, key, msg=None):
if msg is not None:
self.msg = 'Illegal item (%s): %s' % (msg, itemstr(keys, key))
else:
self.msg = 'Illegal item: %s' % itemstr(keys, key)


def validate(cfig, spec, keys=[]):
Expand All @@ -86,6 +89,9 @@ def validate(cfig, spec, keys=[]):
# as that of the __MANY__ item, i.e. dict or not-dict.
val_is_dict = isinstance(val, dict)
spc_is_dict = isinstance(spec['__MANY__'], dict)
if not val_is_dict and ' ' in key:
# Item names shouldn't have consec. spaces (GitHub #2417).
raise IllegalItemError(keys, key, 'consecutive spaces')
if (val_is_dict and spc_is_dict) or \
(not val_is_dict and not spc_is_dict):
speckey = '__MANY__'
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/bash/test_header
Expand Up @@ -51,7 +51,7 @@
# Make sure that each line in FILE_TEST is present in FILE_CONTROL
# (stdin if FILE_CONTROL is "-" or missing).
# grep_ok PATTERN FILE
# Run "grep -q PATTERN FILE".
# Run "grep -q -e PATTERN FILE".
# count_ok PATTERN FILE COUNT
# Test that PATTERN occurs in exactly COUNT lines of FILE.
# exists_ok FILE
Expand Down
41 changes: 41 additions & 0 deletions tests/validate/66-fail-consec-spaces.t
@@ -0,0 +1,41 @@
#!/bin/bash
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) 2008-2017 NIWA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Test consecutive spaces in a __MANY__ name fails validation (GitHub #2417).

. $(dirname $0)/test_header
set_test_number 2

TEST_NAME=${TEST_NAME_BASE}-val
cat > suite.rc <<__END__
[scheduling]
[[dependencies]]
graph = task1
[runtime]
[[HPC]]
[[[job]]]
batch system = pbs
[[[directives]]]
-l select=1:ncpus=1:mem=5GB
[[task1]]
inherit = HPC
[[[directives]]]
-l select=1:ncpus=24:mem=20GB # ERROR!
__END__
run_fail $TEST_NAME cylc validate --debug -v suite.rc
grep_ok "Illegal item (consecutive spaces):\
\[runtime\]\[task1\]\[directives\]-l select" $TEST_NAME.stderr

0 comments on commit 9dacc55

Please sign in to comment.