@@ -38,88 +38,88 @@ def tearDownClass(cls):
3838 del cls .console
3939 gc .collect () # make sure console.__del__ is called quickly
4040
41- def inWindow (self , x , y ):
41+ def in_window (self , x , y ):
4242 "returns True if this point is in the Window"
4343 return 0 <= x < WINWIDTH and 0 <= y < WINHEIGHT
4444
45- def randomizeConsole (self ):
45+ def randomize_console (self ):
4646 "Randomize the console returning the random data"
47- noise = [((x , y ), self .getRandomCharacter ()) for x ,y in self .getDrawables ()]
47+ noise = [((x , y ), self .get_random_character ()) for x ,y in self .get_drawables ()]
4848 for (x , y ), graphic in noise :
49- self .console .drawChar (x , y , * graphic )
49+ self .console .draw_char (x , y , * graphic )
5050 return noise # [((x, y), (cg, fg, bg)), ...]
5151
5252 def flush (self ):
5353 'Pump events and refresh screen so show progress'
5454 #tdl.event.get() # no longer needed
5555 tdl .flush ()
5656
57- def getRandomCharacter (self ):
57+ def get_random_character (self ):
5858 "returns a tuple with a random character and colors (ch, fg, bg)"
59- return (random .getrandbits (8 ), self .getRandomColor (), self .getRandomColor ())
59+ return (random .getrandbits (8 ), self .get_random_color (), self .get_random_color ())
6060
61- def getRandomColor (self ):
61+ def get_random_color (self ):
6262 "returns a single random color"
6363 return (random .getrandbits (8 ), random .getrandbits (8 ), random .getrandbits (8 ))
6464
65- def getDrawables (self , console = None ):
65+ def get_drawables (self , console = None ):
6666 """return a list of all drawable (x,y) positions
6767 defaults to self.console
6868 """
6969 if console is None :
7070 console = self .console
71- w , h = console .getSize ()
71+ w , h = console .get_size ()
7272 return itertools .product (range (w ), range (h ))
7373
74- def getUndrawables (self , console = None ):
74+ def get_undrawables (self , console = None ):
7575 """return a list of (x,y) positions that should raise errors when used
7676 positions are mostly random and will have at least one over the bounds of each side and each corner"""
7777 if console is None :
7878 console = self .console
79- w , h = console .getSize ()
79+ w , h = console .get_size ()
8080 for y in range (- 1 , h + 1 ):
8181 yield - w - 1 , y
8282 yield w , y
8383 for x in range (0 , w ):
8484 yield x , h
8585 yield x , - h - 1
8686
87- def compareConsoles (self , consoleA , consoleB , errorMsg = 'colors should be the same' ):
87+ def compare_consoles (self , consoleA , consoleB , errorMsg = 'colors should be the same' ):
8888 "Compare two console assuming they match and failing if they don't"
89- self .assertEqual (consoleA .getSize (), consoleB .getSize (), 'consoles should be the same size' )
90- for x , y in self .getDrawables (consoleA ):
91- self .assertEqual (consoleA .getChar (x , y ),
92- consoleB .getChar (x , y ), '%s, position: (%i, %i)' % (errorMsg , x , y ))
89+ self .assertEqual (consoleA .get_size (), consoleB .get_size (), 'consoles should be the same size' )
90+ for x , y in self .get_drawables (consoleA ):
91+ self .assertEqual (consoleA .get_char (x , y ),
92+ consoleB .get_char (x , y ), '%s, position: (%i, %i)' % (errorMsg , x , y ))
9393
9494class BasicTests (TDLTemplate ):
9595
9696 def test_clearConsole (self ):
97- self .randomizeConsole ()
98- _ , fg , bg = self .getRandomCharacter ()
97+ self .randomize_console ()
98+ _ , fg , bg = self .get_random_character ()
9999 ch = 0x20 # space
100100 self .console .clear (fg , bg )
101101 self .flush ()
102- for x ,y in self .getDrawables ():
103- self .assertEqual ((ch , fg , bg ), self .console .getChar (x , y ), 'color should be changed with clear' )
104- _ , fg2 , bg2 = self .getRandomCharacter ()
102+ for x ,y in self .get_drawables ():
103+ self .assertEqual ((ch , fg , bg ), self .console .get_char (x , y ), 'color should be changed with clear' )
104+ _ , fg2 , bg2 = self .get_random_character ()
105105 self .window .clear (fg2 , bg2 )
106106 self .flush ()
107- for x ,y in self .getDrawables ():
108- if self .inWindow (x , y ):
109- self .assertEqual ((ch , fg2 , bg2 ), self .console .getChar (x , y ), 'color in window should be changed' )
107+ for x ,y in self .get_drawables ():
108+ if self .in_window (x , y ):
109+ self .assertEqual ((ch , fg2 , bg2 ), self .console .get_char (x , y ), 'color in window should be changed' )
110110 else :
111- self .assertEqual ((ch , fg , bg ), self .console .getChar (x , y ), 'color outside of window should persist' )
111+ self .assertEqual ((ch , fg , bg ), self .console .get_char (x , y ), 'color outside of window should persist' )
112112
113113 def test_cloneConsole (self ):
114- noiseData = self .randomizeConsole ()
114+ noiseData = self .randomize_console ()
115115 clone = copy .copy (self .console )
116- self .compareConsoles (self .console , clone , 'console clone should match root console' )
116+ self .compare_consoles (self .console , clone , 'console clone should match root console' )
117117
118118 def test_pickleConsole (self ):
119- noiseData = self .randomizeConsole ()
119+ noiseData = self .randomize_console ()
120120 pickled = pickle .dumps (self .console )
121121 clone = pickle .loads (pickled )
122- self .compareConsoles (self .console , clone , 'pickled console should match root console' )
122+ self .compare_consoles (self .console , clone , 'pickled console should match root console' )
123123
124124 # This isn't really supported.
125125 #def test_changeFonts(self):
@@ -132,61 +132,61 @@ def test_pickleConsole(self):
132132 # tdl.setFont(font)
133133 # # only works at all in OPENGL
134134 # self.console = tdl.init(WIDTH, HEIGHT, title=font, renderer='OPENGL')
135- # for x,y in self.getDrawables ():
136- # self.console.draw_char(x, y, *self.getRandomCharacter ())
135+ # for x,y in self.get_drawables ():
136+ # self.console.draw_char(x, y, *self.get_random_character ())
137137 # self.flush()
138138 # time.sleep(.05)
139139
140140
141141class DrawingTests (TDLTemplate ):
142142
143- def test_drawCharTuples (self ):
144- "Test passing tuple colors and int characters to drawChar "
143+ def test_draw_charTuples (self ):
144+ "Test passing tuple colors and int characters to draw_char "
145145 record = {}
146- for x ,y in self .getDrawables ():
147- ch , fg , bg = self .getRandomCharacter ()
146+ for x ,y in self .get_drawables ():
147+ ch , fg , bg = self .get_random_character ()
148148 record [x ,y ] = (ch , fg , bg )
149- self .console .drawChar (x , y , ch , fg , bg )
150- self .assertEqual (record [x ,y ], self .console .getChar (x , y ), 'console data should be overwritten' )
149+ self .console .draw_char (x , y , ch , fg , bg )
150+ self .assertEqual (record [x ,y ], self .console .get_char (x , y ), 'console data should be overwritten' )
151151 self .flush () # show progress
152152
153153 for (x ,y ), data in record .items ():
154- self .assertEqual (data , self .console .getChar (x , y ), 'drawChar should not overwrite any other tiles' )
154+ self .assertEqual (data , self .console .get_char (x , y ), 'draw_char should not overwrite any other tiles' )
155155
156- def test_drawCharWebcolor (self ):
157- "Test passing web style colors and string characters to drawChar "
156+ def test_draw_charWebcolor (self ):
157+ "Test passing web style colors and string characters to draw_char "
158158 record = {}
159- for x ,y in self .getDrawables ():
160- ch , fg , bg = self .getRandomCharacter ()
159+ for x ,y in self .get_drawables ():
160+ ch , fg , bg = self .get_random_character ()
161161 record [x ,y ] = (ch , fg , bg )
162162 ch = chr (ch )
163163 fg = fg [0 ] << 16 | fg [1 ] << 8 | fg [2 ] # convert to a 0xRRGGBB style number
164164 bg = bg [0 ] << 16 | bg [1 ] << 8 | bg [2 ]
165- self .console .drawChar (x , y , ch , fg , bg )
166- self .assertEqual (record [x ,y ], self .console .getChar (x , y ), 'console data should be overwritten' )
165+ self .console .draw_char (x , y , ch , fg , bg )
166+ self .assertEqual (record [x ,y ], self .console .get_char (x , y ), 'console data should be overwritten' )
167167 self .flush () # show progress
168168 for (x ,y ), data in record .items ():
169- self .assertEqual (data , self .console .getChar (x , y ), 'drawChar should not overwrite any other tiles' )
169+ self .assertEqual (data , self .console .get_char (x , y ), 'draw_char should not overwrite any other tiles' )
170170
171171 #@unittest.skipIf(not __debug__, 'python run with optimized flag, skipping an AssertionError test')
172- #def test_drawCharErrors (self):
172+ #def test_draw_charErrors (self):
173173 # "test out of bounds assertion errors"
174- # for x,y in self.getUndrawables ():
174+ # for x,y in self.get_undrawables ():
175175 # with self.assertRaisesRegexp(AssertionError, r"\(%i, %i\)" % (x, y)):
176- # self.console.drawChar (x, y, *(self.getRandomCharacter ()))
176+ # self.console.draw_char (x, y, *(self.get_random_character ()))
177177
178- def test_drawStr (self ):
179- """quick regression test for drawStr """
180- width , height = self .console .getSize ()
178+ def test_draw_str (self ):
179+ """quick regression test for draw_str """
180+ width , height = self .console .get_size ()
181181 def str_check (array , string , desc ):
182- fg , bg = self .getRandomColor (), self .getRandomColor ()
182+ fg , bg = self .get_random_color (), self .get_random_color ()
183183 self .console .clear ()
184- self .console .drawStr (0 , 0 , string , fg , bg )
184+ self .console .draw_str (0 , 0 , string , fg , bg )
185185 self .flush ()
186186 i = 0
187187 for y in range (height ):
188188 for x in range (width ):
189- self .assertEqual (self .console .getChar (x , y ), (array [i ], fg , bg ),
189+ self .assertEqual (self .console .get_char (x , y ), (array [i ], fg , bg ),
190190 '%s should be written out' % desc )
191191 i += 1
192192
@@ -210,20 +210,20 @@ def str_check(array, string, desc):
210210 str_check (array , unicode , 'Unicode string' )
211211
212212
213- def test_drawStrArray (self ):
213+ def test_draw_strArray (self ):
214214 """strings will raise errors if they pass over the end of the console.
215215 The data will still be written however."""
216- width , height = self .console .getSize ()
217- for x ,y in self .getDrawables ():
216+ width , height = self .console .get_size ()
217+ for x ,y in self .get_drawables ():
218218 string = [random .getrandbits (8 ) for _ in range (random .randint (2 , 10 ))]
219- fg , bg = self .getRandomColor (), self .getRandomColor ()
219+ fg , bg = self .get_random_color (), self .get_random_color ()
220220 if len (string ) > ((height - y ) * width - x ): # compare length of string to remaining space on the console
221221 with self .assertRaises (tdl .TDLError ): # expect end of console error
222- self .console .drawStr (x , y , string , fg , bg )
222+ self .console .draw_str (x , y , string , fg , bg )
223223 else :
224- self .console .drawStr (x , y , string , fg , bg )
224+ self .console .draw_str (x , y , string , fg , bg )
225225 for ch in string : # inspect console for changes
226- self .assertEqual (self .console .getChar (x , y ), (ch , fg , bg ), 'console data should be overwritten, even after an error' )
226+ self .assertEqual (self .console .get_char (x , y ), (ch , fg , bg ), 'console data should be overwritten, even after an error' )
227227 x += 1
228228 if x == width :
229229 x = 0
@@ -233,54 +233,54 @@ def test_drawStrArray(self):
233233 self .flush () # show progress
234234
235235 #@unittest.skipIf(not __debug__, 'python run with optimized flag, skipping an AssertionError test')
236- #def test_drawStrErrors (self):
236+ #def test_draw_strErrors (self):
237237 # "test out of bounds assertion errors"
238- # for x,y in self.getUndrawables ():
238+ # for x,y in self.get_undrawables ():
239239 # with self.assertRaisesRegexp(AssertionError, r"\(%i, %i\)" % (x, y)):
240- # self.console.drawStr (x, y, 'foo', self.getRandomColor (), self.getRandomColor ())
240+ # self.console.draw_str (x, y, 'foo', self.get_random_color (), self.get_random_color ())
241241
242- def test_drawRect (self ):
243- consoleCopy = tdl .Console (* (self .console .getSize ()))
244- for x ,y in random .sample (list (self .getDrawables ()), 20 ):
242+ def test_draw_rect (self ):
243+ consoleCopy = tdl .Console (* (self .console .get_size ()))
244+ for x ,y in random .sample (list (self .get_drawables ()), 20 ):
245245 consoleCopy .blit (self .console ) # copy the console to compare untouched areas
246- ch , fg , bg = self .getRandomCharacter ()
247- width , height = self .console .getSize ()
246+ ch , fg , bg = self .get_random_character ()
247+ width , height = self .console .get_size ()
248248 width , height = random .randint (1 , width - x ), random .randint (1 , height - y )
249- self .console .drawRect (x , y , width , height , ch , fg , bg )
249+ self .console .draw_rect (x , y , width , height , ch , fg , bg )
250250 self .flush () # show progress
251- for testX ,testY in self .getDrawables ():
251+ for testX ,testY in self .get_drawables ():
252252 if x <= testX < x + width and y <= testY < y + height :
253- self .assertEqual (self .console .getChar (testX , testY ), (ch , fg , bg ), 'rectangle area should be overwritten' )
253+ self .assertEqual (self .console .get_char (testX , testY ), (ch , fg , bg ), 'rectangle area should be overwritten' )
254254 else :
255- self .assertEqual (self .console .getChar (testX , testY ), consoleCopy .getChar (testX , testY ), 'this area should remain untouched' )
255+ self .assertEqual (self .console .get_char (testX , testY ), consoleCopy .get_char (testX , testY ), 'this area should remain untouched' )
256256
257- def test_drawFrame (self ):
258- consoleCopy = tdl .Console (* (self .console .getSize ()))
259- for x ,y in random .sample (list (self .getDrawables ()), 20 ):
257+ def test_draw_frame (self ):
258+ consoleCopy = tdl .Console (* (self .console .get_size ()))
259+ for x ,y in random .sample (list (self .get_drawables ()), 20 ):
260260 consoleCopy .blit (self .console ) # copy the console to compare untouched areas
261- ch , fg , bg = self .getRandomCharacter ()
262- width , height = self .console .getSize ()
261+ ch , fg , bg = self .get_random_character ()
262+ width , height = self .console .get_size ()
263263 width , height = random .randint (1 , width - x ), random .randint (1 , height - y )
264- self .console .drawFrame (x , y , width , height , ch , fg , bg )
264+ self .console .draw_frame (x , y , width , height , ch , fg , bg )
265265 self .flush () # show progress
266- for testX ,testY in self .getDrawables ():
266+ for testX ,testY in self .get_drawables ():
267267 if x + 1 <= testX < x + width - 1 and y + 1 <= testY < y + height - 1 :
268- self .assertEqual (self .console .getChar (testX , testY ), consoleCopy .getChar (testX , testY ), 'inner frame should remain untouched' )
268+ self .assertEqual (self .console .get_char (testX , testY ), consoleCopy .get_char (testX , testY ), 'inner frame should remain untouched' )
269269 elif x <= testX < x + width and y <= testY < y + height :
270- self .assertEqual (self .console .getChar (testX , testY ), (ch , fg , bg ), 'frame area should be overwritten' )
270+ self .assertEqual (self .console .get_char (testX , testY ), (ch , fg , bg ), 'frame area should be overwritten' )
271271 else :
272- self .assertEqual (self .console .getChar (testX , testY ), consoleCopy .getChar (testX , testY ), 'outer frame should remain untouched' )
272+ self .assertEqual (self .console .get_char (testX , testY ), consoleCopy .get_char (testX , testY ), 'outer frame should remain untouched' )
273273
274274 #@unittest.skipIf(not __debug__, 'python run with optimized flag, skipping an AssertionError test')
275- #def test_drawRectFrameErrors (self):
276- # for x,y in self.getDrawables ():
277- # ch, fg, bg = self.getRandomCharacter ()
278- # width, height = self.console.getSize ()
275+ #def test_draw_rectFrameErrors (self):
276+ # for x,y in self.get_drawables ():
277+ # ch, fg, bg = self.get_random_character ()
278+ # width, height = self.console.get_size ()
279279 # width, height = random.randint(x + width, x + width + ERROR_RANGE), random.randint(y + height, y + height + ERROR_RANGE)
280280 # with self.assertRaises(AssertionError):
281- # self.console.drawRect (x, y, width, height, ch, fg, bg)
281+ # self.console.draw_rect (x, y, width, height, ch, fg, bg)
282282 # with self.assertRaises(AssertionError):
283- # self.console.drawFrame (x, y, width, height, ch, fg, bg)
283+ # self.console.draw_frame (x, y, width, height, ch, fg, bg)
284284
285285 #@unittest.skip("Need this to be faster before unskipping")
286286 def test_scrolling (self ):
@@ -295,17 +295,17 @@ def test_scrolling(self):
295295 scrollTests .add ((random .randint (- WIDTH , WIDTH ),
296296 random .randint (- HEIGHT , HEIGHT )))
297297 for sx , sy in scrollTests :
298- noiseData = dict (self .randomizeConsole ())
298+ noiseData = dict (self .randomize_console ())
299299 self .console .set_colors ((0 , 0 , 0 ), (0 , 0 , 0 ))
300300 self .console .scroll (sx , sy )
301301 self .flush () # show progress
302- for x , y in self .getDrawables ():
302+ for x , y in self .get_drawables ():
303303 nX = x - sx
304304 nY = y - sy
305305 if (nX , nY ) in noiseData :
306- self .assertEqual (self .console .getChar (x , y ), noiseData [nX , nY ], 'random noise should be scrolled' )
306+ self .assertEqual (self .console .get_char (x , y ), noiseData [nX , nY ], 'random noise should be scrolled' )
307307 else :
308- self .assertEqual (self .console .getChar (x , y ), DEFAULT_CHAR , 'scrolled away positions should be clear' )
308+ self .assertEqual (self .console .get_char (x , y ), DEFAULT_CHAR , 'scrolled away positions should be clear' )
309309
310310
311311def suite ():
0 commit comments