Files
horizon/openstack_dashboard/test/unit/utils/test_futurist_utils.py
Akihiro Motoki 56ae087995 Refactor futurist calls
After futurist calls were introduced, the code became difficult to
understand. For example, local variables are used something like global.
To keep the code easier to understand, the usage of local variables
should be more scoped.

This commit introduces a wrapper function for futurist.ThreadPoolExecutor
and converts inline functions into normal methods.
I believe it improves the code readability a lot.

Change-Id: Id5b7a06c50e397c8c27447322d7f64f2d65c06b6
2018-03-14 21:15:52 +02:00

61 lines
1.6 KiB
Python

# Licensed 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 unittest
from openstack_dashboard.utils import futurist_utils
class FuturistUtilsTests(unittest.TestCase):
def test_call_functions_parallel(self):
def func1():
return 10
def func2():
return 20
ret = futurist_utils.call_functions_parallel(func1, func2)
self.assertEqual(ret, (10, 20))
def test_call_functions_parallel_with_args(self):
def func1(a):
return a
def func2(a, b):
return a + b
def func3():
return 3
ret = futurist_utils.call_functions_parallel(
(func1, [5]),
(func2, [10, 20]),
func3)
self.assertEqual(ret, (5, 30, 3))
def test_call_functions_parallel_with_kwargs(self):
def func1(a):
return a
def func2(a, b):
return a + b
def func3():
return 3
ret = futurist_utils.call_functions_parallel(
(func1, [], {'a': 5}),
(func2, [], {'a': 10, 'b': 20}),
func3)
self.assertEqual(ret, (5, 30, 3))