File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 1818 'IS' : int , # integer string
1919 }
2020
21+ MAX_CSA_ITEMS = 199
22+
2123
2224class CSAError (Exception ):
2325 pass
@@ -116,7 +118,9 @@ def read(csa_str):
116118 # CSA1 specific length modifier
117119 if tag_no == 1 :
118120 tag0_n_items = n_items
119- assert n_items < 200
121+ if n_items > MAX_CSA_ITEMS :
122+ raise CSAReadError ('Expected <= {0} tags, got {1}' .format (
123+ MAX_CSA_ITEMS , n_items ))
120124 items = []
121125 for item_no in range (n_items ):
122126 x0 ,x1 ,x2 ,x3 = up_str .unpack ('4i' )
Original file line number Diff line number Diff line change @@ -68,9 +68,19 @@ def test_csa_len0():
6868
6969
7070def test_csa_nitem ():
71- # testing csa.read's ability to raise an error when n_items >200
72- assert_raises (AssertionError , csa .read , CSA_STR_200n_items )
73- assert csa .read (CSA_STR_valid )
71+ # testing csa.read's ability to raise an error when n_items >= 200
72+ assert_raises (csa .CSAReadError , csa .read , CSA_STR_200n_items )
73+ # OK when < 200
74+ csa_info = csa .read (CSA_STR_valid )
75+ assert_equal (len (csa_info ['tags' ]), 1 )
76+ # OK after changing module global
77+ n_items_thresh = csa .MAX_CSA_ITEMS
78+ try :
79+ csa .MAX_CSA_ITEMS = 1000
80+ csa_info = csa .read (CSA_STR_200n_items )
81+ assert_equal (len (csa_info ['tags' ]), 1 )
82+ finally :
83+ csa .MAX_CSA_ITEMS = n_items_thresh
7484
7585
7686def test_csa_params ():
You can’t perform that action at this time.
0 commit comments