@@ -27,18 +27,31 @@ def setup_reader():
2727 test_reader = zxing .BarCodeReader ()
2828
2929@with_setup (setup_reader )
30- def test_decoding ( ):
30+ def _check_decoding ( filename , expected_format , expected_raw , extra = {} ):
3131 global test_reader
32- for filename , expected_format , expected_raw in test_barcodes :
33- path = os .path .join (test_barcode_dir , filename )
34- logging .debug ('Trying to parse {}, expecting {!r}.' .format (path , expected_raw ))
35- dec = test_reader .decode (path , pure_barcode = True )
32+ path = os .path .join (test_barcode_dir , filename )
33+ logging .debug ('Trying to parse {}, expecting {!r}.' .format (path , expected_raw ))
34+ dec = test_reader .decode (path , pure_barcode = True , ** extra )
35+ if expected_raw is None :
36+ if dec is not None :
37+ raise AssertionError ('Expected failure, but got result in {} format' .format (expected_format , dec .format ))
38+ else :
3639 if dec .raw != expected_raw :
3740 raise AssertionError ('Expected {!r} but got {!r}' .format (expected_raw , dec .raw ))
3841 if dec .format != expected_format :
3942 raise AssertionError ('Expected {!r} but got {!r}' .format (expected_format , dec .format ))
4043
4144
45+ def test_decoding ():
46+ global test_reader
47+ yield from ((_check_decoding , filename , expected_format , expected_raw ) for filename , expected_format , expected_raw in test_barcodes )
48+
49+
50+ def test_possible_formats ():
51+ yield from ((_check_decoding , filename , expected_format , expected_raw , dict (possible_formats = ('CODE_93' , expected_format , 'DATA_MATRIX' )))
52+ for filename , expected_format , expected_raw in test_barcodes )
53+
54+
4255@with_setup (setup_reader )
4356def test_decoding_multiple ():
4457 reader = zxing .BarCodeReader ()
@@ -72,17 +85,10 @@ def test_parsing():
7285 assert dec .points == [(24.0 ,18.0 ),(21.0 ,196.0 ),(201.0 ,198.0 ),(205.23952 ,21.0 )]
7386
7487
75- @with_setup (setup_reader )
76- def test_possible_formats ():
77- global test_reader
88+ def test_wrong_formats ():
7889 all_test_formats = {fmt for fn ,fmt ,raw in test_barcodes }
79- for filename , expected_format , expected_raw in test_barcodes :
80- path = os .path .join (test_barcode_dir , filename )
81- incomplete_formats = all_test_formats - {expected_format }
82- dec = test_reader .decode (path , possible_formats = incomplete_formats , pure_barcode = True )
83- if dec is not None :
84- raise AssertionError ('Tried to decode {}-format barcode with possible_formats={!r}; expected failure, but got result in {} format' .format (
85- expected_format , incomplete_formats , dec .format ))
90+ yield from ((_check_decoding , filename , expected_format , None , dict (possible_formats = all_test_formats - {expected_format }))
91+ for filename , expected_format , expected_raw in test_barcodes )
8692
8793
8894@raises (zxing .BarCodeReaderException )
0 commit comments