nit: fix loading tosca classes including ., p, y

When loading tosca clsses, '.', 'p' and 'y' are splited so files
including these charactors in its basename are failed to load. This
patch fixes it by removing only file extension.

Change-Id: I6ad8a32982aec67f8d8aecaafcbaec803d4c7a02
This commit is contained in:
Hiroyuki JO 2019-07-25 19:16:57 +09:00 committed by Hiroo Kitamura
parent 146fb828ef
commit 9d5056a9d7
3 changed files with 48 additions and 7 deletions

View File

@ -91,7 +91,7 @@ def _load_classes(locations, classes):
if f == 'tosca_block_storage_attachment.py':
continue
mod_name = cls_path + '/' + f.strip('.py')
mod_name = cls_path + '/' + os.path.splitext(f)[0]
mod_name = mod_name.replace('/', '.')
try:
mod = importlib.import_module(mod_name)

View File

@ -42,16 +42,16 @@ class ConfTest(TestCase):
translatorConfig._load_config('fake_file.conf')
self.assertTrue(translatorConfig._translator_config.read.called)
def test_get_value(self):
ret_value = mock.MagicMock(return_value='hot')
translatorConfig._translator_config.get = ret_value
@mock.patch.object(translatorConfig._translator_config, 'get')
def test_get_value(self, mock_translator_config):
mock_translator_config.return_value = 'hot'
value = translatorConfig.get_value('DEFAULT', 'language')
self.assertTrue(translatorConfig._translator_config.get.called)
self.assertEqual(value, 'hot')
def test_get_all_values(self):
ret_value = mock.MagicMock(return_value=['hot'])
translatorConfig._translator_config.items = ret_value
@mock.patch.object(translatorConfig._translator_config, 'items')
def test_get_all_values(self, mock_translator_config):
mock_translator_config.return_value = ['hot']
values = translatorConfig.get_all_values()
self.assertTrue(translatorConfig._translator_config.items.called)
self.assertEqual(values[0], 'hot')

View File

@ -0,0 +1,41 @@
# 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.
from translator.hot.translate_node_templates import _generate_type_map
from translator.tests.base import TestCase
class TranslateNodeTemplatesTest(TestCase):
def test_generate_type_map(self):
expected_type_list = [
'tosca.nodes.BlockStorage',
'tosca.nodes.Compute',
'tosca.nodes.DBMS',
'tosca.nodes.Database',
'tosca.nodes.ObjectStorage',
'tosca.nodes.SoftwareComponent',
'tosca.nodes.WebApplication',
'tosca.nodes.WebServer',
'tosca.nodes.network.FloatingIP',
'tosca.nodes.network.Network',
'tosca.nodes.network.Port',
'tosca.policies.Monitoring',
'tosca.policies.Placement',
'tosca.policies.Reservation',
'tosca.policies.Scaling',
'tosca.policies.Scaling.Cluster'
]
actual_type_list = list(_generate_type_map())
self.assertItemsEqual(expected_type_list, actual_type_list)