1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-06 20:17:15 +00:00

unit tests (modules): use f-strings (#10992)

* unit tests (modules): use f-strings

* Apply suggestions from code review
This commit is contained in:
Alexei Znamensky 2025-10-27 11:08:33 +13:00 committed by GitHub
parent f6781f654e
commit e177d1e61a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 140 additions and 159 deletions

View file

@ -18,7 +18,7 @@ class OneViewBaseTest(object):
@pytest.fixture(autouse=True)
def setUp(self, mock_ansible_module, mock_ov_client, request):
marker = request.node.get_marker('resource')
self.resource = getattr(mock_ov_client, "%s" % (marker.args))
self.resource = getattr(mock_ov_client, f"{marker.args}")
self.mock_ov_client = mock_ov_client
self.mock_ansible_module = mock_ansible_module
@ -27,7 +27,7 @@ class OneViewBaseTest(object):
resource_name = type(self).__name__.replace('Test', '')
resource_module_path_name = resource_name.replace('Module', '')
resource_module_path_name = re.findall('[A-Z][^A-Z]*', resource_module_path_name)
resource_module_path_name = 'oneview_' + str.join('_', resource_module_path_name).lower()
resource_module_path_name = f"oneview_{str.join('_', resource_module_path_name).lower()}"
ansible_collections = __import__('ansible_collections')
oneview_module = ansible_collections.community.general.plugins.modules
@ -40,7 +40,7 @@ class OneViewBaseTest(object):
EXAMPLES = yaml.safe_load(testing_module.EXAMPLES)
except yaml.scanner.ScannerError:
message = "Something went wrong while parsing yaml from {0}.EXAMPLES".format(self.testing_class.__module__)
message = f"Something went wrong while parsing yaml from {self.testing_class.__module__}.EXAMPLES"
raise Exception(message)
return testing_module
@ -114,7 +114,7 @@ class OneViewBaseTestCase(object):
self.mock_ov_client = self.mock_ov_client_from_json_file.return_value
# Define Ansible Module Mock
patcher_ansible = patch(ONEVIEW_MODULE_UTILS_PATH + '.AnsibleModule')
patcher_ansible = patch(f"{ONEVIEW_MODULE_UTILS_PATH}.AnsibleModule")
test_case.addCleanup(patcher_ansible.stop)
mock_ansible_module = patcher_ansible.start()
self.mock_ansible_module = Mock()
@ -142,7 +142,7 @@ class OneViewBaseTestCase(object):
self.EXAMPLES = yaml.safe_load(self.testing_module.EXAMPLES)
except yaml.scanner.ScannerError:
message = "Something went wrong while parsing yaml from {0}.EXAMPLES".format(self.testing_class.__module__)
message = f"Something went wrong while parsing yaml from {self.testing_class.__module__}.EXAMPLES"
raise Exception(message)