diff --git a/SpchtDescriptorFormat.py b/SpchtDescriptorFormat.py index 62283f6..ecc12e7 100644 --- a/SpchtDescriptorFormat.py +++ b/SpchtDescriptorFormat.py @@ -347,21 +347,15 @@ def list_wrapper(some_element): """ I had the use case that i needed always a list of elements on a type i dont really care about as even when its just a list of one element. - :param some_element: any variable that will be wrapped in a list + :param some_element: any object that will be wrapped in a list :type some_element: any - :return: Will return the element wrapped in the list unless its already a list, its its something weird returns None - :rtype: list or None + :return: Will return the element wrapped in the list unless its already a list, its its something weird it gets wrapped in a list of one + :rtype: list """ if isinstance(some_element, list): return some_element - elif isinstance(some_element, str) or isinstance(some_element, int) or isinstance(some_element, float): - return [some_element] - elif isinstance(some_element, bool): - return [some_element] - elif isinstance(some_element, dict): - return [some_element] else: - return None + return [some_element] @staticmethod def all_variants(variant_matrix: list) -> list: diff --git a/tests/test_spcht.py b/tests/test_spcht.py new file mode 100644 index 0000000..cd8c42e --- /dev/null +++ b/tests/test_spcht.py @@ -0,0 +1,24 @@ +import unittest + +from SpchtDescriptorFormat import Spcht, SpchtIterator + + +class TestFunc(unittest.TestCase): + bird = Spcht() + + def test_listwrapper1(self): + self.assertEqual(self.bird.list_wrapper(["OneElementList"]), ["OneElementList"]) + + def test_listwrapper2(self): + self.assertEqual( self.bird.list_wrapper("OneElement"), ["OneElement"]) + + def test_listwrapper3(self): + self.assertEqual(self.bird.list_wrapper(["Element1", "Element2"]), ["Element1", "Element2"]) + + def test_listwrapper4(self): + self.assertEqual(self.bird.list_wrapper(None), [None]) + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file