Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail __MANY__ names with consecutive spaces. #2426

Merged
merged 3 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/parsec/validate.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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