summaryrefslogtreecommitdiffstats
path: root/azure/aria/aria-extension-cloudify/src/aria/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'azure/aria/aria-extension-cloudify/src/aria/tests/utils')
-rw-r--r--azure/aria/aria-extension-cloudify/src/aria/tests/utils/__init__.py14
-rw-r--r--azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_exceptions.py73
-rw-r--r--azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_plugin.py58
-rw-r--r--azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_threading.py33
-rw-r--r--azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_validation.py35
-rw-r--r--azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_versions.py85
6 files changed, 298 insertions, 0 deletions
diff --git a/azure/aria/aria-extension-cloudify/src/aria/tests/utils/__init__.py b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/__init__.py
new file mode 100644
index 0000000..ae1e83e
--- /dev/null
+++ b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/__init__.py
@@ -0,0 +1,14 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_exceptions.py b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_exceptions.py
new file mode 100644
index 0000000..5d030e2
--- /dev/null
+++ b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_exceptions.py
@@ -0,0 +1,73 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import jsonpickle
+
+from aria.utils import exceptions
+
+_ARG1 = 'arg-1'
+_ARG2 = 'arg-2'
+
+
+class TestWrapIfNeeded(object):
+
+ def test_no_wrapping_required1(self):
+ e = JsonPickleableException1(_ARG1, _ARG2)
+ assert exceptions.wrap_if_needed(e) is e
+
+ def test_no_wrapping_required2(self):
+ e = JsonPickleableException1(arg1=_ARG1, arg2=_ARG2)
+ assert exceptions.wrap_if_needed(e) is e
+
+ def test_no_wrapping_required3(self):
+ e = JsonPickleableException2(arg1=_ARG1, arg2=_ARG2)
+ assert exceptions.wrap_if_needed(e) is e
+
+ def test_wrapping_required1(self):
+ e = NonJsonPickleableException(_ARG1, _ARG2)
+ wrapped_e = exceptions.wrap_if_needed(e)
+ wrapped_e = jsonpickle.loads(jsonpickle.dumps(wrapped_e))
+ assert isinstance(wrapped_e, exceptions._WrappedException)
+ assert wrapped_e.exception_type == type(e).__name__
+ assert wrapped_e.exception_str == str(e)
+
+ def test_wrapping_required2(self):
+ e = NonJsonPickleableException(arg1=_ARG1, arg2=_ARG2)
+ wrapped_e = exceptions.wrap_if_needed(e)
+ wrapped_e = jsonpickle.loads(jsonpickle.dumps(wrapped_e))
+ assert isinstance(wrapped_e, exceptions._WrappedException)
+ assert wrapped_e.exception_type == type(e).__name__
+ assert wrapped_e.exception_str == str(e)
+
+
+class JsonPickleableException1(Exception):
+ def __init__(self, arg1, arg2):
+ super(JsonPickleableException1, self).__init__(arg1, arg2)
+ self.arg1 = arg1
+ self.arg2 = arg2
+
+
+class JsonPickleableException2(Exception):
+ def __init__(self, arg1=None, arg2=None):
+ super(JsonPickleableException2, self).__init__()
+ self.arg1 = arg1
+ self.arg2 = arg2
+
+
+class NonJsonPickleableException(Exception):
+ def __init__(self, arg1, arg2):
+ super(NonJsonPickleableException, self).__init__()
+ self.arg1 = arg1
+ self.arg2 = arg2
diff --git a/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_plugin.py b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_plugin.py
new file mode 100644
index 0000000..c91d0c9
--- /dev/null
+++ b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_plugin.py
@@ -0,0 +1,58 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+
+import pytest
+
+from aria.orchestrator import exceptions
+from aria.utils.plugin import create as create_plugin
+
+from ..fixtures import ( # pylint: disable=unused-import
+ plugins_dir,
+ plugin_manager,
+ inmemory_model as model
+)
+
+
+PACKAGE_NAME = 'mock-plugin'
+PACKAGE_VERSION = '100'
+
+
+class TestPluginManager(object):
+
+ def test_install(self, plugin_manager, mock_plugin, model, plugins_dir):
+ plugin = plugin_manager.install(mock_plugin)
+ assert plugin.package_name == PACKAGE_NAME
+ assert plugin.package_version == PACKAGE_VERSION
+ assert plugin == model.plugin.get(plugin.id)
+ plugin_dir = os.path.join(plugins_dir, '{0}-{1}'.format(PACKAGE_NAME, PACKAGE_VERSION))
+ assert os.path.isdir(plugin_dir)
+ assert plugin_dir == plugin_manager.get_plugin_dir(plugin)
+
+ def test_install_already_exits(self, plugin_manager, mock_plugin):
+ plugin_manager.install(mock_plugin)
+ with pytest.raises(exceptions.PluginAlreadyExistsError):
+ plugin_manager.install(mock_plugin)
+
+
+@pytest.fixture
+def mock_plugin(tmpdir):
+ source_dir = tmpdir.join('mock_plugin')
+ source_dir.mkdir()
+ setup_py = source_dir.join('setup.py')
+ setup_py.write('from setuptools import setup; setup(name="{0}", version="{1}")'
+ .format(PACKAGE_NAME, PACKAGE_VERSION))
+ return create_plugin(source=str(source_dir), destination_dir=str(tmpdir))
diff --git a/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_threading.py b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_threading.py
new file mode 100644
index 0000000..d24661f
--- /dev/null
+++ b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_threading.py
@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import pytest
+
+from aria.utils import threading
+
+
+def test_exception_raised_from_thread():
+
+ def error_raising_func():
+ raise ValueError('This is an error')
+
+ thread = threading.ExceptionThread(target=error_raising_func)
+ thread.start()
+ thread.join()
+
+ assert thread.is_error()
+ with pytest.raises(ValueError):
+ thread.raise_error_if_exists()
diff --git a/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_validation.py b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_validation.py
new file mode 100644
index 0000000..8e35f22
--- /dev/null
+++ b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_validation.py
@@ -0,0 +1,35 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+
+from aria.utils import validation
+
+
+def test_function_kwargs_validation():
+
+ def mock_function(arg1, arg2=1, arg3=1):
+ pass
+
+ with pytest.raises(ValueError):
+ validation.validate_function_arguments(mock_function, dict(arg2=1))
+ with pytest.raises(ValueError):
+ validation.validate_function_arguments(mock_function, dict(arg3=3))
+ with pytest.raises(ValueError):
+ validation.validate_function_arguments(mock_function, dict(arg2=2, arg3=3))
+
+ validation.validate_function_arguments(mock_function, dict(arg1=1, arg3=3))
+ validation.validate_function_arguments(mock_function, dict(arg1=1, arg2=2))
+ validation.validate_function_arguments(mock_function, dict(arg1=1, arg2=2, arg3=3))
diff --git a/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_versions.py b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_versions.py
new file mode 100644
index 0000000..222949c
--- /dev/null
+++ b/azure/aria/aria-extension-cloudify/src/aria/tests/utils/test_versions.py
@@ -0,0 +1,85 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from aria.utils.versions import (VersionString, parse_version_string)
+
+
+def test_version_string():
+ # No qualifiers
+ assert VersionString('20') == VersionString('20')
+ assert VersionString('20') == VersionString('20.0')
+ assert VersionString('20') == VersionString('20.0.0')
+ assert VersionString('20') < VersionString('20.0.1')
+
+ # With numeric qualifiers
+ assert VersionString('20.0.1-1') < VersionString('20.0.1-2')
+ assert VersionString('20.0.1-0') < VersionString('20.0.1')
+ assert VersionString('20.0.1-1') < VersionString('20.0.1')
+
+ # With prefixed qualifiers
+ assert VersionString('20.0.1-beta1') < VersionString('20.0.1-beta2')
+ assert VersionString('20.0.1-beta1') < VersionString('20.0.1-1')
+ assert VersionString('20.0.1-beta1') < VersionString('20.0.1')
+ assert VersionString('20.0.1-beta2') < VersionString('20.0.1-rc2')
+ assert VersionString('20.0.1-alpha2') < VersionString('20.0.1-beta1')
+ assert VersionString('20.0.1-dev2') < VersionString('20.0.1-alpha1')
+ assert VersionString('20.0.1-DEV2') < VersionString('20.0.1-ALPHA1')
+
+ # Coercive comparisons
+ assert VersionString('20.0.0') == VersionString(10 * 2)
+ assert VersionString('20.0.0') == VersionString(20.0)
+
+ # Non-VersionString comparisons
+ assert VersionString('20.0.0') == 20
+ assert VersionString('20.0.0') < '20.0.1'
+
+ # Nulls
+ assert VersionString() == VersionString()
+ assert VersionString() == VersionString.NULL
+ assert VersionString(None) == VersionString.NULL
+ assert VersionString.NULL == None # pylint: disable=singleton-comparison
+ assert VersionString.NULL == 0
+
+ # Invalid version strings
+ assert VersionString('maxim is maxim') == VersionString.NULL
+ assert VersionString('20.maxim.0') == VersionString.NULL
+ assert VersionString('20.0.0-maxim1') == VersionString.NULL
+ assert VersionString('20.0.1-1.1') == VersionString.NULL
+
+ # Sorts
+ v1 = VersionString('20.0.0')
+ v2 = VersionString('20.0.1-beta1')
+ v3 = VersionString('20.0.1')
+ v4 = VersionString('20.0.2')
+ assert [v1, v2, v3, v4] == sorted([v4, v3, v2, v1], key=lambda v: v.key)
+
+ # Sets
+ v1 = VersionString('20.0.0')
+ v2 = VersionString('20.0')
+ v3 = VersionString('20')
+ assert set([v1]) == set([v1, v2, v3])
+
+ # Dicts
+ the_dict = {v1: 'test'}
+ assert the_dict.get(v2) == 'test'
+
+def test_parse_version_string():
+ # One test of each type from the groups above should be enough
+ assert parse_version_string('20') < parse_version_string('20.0.1')
+ assert parse_version_string('20.0.1-1') < parse_version_string('20.0.1-2')
+ assert parse_version_string('20.0.1-beta1') < parse_version_string('20.0.1-beta2')
+ assert parse_version_string('20.0.0') == parse_version_string(10 * 2)
+ assert parse_version_string(None) == parse_version_string(0)
+ assert parse_version_string(None) == parse_version_string('maxim is maxim')