Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-1-parser-test-suite 29a934d7e -> a508f463f (forced update)
Use YAML C library Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/a508f463 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/a508f463 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/a508f463 Branch: refs/heads/ARIA-1-parser-test-suite Commit: a508f463fcf1b0f3d34d015a85e8b43f12e8ad67 Parents: f29cc2f Author: Tal Liron <[email protected]> Authored: Thu Aug 31 18:20:03 2017 -0500 Committer: Tal Liron <[email protected]> Committed: Fri Sep 8 13:00:59 2017 -0500 ---------------------------------------------------------------------- .travis.yml | 66 +++-- appveyor.yml | 3 +- aria/parser/reading/yaml.py | 6 +- .../aria_extension_tosca/simple_v1_0/data.py | 16 +- .../templates/test_template_parameters.py | 275 ++++++++++++++----- .../simple_v1_0/templates/test_templates.py | 33 +-- tox.ini | 26 +- 7 files changed, 295 insertions(+), 130 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a508f463/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml index 37f63a8..c6a7b53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,41 +10,57 @@ # See the License for the specific language governing permissions and # limitations under the License. -sudo: false +# We need to set "sudo: true" in order to use a virtual machine instead of a container, because +# SSH tests fail in the container. See: +# https://docs.travis-ci.com/user/reference/overview/#Virtualization-environments -# TODO: The default dist is "trusty", but it is broken for us because it doesn't have Python 2.6, -# and does not allow SSH access (for py2?ssh tests) -dist: precise +dist: trusty +sudo: true language: python +addons: + apt: + sources: + - sourceline: 'ppa:fkrull/deadsnakes' + packages: + # Ubuntu 14.04 (trusty) does not come with Python 2.6, so we will install it from Felix + # Krull's PPA + - python2.6 + - python2.6-dev + python: + # We handle Python 2.6 testing from within tox (see tox.ini); note that this means that we run + # tox itself always from Python 2.7 - '2.7' env: - - TOX_ENV=pylint_code - - TOX_ENV=pylint_tests - - TOX_ENV=py27 - - TOX_ENV=py26 - - TOX_ENV=py27e2e - - TOX_ENV=py26e2e - - TOX_ENV=py27extensions - - TOX_ENV=py26extensions - - TOX_ENV=py27ssh - - TOX_ENV=py26ssh - - TOX_ENV=docs - -install: + # The PYTEST_PROCESSES environment var is used in tox.ini to override the --numprocesses argument + # for PyTest's xdist plugin. The reason this is necessary is that conventional Travis environments + # may report a large amount of available CPUs, but they they are greatly restricted. Through trial + # and error we found that more than 1 process may result in failures. + - PYTEST_PROCESSES=1 TOX_ENV=py27 + - PYTEST_PROCESSES=1 TOX_ENV=py26 + - PYTEST_PROCESSES=1 TOX_ENV=py27e2e + - PYTEST_PROCESSES=1 TOX_ENV=py26e2e + - PYTEST_PROCESSES=1 TOX_ENV=py27extensions + - PYTEST_PROCESSES=1 TOX_ENV=py26extensions + - PYTEST_PROCESSES=1 TOX_ENV=py27ssh + - PYTEST_PROCESSES=1 TOX_ENV=py26ssh + - PYTEST_PROCESSES=1 TOX_ENV=pylint_code + - PYTEST_PROCESSES=1 TOX_ENV=pylint_tests + - PYTEST_PROCESSES=1 TOX_ENV=docs + +before_install: + # Create SSH keys for SSH tests + - ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N '' + - cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys + + # Python dependencies - pip install --upgrade pip - pip install --upgrade setuptools - pip install tox - -script: - - pip --version - tox --version - - PYTEST_PROCESSES=1 tox -e $TOX_ENV -# The PYTEST_PROCESSES environment var is used in tox.ini to override the --numprocesses argument -# for PyTest's xdist plugin. The reason this is necessary is that conventional Travis environments -# may report a large amount of available CPUs, but they they are greatly restricted. Through trial -# and error we found that more than 1 process may result in failures. +script: + - tox -e $TOX_ENV http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a508f463/appveyor.yml ---------------------------------------------------------------------- diff --git a/appveyor.yml b/appveyor.yml index a03b180..89e735a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,8 +34,7 @@ before_test: - virtualenv env - 'env\Scripts\activate.bat' - pip install tox + - tox --version test_script: - - pip --version - - tox --version - tox -e %TOX_ENV% http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a508f463/aria/parser/reading/yaml.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/yaml.py b/aria/parser/reading/yaml.py index f5eac43..0148d3a 100644 --- a/aria/parser/reading/yaml.py +++ b/aria/parser/reading/yaml.py @@ -82,7 +82,11 @@ class YamlReader(Reader): # see issue here: # https://bitbucket.org/ruamel/yaml/issues/61/roundtriploader-causes-exceptions-with #yaml_loader = yaml.RoundTripLoader(data) - yaml_loader = yaml.SafeLoader(data) + try: + # Faster C-based loader, might not be available on all platforms + yaml_loader = yaml.CSafeLoader(data) + except BaseException: + yaml_loader = yaml.SafeLoader(data) try: node = yaml_loader.get_single_node() locator = YamlLocator(self.loader.location, 0, 0) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a508f463/tests/extensions/aria_extension_tosca/simple_v1_0/data.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/data.py b/tests/extensions/aria_extension_tosca/simple_v1_0/data.py index d428668..7310ed9 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/data.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/data.py @@ -30,13 +30,19 @@ TYPE_NAME_PLURAL = { 'policy': 'policies' } PRIMITIVE_TYPE_NAMES = ('string', 'integer', 'float', 'boolean') +PARAMETER_SECTION_NAMES = ('properties', 'attributes') TEMPLATE_NAMES = ('node', 'group', 'policy') -TEMPLATE_NAME_SECTION = { +TEMPLATE_NAME_SECTIONS = { 'node': 'node_templates', 'group': 'groups', 'policy': 'policies' } -PARAMETER_SECTION_NAMES = ('properties', 'attributes') +TEMPLATE_PARAMETER_SECTIONS = ( + ('node', 'properties'), + ('node', 'attributes'), + ('group', 'properties'), + ('policy', 'properties') +) PARAMETER_SECTIONS = ( ('artifact', 'properties'), ('data', 'properties'), @@ -83,10 +89,12 @@ STATUSES = ('supported', 'unsupported', 'experimental', 'deprecated') ENTRY_SCHEMA_VALUES = ( ('string', 'a string', 'another string'), ('integer', '1', '2'), - ('float', '1.1', '2.2') + ('float', '1.1', '2.2'), + ('MyType', '{my_field: a string}', '{}') ) ENTRY_SCHEMA_VALUES_BAD = ( ('string', 'a string', '1'), ('integer', '1', 'a string'), - ('float', '1.1', 'a string') + ('float', '1.1', 'a string'), + ('MyType', '{my_field1: a string}', 'a string') ) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a508f463/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py index 67731b3..48087d0 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_template_parameters.py @@ -21,149 +21,296 @@ import pytest from .. import data +# Required properties + [email protected](reason='fixed in ARIA-351') [email protected]('name', data.TEMPLATE_NAMES) +def test_template_property_required(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + properties: + my_property: + type: string +topology_template: + {{ section }}: + my_template: + type: MyType +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() + + [email protected]('name', data.TEMPLATE_NAMES) +def test_template_property_not_required(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + properties: + my_property: + type: string + required: false +topology_template: + {{ section }}: + my_template: + type: MyType +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + [email protected]('name', data.TEMPLATE_NAMES) +def test_template_property_required_with_default(parser, name): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +{{ name }}_types: + MyType: + properties: + my_property: + type: string + default: a string +topology_template: + {{ section }}: + my_template: + type: MyType +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() + + # Entry schema [email protected]('section,values', itertools.product( - data.PARAMETER_SECTION_NAMES, - data.ENTRY_SCHEMA_VALUES -)) -def test_node_type_parameter_map(parser, section, values): [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES)) +) +def test_template_parameter_map(parser, name, parameter_section, values): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -node_types: +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: MyType: - {{ section }}: + {{ parameter_section }}: my_parameter: type: map entry_schema: {{ values[0] }} topology_template: - node_templates: + {{ section }}: my_template: type: MyType - {{ section }}: + {{ parameter_section }}: my_parameter: key1: {{ values[1] }} key2: {{ values[2] }} -""", dict(section=section, values=values)).assert_success() +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_success() [email protected]('section,values', itertools.product( - data.PARAMETER_SECTION_NAMES, - data.ENTRY_SCHEMA_VALUES_BAD -)) -def test_node_type_parameter_map_bad(parser, section, values): [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES_BAD)) +) +def test_template_parameter_map_bad(parser, name, parameter_section, values): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -node_types: +data_types: MyType: - {{ section }}: + properties: + my_field: + type: string + default: default value +{{ name }}_types: + MyType: + {{ parameter_section }}: my_parameter: type: map entry_schema: {{ values[0] }} topology_template: - node_templates: + {{ section }}: my_template: type: MyType - {{ section }}: + {{ parameter_section }}: my_parameter: key1: {{ values[1] }} key2: {{ values[2] }} -""", dict(section=section, values=values)).assert_failure() +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_failure() + + [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_map_required_field(parser, name, parameter_section): + parser.parse_literal(""" +tosca_definitions_version: tosca_simple_yaml_1_0 +data_types: + MyType: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: map + entry_schema: MyType +topology_template: + {{ section }}: + my_template: + type: MyType + {{ parameter_section }}: + my_parameter: + key: {my_field: a value} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_success() [email protected]('section,values', itertools.product( - data.PARAMETER_SECTION_NAMES, - data.ENTRY_SCHEMA_VALUES -)) -def test_node_type_parameter_list(parser, section, values): [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_map_required_field_bad(parser, name, parameter_section): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -node_types: +data_types: MyType: - {{ section }}: + properties: + my_field: + type: string +{{ name }}_types: + MyType: + {{ parameter_section }}: my_parameter: - type: list - entry_schema: {{ values[0] }} + type: map + entry_schema: MyType topology_template: - node_templates: + {{ section }}: my_template: type: MyType - {{ section }}: + {{ parameter_section }}: my_parameter: - - {{ values[1] }} - - {{ values[2] }} -""", dict(section=section, values=values)).assert_success() + key: {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_failure() [email protected]('section,values', itertools.product( - data.PARAMETER_SECTION_NAMES, - data.ENTRY_SCHEMA_VALUES_BAD -)) -def test_node_type_parameter_list_bad(parser, section, values): [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES)) +) +def test_template_parameter_list(parser, name, parameter_section, values): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -node_types: +data_types: + MyType: + properties: + my_field: + type: string + default: default value +{{ name }}_types: MyType: - {{ section }}: + {{ parameter_section }}: my_parameter: type: list entry_schema: {{ values[0] }} topology_template: - node_templates: + {{ section }}: my_template: type: MyType - {{ section }}: + {{ parameter_section }}: my_parameter: - {{ values[1] }} - {{ values[2] }} -""", dict(section=section, values=values)).assert_failure() +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_success() -# Required - [email protected](reason='fixed in ARIA-351') -def test_node_type_property_required(parser): [email protected]( + 'name,parameter_section,values', + ((s[0], s[1], v) + for s, v in itertools.product( + data.TEMPLATE_PARAMETER_SECTIONS, + data.ENTRY_SCHEMA_VALUES_BAD)) +) +def test_template_parameter_list_bad(parser, name, parameter_section, values): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -node_types: +data_types: MyType: properties: - my_property: + my_field: type: string + default: default value +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: list + entry_schema: {{ values[0] }} topology_template: - node_templates: + {{ section }}: my_template: type: MyType -""").assert_failure() + {{ parameter_section }}: + my_parameter: + - {{ values[1] }} + - {{ values[2] }} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], parameter_section=parameter_section, + values=values)).assert_failure() -def test_node_type_property_not_required(parser): [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_list_required_field(parser, name, parameter_section): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -node_types: +data_types: MyType: properties: - my_property: + my_field: type: string - required: false +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: list + entry_schema: MyType topology_template: - node_templates: + {{ section }}: my_template: type: MyType -""").assert_success() + {{ parameter_section }}: + my_parameter: + - {my_field: a value} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_success() -def test_node_type_property_required_with_default(parser): [email protected]('name,parameter_section', data.TEMPLATE_PARAMETER_SECTIONS) +def test_template_parameter_list_required_field_bad(parser, name, parameter_section): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -node_types: +data_types: MyType: properties: - my_property: + my_field: type: string - default: a string +{{ name }}_types: + MyType: + {{ parameter_section }}: + my_parameter: + type: list + entry_schema: MyType topology_template: - node_templates: + {{ section }}: my_template: type: MyType -""").assert_success() + {{ parameter_section }}: + my_parameter: + - {} +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name], + parameter_section=parameter_section)).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a508f463/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py ---------------------------------------------------------------------- diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py index 98f06ca..bcd232a 100644 --- a/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py +++ b/tests/extensions/aria_extension_tosca/simple_v1_0/templates/test_templates.py @@ -31,7 +31,7 @@ topology_template: {{ value }} """, dict(value=value)).assert_failure() -def test_topology_template_emtpy(parser): +def test_topology_template_empty(parser): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 topology_template: {} @@ -47,7 +47,7 @@ def test_template_section_wrong_yaml_type(parser, name, value): tosca_definitions_version: tosca_simple_yaml_1_0 topology_template: {{ section }}: {{ value }} -""", dict(section=data.TEMPLATE_NAME_SECTION[name], value=value)).assert_failure() +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() @pytest.mark.parametrize('name,value', itertools.product( @@ -61,7 +61,7 @@ topology_template: {{ section }}: my_template: type: {{ value }} -""", dict(section=data.TEMPLATE_NAME_SECTION[name], value=value)).assert_failure() +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name], value=value)).assert_failure() # Common fields @@ -70,32 +70,18 @@ topology_template: def test_template_fields(parser, name): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 -topology_template: - {{ section }}: - my_template: - type: tosca.{{ plural }}.Root - description: a description -""", dict(section=data.TEMPLATE_NAME_SECTION[name], - plural=data.TYPE_NAME_PLURAL[name])).assert_success() - - -# Of types - [email protected]('name', data.TEMPLATE_NAMES) -def test_template_of_type(parser, name): - parser.parse_literal(""" -tosca_definitions_version: tosca_simple_yaml_1_0 {{ name }}_types: MyType: {} topology_template: {{ section }}: my_template: type: MyType -""", dict(name=name, section=data.TEMPLATE_NAME_SECTION[name])).assert_success() + description: a description +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() @pytest.mark.parametrize('name', data.TEMPLATE_NAMES) -def test_template_of_type_unicode(parser, name): +def test_template_fields_unicode(parser, name): parser.parse_literal(""" tosca_definitions_version: tosca_simple_yaml_1_0 {{ name }}_types: @@ -104,7 +90,8 @@ topology_template: {{ section }}: 模æ¿: type: é¡å -""", dict(name=name, section=data.TEMPLATE_NAME_SECTION[name])).assert_success() + description: æè¿° +""", dict(name=name, section=data.TEMPLATE_NAME_SECTIONS[name])).assert_success() @pytest.mark.parametrize('name', data.TEMPLATE_NAMES) @@ -115,7 +102,7 @@ topology_template: {{ section }}: my_template: type: UnknownType -""", dict(section=data.TEMPLATE_NAME_SECTION[name])).assert_failure() +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() @pytest.mark.parametrize('name', data.TEMPLATE_NAMES) @@ -126,4 +113,4 @@ topology_template: {{ section }}: my_template: type: null -""", dict(section=data.TEMPLATE_NAME_SECTION[name])).assert_failure() +""", dict(section=data.TEMPLATE_NAME_SECTIONS[name])).assert_failure() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a508f463/tox.ini ---------------------------------------------------------------------- diff --git a/tox.ini b/tox.ini index 1adb4ce..b4abc06 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,8 @@ [tox] envlist=py27,py26,py27e2e,py26e2e,py27extensions,py26extensions,py27ssh,py26ssh,pywin,pylint_code,pylint_tests,docs processes={env:PYTEST_PROCESSES:auto} +py26={env:PY26:python2.6} +py27={env:PY27:python2.7} [testenv] whitelist_externals= @@ -28,18 +30,18 @@ deps= --requirement tests/requirements.txt basepython= - py27: python2.7 - py26: python2.6 - py27e2e: python2.7 - py26e2e: python2.6 - py27extensions: python2.7 - py26extensions: python2.6 - py27ssh: python2.7 - py26ssh: python2.6 + py27: {[tox]py27} + py26: {[tox]py26} + py27e2e: {[tox]py27} + py26e2e: {[tox]py26} + py27extensions: {[tox]py27} + py26extensions: {[tox]py26} + py27ssh: {[tox]py27} + py26ssh: {[tox]py26} pywin: {env:PYTHON:}\python.exe - pylint_code: python2.7 - pylint_tests: python2.7 - docs: python2.7 + pylint_code: {[tox]py27} + pylint_tests: {[tox]py27} + docs: {[tox]py27} [testenv:py27] commands= @@ -116,12 +118,14 @@ commands= [testenv:pylint_code] commands= pylint aria extensions/aria_extension_tosca \ + -j 0 \ --rcfile=aria/.pylintrc \ --disable=fixme,missing-docstring [testenv:pylint_tests] commands= pylint tests \ + -j 0 \ --rcfile=tests/.pylintrc \ --disable=fixme,missing-docstring
