From e2082e8bd254c368a6ab63817f7b55ae17dd11ba Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 9 Mar 2022 17:23:08 +0100 Subject: [PATCH] Hello everyone, would like to join the party with a small proposal to simplify that method --- RFEM/initModel.py | 6 +---- UnitTests/test_initModel.py | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 UnitTests/test_initModel.py diff --git a/RFEM/initModel.py b/RFEM/initModel.py index 660a3177..ae769a88 100644 --- a/RFEM/initModel.py +++ b/RFEM/initModel.py @@ -187,11 +187,7 @@ def insertSpaces(lst: list): Add spaces between list of numbers. Returns list of values. ''' - strLst = '' - for i in lst: - strLst += str(i) + ' ' - # remove trailing space - return strLst[:-1] + return ' '.join(str(item) for item in lst) def Calculate_all(generateXmlSolverInput: bool = False): ''' diff --git a/UnitTests/test_initModel.py b/UnitTests/test_initModel.py new file mode 100644 index 00000000..a28bf0aa --- /dev/null +++ b/UnitTests/test_initModel.py @@ -0,0 +1,46 @@ +######################################################### +## This is the unit test template. +## All good practices and requirements related to unit tests +## will be recorded here. Feel free to add whatever you feel +## as important or new to unit tests and testing procedure. +######################################################### + +# Name of the test module/file starts with test_... +# Start the unit test by copying the content of this file +# to ensure that the latest requirements are met. + +# import only used modules +# avoid wild-card import (from RFEM.enums import *) if possible +import os +import sys +PROJECT_ROOT = os.path.abspath(os.path.join( + os.path.dirname(__file__), + os.pardir) +) +sys.path.append(PROJECT_ROOT) + +import pytest +from RFEM.initModel import insertSpaces +# Unused imports are displayed in dark green as one below. +from RFEM.enums import MemberType + +# When running tests individually the Model needs to be explicitly initialized. +# If all tests are executed together this expresion is False. +#if Model.clientModel is None: +# Model() + +# 'pytestmark' sets same parameters (in this case 'skipif') to all functions in the module or class at once. +#pytestmark = pytest.mark.skipif(CheckIfMethodOrTypeExists(Model... + +# Use 'skipif' if you wish to skip individual test function conditionally +#@pytest.mark.skipif(CheckIfMethodOrTypeExists(Model.clientModel,'set_model_settings_and_options', True), reason="set_model_settings_and_options not in RFEM yet") + +# Name of the test function starts with test_... +# If no specific need to atomize the testing procedure, pack as much funtionality as possible in one test function. +# Write sepatate test when used method/type is not in RFEM yet, to be able to skip it for example. +def test_insertSpaces(): + """ + Test conversion of list to string with spaces between items + """ + assert insertSpaces([1, 2, 3]) == "1 2 3" +