1212
1313# ## Python StdLib Imports ----
1414import logging
15- from typing import Union
15+ from typing import Generator , Literal , Union
1616from unittest import TestCase
1717
1818# ## Python Third Party Imports ----
1919import pytest
2020import requests
21+ from parameterized import parameterized
2122from typeguard import TypeCheckError
2223
2324# ## Local First Party Imports ----
24- from toolbox_python .collection_types import str_list
25+ from toolbox_python .collection_types import str_list , str_set , str_tuple
2526from toolbox_python .output import list_columns , print_or_log_output
2627
2728
@@ -188,12 +189,11 @@ def get_list_of_words(num_words: int = 100) -> str_list:
188189 words : str_list = response .content .decode ().splitlines ()
189190 return words [:num_words ]
190191
191- def test_1 (self ) -> None :
192+ def test_1_defaults (self ) -> None :
192193 output : Union [str , None ] = list_columns (
193194 self .get_list_of_words (4 * 5 ),
194195 print_output = False ,
195196 )
196-
197197 expected : str = "\n " .join (
198198 [
199199 "a abandoned able abraham " ,
@@ -205,15 +205,15 @@ def test_1(self) -> None:
205205 )
206206 assert output == expected
207207
208- def test_2 (self ) -> None :
208+ def test_2_no_printing (self ) -> None :
209209 output : Union [str , None ] = list_columns (
210210 self .get_list_of_words (3 ),
211211 print_output = False ,
212212 )
213213 expected = """a aa aaa """
214214 assert output == expected
215215
216- def test_3 (self ) -> None :
216+ def test_3_columnwise (self ) -> None :
217217 output : Union [str , None ] = list_columns (
218218 self .get_list_of_words (5 ),
219219 cols_wide = 2 ,
@@ -229,18 +229,60 @@ def test_3(self) -> None:
229229 )
230230 assert output == expected
231231
232- def test_4 (self ) -> None :
232+ def test_4_print_output (self ) -> None :
233233 list_columns (
234- self .get_list_of_words (4 * 3 ),
235- columnwise = False ,
236- cols_wide = 4 ,
234+ self .get_list_of_words (4 * 5 ),
237235 print_output = True ,
238236 )
239237 output : str_list = self .capsys .readouterr ().out .split ("\n " )
240238 expected : str_list = [
241- "a aa aaa aaron " ,
242- "ab abandoned abc aberdeen " ,
243- "abilities ability able aboriginal " ,
239+ "a abandoned able abraham " ,
240+ "aa abc aboriginal abroad " ,
241+ "aaa aberdeen abortion abs " ,
242+ "aaron abilities about absence " ,
243+ "ab ability above absent " ,
244244 "" ,
245245 ]
246246 assert output == expected
247+
248+ def test_5_rowwise (self ) -> None :
249+ output = list_columns (
250+ self .get_list_of_words (4 * 3 ),
251+ columnwise = False ,
252+ cols_wide = 4 ,
253+ print_output = False ,
254+ )
255+ expected : str = "\n " .join (
256+ [
257+ "a aa aaa aaron " ,
258+ "ab abandoned abc aberdeen " ,
259+ "abilities ability able aboriginal " ,
260+ ]
261+ )
262+ assert output == expected
263+
264+ @parameterized .expand ([("list" ), ("tuple" ), ("set" ), ("generator" )])
265+ def test_6_types (self , input_type : Literal ["list" , "tuple" , "set" , "generator" ]) -> None :
266+ words : str_list = self .get_list_of_words (4 * 3 )
267+ expected : str = "\n " .join (
268+ [
269+ "a aaron abc ability " ,
270+ "aa ab aberdeen able " ,
271+ "aaa abandoned abilities aboriginal " ,
272+ ]
273+ )
274+ if input_type == "list" :
275+ input_data : str_list = list (words )
276+ elif input_type == "tuple" :
277+ input_data : str_tuple = tuple (words )
278+ elif input_type == "set" :
279+ input_data : str_set = set (words )
280+ expected = "\n " .join (set (expected .splitlines ()))
281+ elif input_type == "generator" :
282+ input_data : Generator = (word for word in words )
283+ output : Union [str , None ] = list_columns (input_data )
284+ if input_type != "set" :
285+ assert output == expected
286+ else :
287+ for word in words :
288+ assert word in output
0 commit comments