[3/7] incubator-ariatosca git commit: ARIA-21 reorder repository sturcutre
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/653365da/tests/orchestrator/workflows/api/test_task_graph.py -- diff --git a/tests/orchestrator/workflows/api/test_task_graph.py b/tests/orchestrator/workflows/api/test_task_graph.py new file mode 100644 index 000..a569386 --- /dev/null +++ b/tests/orchestrator/workflows/api/test_task_graph.py @@ -0,0 +1,745 @@ +# 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.orchestrator.workflows.api import task_graph, task + + +class MockTask(task.BaseTask): +def __init__(self): +super(MockTask, self).__init__(ctx={}) + + +@pytest.fixture +def graph(): +return task_graph.TaskGraph(name='mock-graph') + + +class TestTaskGraphTasks(object): + +def test_add_task(self, graph): +task = MockTask() +add_result = graph.add_tasks(task) +assert add_result == [task] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_add_empty_group(self, graph): +result = graph.add_tasks([]) +assert result == [] + +def test_add_group(self, graph): +tasks = [MockTask(), MockTask(), MockTask()] +added_tasks = graph.add_tasks(*tasks) +assert added_tasks == tasks + +def test_add_partially_existing_group(self, graph): +task = MockTask() +graph.add_tasks(task) +tasks = [MockTask(), task, MockTask()] +added_tasks = graph.add_tasks(*tasks) +assert added_tasks == [tasks[0], tasks[2]] + +def test_add_recursively_group(self, graph): +recursive_group = [MockTask(), MockTask()] +tasks = [MockTask(), recursive_group, MockTask()] +added_tasks = graph.add_tasks(tasks) +assert added_tasks == [tasks[0], recursive_group[0], recursive_group[1], tasks[2]] + +def test_add_existing_task(self, graph): +task = MockTask() +graph.add_tasks(task) +# adding a task already in graph - should have no effect, and return False +add_result = graph.add_tasks(task) +assert add_result == [] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_remove_task(self, graph): +task = MockTask() +other_task = MockTask() +graph.add_tasks(task) +graph.add_tasks(other_task) +graph.remove_tasks(other_task) +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_remove_tasks_with_dependency(self, graph): +task = MockTask() +dependent_task = MockTask() +graph.add_tasks(task) +graph.add_tasks(dependent_task) +graph.add_dependency(dependent_task, task) +remove_result = graph.remove_tasks(dependent_task) +assert remove_result == [dependent_task] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task +# asserting no dependencies are left for the dependent task +assert len(list(graph.get_dependencies(task))) == 0 + +def test_remove_empty_group(self, graph): +result = graph.remove_tasks([]) +assert result == [] + +def test_remove_group(self, graph): +tasks = [MockTask(), MockTask(), MockTask()] +graph.add_tasks(*tasks) +removed_tasks = graph.remove_tasks(*tasks) +assert removed_tasks == tasks + +def test_remove_partially_existing_group(self, graph): +task = MockTask() +graph.add_tasks(task) +tasks = [MockTask(), task, MockTask()] +removed_tasks = graph.remove_tasks(*tasks) +assert removed_tasks == [task] + +def test_remove_recursively_group(self, graph): +recursive_group = [MockTask(), MockTask()] +tasks = [MockTask(), recursive_group, MockTask()] +graph.add_tasks(tasks) +removed_tasks = graph.remove_tasks(tasks) +assert removed_tasks == [tasks[0], recursive_group[0], recursive_group[1], tasks[2]] + +def test_remove_nonexistent_task(self, graph): +task = MockTask() +
[3/7] incubator-ariatosca git commit: ARIA-21 reorder repository sturcutre
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/653365da/tests/orchestrator/workflows/api/test_task_graph.py -- diff --git a/tests/orchestrator/workflows/api/test_task_graph.py b/tests/orchestrator/workflows/api/test_task_graph.py new file mode 100644 index 000..a569386 --- /dev/null +++ b/tests/orchestrator/workflows/api/test_task_graph.py @@ -0,0 +1,745 @@ +# 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.orchestrator.workflows.api import task_graph, task + + +class MockTask(task.BaseTask): +def __init__(self): +super(MockTask, self).__init__(ctx={}) + + +@pytest.fixture +def graph(): +return task_graph.TaskGraph(name='mock-graph') + + +class TestTaskGraphTasks(object): + +def test_add_task(self, graph): +task = MockTask() +add_result = graph.add_tasks(task) +assert add_result == [task] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_add_empty_group(self, graph): +result = graph.add_tasks([]) +assert result == [] + +def test_add_group(self, graph): +tasks = [MockTask(), MockTask(), MockTask()] +added_tasks = graph.add_tasks(*tasks) +assert added_tasks == tasks + +def test_add_partially_existing_group(self, graph): +task = MockTask() +graph.add_tasks(task) +tasks = [MockTask(), task, MockTask()] +added_tasks = graph.add_tasks(*tasks) +assert added_tasks == [tasks[0], tasks[2]] + +def test_add_recursively_group(self, graph): +recursive_group = [MockTask(), MockTask()] +tasks = [MockTask(), recursive_group, MockTask()] +added_tasks = graph.add_tasks(tasks) +assert added_tasks == [tasks[0], recursive_group[0], recursive_group[1], tasks[2]] + +def test_add_existing_task(self, graph): +task = MockTask() +graph.add_tasks(task) +# adding a task already in graph - should have no effect, and return False +add_result = graph.add_tasks(task) +assert add_result == [] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_remove_task(self, graph): +task = MockTask() +other_task = MockTask() +graph.add_tasks(task) +graph.add_tasks(other_task) +graph.remove_tasks(other_task) +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_remove_tasks_with_dependency(self, graph): +task = MockTask() +dependent_task = MockTask() +graph.add_tasks(task) +graph.add_tasks(dependent_task) +graph.add_dependency(dependent_task, task) +remove_result = graph.remove_tasks(dependent_task) +assert remove_result == [dependent_task] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task +# asserting no dependencies are left for the dependent task +assert len(list(graph.get_dependencies(task))) == 0 + +def test_remove_empty_group(self, graph): +result = graph.remove_tasks([]) +assert result == [] + +def test_remove_group(self, graph): +tasks = [MockTask(), MockTask(), MockTask()] +graph.add_tasks(*tasks) +removed_tasks = graph.remove_tasks(*tasks) +assert removed_tasks == tasks + +def test_remove_partially_existing_group(self, graph): +task = MockTask() +graph.add_tasks(task) +tasks = [MockTask(), task, MockTask()] +removed_tasks = graph.remove_tasks(*tasks) +assert removed_tasks == [task] + +def test_remove_recursively_group(self, graph): +recursive_group = [MockTask(), MockTask()] +tasks = [MockTask(), recursive_group, MockTask()] +graph.add_tasks(tasks) +removed_tasks = graph.remove_tasks(tasks) +assert removed_tasks == [tasks[0], recursive_group[0], recursive_group[1], tasks[2]] + +def test_remove_nonexistent_task(self, graph): +task = MockTask() +
[3/7] incubator-ariatosca git commit: Aria 21 reorder repository sturcutre
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/17510b02/tests/orchestrator/workflows/api/test_task_graph.py -- diff --git a/tests/orchestrator/workflows/api/test_task_graph.py b/tests/orchestrator/workflows/api/test_task_graph.py new file mode 100644 index 000..a569386 --- /dev/null +++ b/tests/orchestrator/workflows/api/test_task_graph.py @@ -0,0 +1,745 @@ +# 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.orchestrator.workflows.api import task_graph, task + + +class MockTask(task.BaseTask): +def __init__(self): +super(MockTask, self).__init__(ctx={}) + + +@pytest.fixture +def graph(): +return task_graph.TaskGraph(name='mock-graph') + + +class TestTaskGraphTasks(object): + +def test_add_task(self, graph): +task = MockTask() +add_result = graph.add_tasks(task) +assert add_result == [task] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_add_empty_group(self, graph): +result = graph.add_tasks([]) +assert result == [] + +def test_add_group(self, graph): +tasks = [MockTask(), MockTask(), MockTask()] +added_tasks = graph.add_tasks(*tasks) +assert added_tasks == tasks + +def test_add_partially_existing_group(self, graph): +task = MockTask() +graph.add_tasks(task) +tasks = [MockTask(), task, MockTask()] +added_tasks = graph.add_tasks(*tasks) +assert added_tasks == [tasks[0], tasks[2]] + +def test_add_recursively_group(self, graph): +recursive_group = [MockTask(), MockTask()] +tasks = [MockTask(), recursive_group, MockTask()] +added_tasks = graph.add_tasks(tasks) +assert added_tasks == [tasks[0], recursive_group[0], recursive_group[1], tasks[2]] + +def test_add_existing_task(self, graph): +task = MockTask() +graph.add_tasks(task) +# adding a task already in graph - should have no effect, and return False +add_result = graph.add_tasks(task) +assert add_result == [] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_remove_task(self, graph): +task = MockTask() +other_task = MockTask() +graph.add_tasks(task) +graph.add_tasks(other_task) +graph.remove_tasks(other_task) +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task + +def test_remove_tasks_with_dependency(self, graph): +task = MockTask() +dependent_task = MockTask() +graph.add_tasks(task) +graph.add_tasks(dependent_task) +graph.add_dependency(dependent_task, task) +remove_result = graph.remove_tasks(dependent_task) +assert remove_result == [dependent_task] +tasks = [t for t in graph.tasks] +assert len(tasks) == 1 +assert tasks[0] == task +# asserting no dependencies are left for the dependent task +assert len(list(graph.get_dependencies(task))) == 0 + +def test_remove_empty_group(self, graph): +result = graph.remove_tasks([]) +assert result == [] + +def test_remove_group(self, graph): +tasks = [MockTask(), MockTask(), MockTask()] +graph.add_tasks(*tasks) +removed_tasks = graph.remove_tasks(*tasks) +assert removed_tasks == tasks + +def test_remove_partially_existing_group(self, graph): +task = MockTask() +graph.add_tasks(task) +tasks = [MockTask(), task, MockTask()] +removed_tasks = graph.remove_tasks(*tasks) +assert removed_tasks == [task] + +def test_remove_recursively_group(self, graph): +recursive_group = [MockTask(), MockTask()] +tasks = [MockTask(), recursive_group, MockTask()] +graph.add_tasks(tasks) +removed_tasks = graph.remove_tasks(tasks) +assert removed_tasks == [tasks[0], recursive_group[0], recursive_group[1], tasks[2]] + +def test_remove_nonexistent_task(self, graph): +task = MockTask() +