33
44import codecs
55import os
6+ from typing import Iterator
7+
8+ import pytest
69
710from barcode import get_barcode
811from barcode import get_barcode_class
5053)
5154
5255
53- def test_generating_barcodes () -> None :
56+ @pytest .mark .parametrize (("codename" , "code" ), TESTCODES )
57+ def test_generating_barcodes (
58+ codename : str , code : str , gather_image_elements_into_html : list [str ]
59+ ) -> None :
5460 os .makedirs (TESTPATH , exist_ok = True )
5561
56- objects = []
62+ objects = gather_image_elements_into_html
5763
5864 def append (x , y ) -> None :
5965 objects .append (OBJECTS .format (filename = x , name = y ))
@@ -62,7 +68,7 @@ def append_img(x, y) -> None:
6268 objects .append (IMAGES .format (filename = x , name = y ))
6369
6470 options = {}
65- for codename , code in TESTCODES :
71+ if True :
6672 bcode = get_barcode (codename , code )
6773 if codename .startswith ("i" ):
6874 options ["center_text" ] = False
@@ -83,9 +89,16 @@ def append_img(x, y) -> None:
8389 append_img (os .path .basename (filename ), bcode .name )
8490 else :
8591 objects .append (NO_PIL )
92+
93+
94+ @pytest .fixture (scope = "module" )
95+ def gather_image_elements_into_html () -> Iterator [list [str ]]:
96+ image_elements : list [str ] = []
97+ yield image_elements
98+
8699 # Save htmlfile with all objects
87100 with codecs .open (HTMLFILE , "w" , encoding = "utf-8" ) as f :
88- obj = "\n " .join (objects )
101+ obj = "\n " .join (image_elements )
89102 f .write (HTML .format (version = version , body = obj ))
90103
91104 print (f"\n Now open { HTMLFILE } in your browser." )
0 commit comments