@@ -78,53 +78,35 @@ def test_all_slices():
7878 """
7979 test all possible slices except big number
8080 """
81- MODE = None # set to "build" to rebuild slice_res.py
82- ll = [0 , 1 , 2 , 3 ]
83- start = list (range (- 7 , 7 ))
84- end = list (range (- 7 , 7 ))
85- step = list (range (- 5 , 5 ))
86- step .pop (step .index (0 ))
87-
88- for i in [start , end , step ]:
89- i .append (None )
90-
91- def build ():
92- # loop used to build slices_res.py with cpython
93- with open ("slice_res.py" , "wt" ) as f :
94- for s in start :
95- for e in end :
96- for t in step :
97- f .write (str (ll [s :e :t ]) + "\n " )
98-
99- def run ():
100- # test utility
101- from slice_res import SLICES_RES
102-
103- count = 0
104- failures = []
105- for s in start :
106- for e in end :
107- for t in step :
108- lhs = ll [s :e :t ]
109- try :
110- assert lhs == SLICES_RES [count ]
111- except AssertionError :
112- failures .append (
113- "start: {} ,stop: {}, step {}. Expected: {}, found: {}" .format (
114- s , e , t , lhs , SLICES_RES [count ]
115- )
116- )
117- count += 1
11881
119- if failures :
120- for f in failures :
121- print (f )
122- print (len (failures ), "slices failed" )
82+ import resources
83+ from resources .cpython_generated_slices import SLICES_RES , START , END , STEP , LL
84+
85+ ll = LL
86+ start = START
87+ end = END
88+ step = STEP
89+
90+ count = 0
91+ failures = []
92+ for s in start :
93+ for e in end :
94+ for t in step :
95+ lhs = ll [s :e :t ]
96+ try :
97+ assert lhs == SLICES_RES [count ]
98+ except AssertionError :
99+ failures .append (
100+ "start: {} ,stop: {}, step {}. Expected: {}, found: {}" .format (
101+ s , e , t , lhs , SLICES_RES [count ]
102+ )
103+ )
104+ count += 1
123105
124- if MODE == "build" :
125- build ()
126- else :
127- run ( )
106+ if failures :
107+ for f in failures :
108+ print ( f )
109+ print ( len ( failures ), "slices failed" )
128110
129111
130112test_all_slices ()
0 commit comments