Merge "Update hacking for Python3"

This commit is contained in:
Zuul 2020-04-07 15:40:23 +00:00 committed by Gerrit Code Review
commit 3957724fb4
14 changed files with 58 additions and 54 deletions

View File

@ -7,15 +7,12 @@ coverage==4.0
docutils==0.11
extras==1.0.0
fixtures==3.0.0
flake8==2.5.5
hacking==0.12.0
imagesize==0.7.1
iso8601==0.1.11
Jinja2==2.10
keystoneauth1==3.4.0
linecache2==1.0.0
MarkupSafe==1.0
mccabe==0.2.1
mock==2.0.0
mox3==0.20.0
openstackdocstheme==1.20.0
@ -23,9 +20,7 @@ os-client-config==1.28.0
oslosphinx==4.7.0
oslotest==3.2.0
pbr==2.0.0
pep8==1.5.7
prettytable==0.7.2
pyflakes==0.8.1
Pygments==2.2.0
pyparsing==2.1.0
pyperclip==1.5.27

View File

@ -1,7 +1,7 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
hacking>=3.0,<3.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
oslotest>=3.2.0 # Apache-2.0

View File

@ -608,7 +608,7 @@ constraint_mapping = {
Constraint.MIN_LENGTH: MinLength,
Constraint.MAX_LENGTH: MaxLength,
Constraint.PATTERN: Pattern
}
}
def get_constraint_class(type):

View File

@ -21,7 +21,9 @@ from toscaparser.elements.statefulentitytype import StatefulEntityType
class NodeType(StatefulEntityType):
'''TOSCA built-in node type.'''
SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION, DESCRIPTION, ATTRIBUTES, REQUIREMENTS, CAPABILITIES, INTERFACES, ARTIFACTS) = \
SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION,
DESCRIPTION, ATTRIBUTES, REQUIREMENTS, CAPABILITIES,
INTERFACES, ARTIFACTS) = \
('derived_from', 'metadata', 'properties', 'version',
'description', 'attributes', 'requirements', 'capabilities',
'interfaces', 'artifacts')

View File

@ -55,7 +55,7 @@ class ScalarUnit(object):
ExceptionCollector.appendException(ValueError(msg))
def validate_scalar_unit(self):
regex = re.compile('([0-9.]+)\s*(\w+)')
regex = re.compile(r'([0-9.]+)\s*(\w+)')
try:
result = regex.match(str(self.value)).groups()
validateutils.str_to_num(result[0])
@ -75,7 +75,7 @@ class ScalarUnit(object):
unit = self.SCALAR_UNIT_DEFAULT
self.validate_scalar_unit()
regex = re.compile('([0-9.]+)\s*(\w+)')
regex = re.compile(r'([0-9.]+)\s*(\w+)')
result = regex.match(str(self.value)).groups()
converted = (float(validateutils.str_to_num(result[0]))
* self.SCALAR_UNIT_DICT[result[1]]
@ -112,7 +112,7 @@ scalarunit_mapping = {
ScalarUnit.SCALAR_UNIT_FREQUENCY: ScalarUnit_Frequency,
ScalarUnit.SCALAR_UNIT_SIZE: ScalarUnit_Size,
ScalarUnit.SCALAR_UNIT_TIME: ScalarUnit_Time,
}
}
def get_scalarunit_class(type):

View File

@ -34,7 +34,8 @@ class EntityTemplate(object):
('derived_from', 'properties', 'requirements', 'interfaces',
'capabilities', 'type', 'description', 'directives',
'attributes', 'artifacts', 'node_filter', 'copy')
REQUIREMENTS_SECTION = (NODE, CAPABILITY, RELATIONSHIP, OCCURRENCES, NODE_FILTER) = \
REQUIREMENTS_SECTION = (NODE, CAPABILITY, RELATIONSHIP, OCCURRENCES,
NODE_FILTER) = \
('node', 'capability', 'relationship',
'occurrences', 'node_filter')
# Special key names

View File

@ -298,7 +298,7 @@ class GetAttribute(Function):
ExceptionCollector.appendException(
KeyError(_(
'Node template "{0}" was not found.'
).format(node_template_name)))
).format(node_template_name)))
def _find_req_or_cap_attribute(self, req_or_cap, attr_name):
node_tpl = self._find_node_template(self.args[0])
@ -536,8 +536,8 @@ class GetProperty(Function):
KeyError(_(
'Node template "{0}" was not found.'
' referenced from node template {1}'
).format(node_template_name,
self.context.name)))
).format(node_template_name,
self.context.name)))
def _get_index_value(self, value, index):
if isinstance(value, list):
@ -742,7 +742,7 @@ class GetOperationOutput(Function):
ExceptionCollector.appendException(
KeyError(_(
'Node template "{0}" was not found.'
).format(node_template_name)))
).format(node_template_name)))
def result(self):
return self
@ -822,6 +822,7 @@ class Token(Function):
def result(self):
return self
function_mappings = {
GET_PROPERTY: GetProperty,
GET_INPUT: GetInput,

View File

@ -232,16 +232,16 @@ class ImportsLoader(object):
self.path))
if file_path[0] != '' and dir_path.endswith(
file_path[0]):
import_template = dir_path + "/" +\
file_path[2]
if not os.path.isfile(import_template):
msg = (_('"%(import_template)s" is'
'not a valid file')
% {'import_template':
import_template})
log.error(msg)
ExceptionCollector.appendException
(ValueError(msg))
import_template = dir_path + "/" +\
file_path[2]
if not os.path.isfile(import_template):
msg = (_('"%(import_template)s" is '
'not a valid file')
% {'import_template':
import_template})
log.error(msg)
ExceptionCollector.appendException
(ValueError(msg))
else: # template is pre-parsed
if os.path.isabs(file_name) and os.path.isfile(file_name):
a_file = True

View File

@ -235,8 +235,9 @@ class NodeTemplate(EntityTemplate):
DataEntity.validate_datatype('list', occurrences)
for value in occurrences:
DataEntity.validate_datatype('integer', value)
if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \
or occurrences[1] == 0:
if (len(occurrences) != 2
or not (0 <= occurrences[0] <= occurrences[1])
or occurrences[1] == 0):
ExceptionCollector.appendException(
InvalidPropertyValueError(what=(occurrences)))

View File

@ -334,17 +334,17 @@ class ToscaTemplateTest(TestCase):
relation, node in node_tpl.relationships.items()])
self.assertEqual(expected_relationship, actual_relationship)
if node_tpl.name == 'mysql_database':
self.assertEqual(
[('tosca.relationships.HostedOn', 'my_dbms')],
[(relation.type, node.name) for
relation,
node in node_tpl.relationships.items()])
self.assertEqual(
[('tosca.relationships.HostedOn', 'my_dbms')],
[(relation.type, node.name) for
relation,
node in node_tpl.relationships.items()])
if node_tpl.name == 'my_server':
self.assertEqual(
[('tosca.relationships.AttachesTo', 'my_storage')],
[(relation.type, node.name) for
relation,
node in node_tpl.relationships.items()])
self.assertEqual(
[('tosca.relationships.AttachesTo', 'my_storage')],
[(relation.type, node.name) for
relation,
node in node_tpl.relationships.items()])
def test_template_requirements_not_implemented(self):
# TODO(spzala): replace this test with new one once TOSCA types look up

View File

@ -448,16 +448,16 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
"WebApplication.WordPress"))
def test_imports_file_with_suffix_yml(self):
tpl_snippet = '''
imports:
- custom_types/wordpress.yml
'''
path = 'toscaparser/tests/data/tosca_elk.yaml'
custom_defs = self._imports_content_test(tpl_snippet,
path,
"node_types")
self.assertTrue(custom_defs.get("tosca.nodes."
"WebApplication.WordPress"))
tpl_snippet = '''
imports:
- custom_types/wordpress.yml
'''
path = 'toscaparser/tests/data/tosca_elk.yaml'
custom_defs = self._imports_content_test(tpl_snippet,
path,
"node_types")
self.assertTrue(custom_defs.get("tosca.nodes."
"WebApplication.WordPress"))
def test_import_error_file_uri(self):
tpl_snippet = '''

View File

@ -165,11 +165,11 @@ def validate_timestamp(value):
class TOSCAVersionProperty(object):
VERSION_RE = re.compile('^(?P<major_version>([0-9][0-9]*))'
'(\.(?P<minor_version>([0-9][0-9]*)))?'
'(\.(?P<fix_version>([0-9][0-9]*)))?'
'(\.(?P<qualifier>([0-9A-Za-z]+)))?'
'(\-(?P<build_version>[0-9])*)?$')
VERSION_RE = re.compile(r'^(?P<major_version>([0-9][0-9]*))'
r'(\.(?P<minor_version>([0-9][0-9]*)))?'
r'(\.(?P<fix_version>([0-9][0-9]*)))?'
r'(\.(?P<qualifier>([0-9A-Za-z]+)))?'
r'(\-(?P<build_version>[0-9])*)?$')
def __init__(self, version):
self.version = str(version)

View File

@ -45,7 +45,7 @@ def load_yaml(path, a_file=True):
% {'path': path, 'code': e.code})
ExceptionCollector.appendException(URLException(what=msg))
return
except Exception as e:
except Exception:
raise
return yaml.load(f.read(), Loader=yaml_loader)

View File

@ -41,6 +41,10 @@ commands = oslo_debug_helper -t toscaparser/tests {posargs}
[flake8]
show-source = True
builtins = _
# Enable either of these:
# W503 line break before binary operator
# W504 line break after binary operator
ignore = W503,W504
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
[testenv:lower-constraints]