Skip to content

Commit

Permalink
added some rudimentary tests, streamlined Spcht.make_list() a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkanter committed May 7, 2021
1 parent 8288c20 commit ed99a30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
14 changes: 4 additions & 10 deletions SpchtDescriptorFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_spcht.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit ed99a30

Please sign in to comment.