Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 633d746

Browse files
Merge pull request #401 from simphony/regenerate-validation
Regenerate validation and fix missing code
2 parents 031102c + f33577f commit 633d746

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

scripts/validation.template

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is copied and renamed in simphony/cuds/meta/ to support the
22
# meta classes in performing validation
33
import warnings
4-
4+
import re
55
import numpy
66

77

@@ -43,6 +43,11 @@ def without_cuba_prefix(string):
4343
return string
4444

4545

46+
def is_cuba_key(value):
47+
"""True if value is a qualified cuba key"""
48+
return isinstance(value, (str, unicode)) and value.startswith("CUBA.")
49+
50+
4651
def check_valid_shape(value, shape, cuba_key):
4752
""" Check if `value` is a sequence that comply with `shape`.
4853
Note that the cuba data dimensionality is also taken into account.

simphony/cuds/meta/validation.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,51 @@
11
# This file is copied and renamed in simphony/cuds/meta/ to support the
22
# meta classes in performing validation
33
import warnings
4-
4+
import re
55
import numpy
66

7-
from scripts.utils import to_camel_case, without_cuba_prefix
7+
8+
def to_camel_case(text, special={'cuds': 'CUDS'}):
9+
""" Convert text to CamelCase (for class name)
10+
11+
Parameters
12+
----------
13+
text : str
14+
The text to be converted
15+
16+
special : dict
17+
If any substring of text (lower case) matches a key of `special`,
18+
the substring is replaced by the value
19+
20+
Returns
21+
-------
22+
result : str
23+
"""
24+
25+
def replace_func(matched):
26+
# word should be lower case already
27+
word = matched.group(0).strip("_")
28+
if word in special:
29+
# Handle special case
30+
return special[word]
31+
else:
32+
# Capitalise the first character
33+
return word[0].upper() + word[1:]
34+
35+
return re.sub(r'(_?[a-zA-Z]+)', replace_func, text.lower())
36+
37+
38+
def without_cuba_prefix(string):
39+
"""Removes the CUBA. prefix to the string if there."""
40+
if is_cuba_key(string):
41+
return string[5:]
42+
43+
return string
44+
45+
46+
def is_cuba_key(value):
47+
"""True if value is a qualified cuba key"""
48+
return isinstance(value, (str, unicode)) and value.startswith("CUBA.")
849

950

1051
def check_valid_shape(value, shape, cuba_key):

0 commit comments

Comments
 (0)