~pygame/pygame/trunk

« back to all changes in this revision

Viewing changes to test/font_test.py

  • Committer: pygame
  • Date: 2017-01-10 00:31:42 UTC
  • Revision ID: git-v1:2eea4f299a2e791f884608d7ed601558634af73c
commit 1639c41a8cb3433046882ede92c80ce69d59016b
Author: Thomas Kluyver <takowl@gmail.com>
Date:   Sun Jan 8 18:46:46 2017 +0000

    Build newer versions of libogg and libvorbis into Linux base images

    Closes #317
    Closes #323

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
import os
 
3
if __name__ == '__main__':
 
4
    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
 
5
    parent_dir, pkg_name = os.path.split(pkg_dir)
 
6
    is_pygame_pkg = (pkg_name == 'tests' and
 
7
                     os.path.split(parent_dir)[1] == 'pygame')
 
8
    if not is_pygame_pkg:
 
9
        sys.path.insert(0, parent_dir)
 
10
else:
 
11
    is_pygame_pkg = __name__.startswith('pygame.tests.')
 
12
 
 
13
import unittest
 
14
import pygame
 
15
from pygame import font as pygame_font  # So font can be replaced with ftfont
 
16
from pygame.compat import as_unicode, as_bytes, xrange_, filesystem_errors
 
17
from pygame.compat import PY_MAJOR_VERSION
 
18
 
 
19
UCS_4 = sys.maxunicode > 0xFFFF
 
20
 
 
21
def equal_images(s1, s2):
 
22
    size = s1.get_size()
 
23
    if s2.get_size() != size:
 
24
        return False
 
25
    w, h = size
 
26
    for x in xrange_(w):
 
27
        for y in xrange_(h):
 
28
            if s1.get_at((x, y)) != s2.get_at((x, y)):
 
29
                return False
 
30
    return True
 
31
 
 
32
 
 
33
class FontModuleTest( unittest.TestCase ):
 
34
    def setUp(self):
 
35
        pygame_font.init()
 
36
 
 
37
    def tearDown(self):
 
38
        pygame_font.quit()
 
39
 
 
40
    def test_SysFont(self):
 
41
        # Can only check that a font object is returned.
 
42
        fonts = pygame_font.get_fonts()
 
43
        o = pygame_font.SysFont(fonts[0], 20)
 
44
        self.failUnless(isinstance(o, pygame_font.FontType))
 
45
        o = pygame_font.SysFont(fonts[0], 20, italic=True)
 
46
        self.failUnless(isinstance(o, pygame_font.FontType))
 
47
        o = pygame_font.SysFont(fonts[0], 20, bold=True)
 
48
        self.failUnless(isinstance(o, pygame_font.FontType))
 
49
        o = pygame_font.SysFont('thisisnotafont', 20)
 
50
        self.failUnless(isinstance(o, pygame_font.FontType))
 
51
 
 
52
    def test_get_default_font(self):
 
53
        self.failUnlessEqual(pygame_font.get_default_font(), 'freesansbold.ttf')
 
54
 
 
55
    def test_get_fonts_returns_something(self):
 
56
        fnts = pygame_font.get_fonts()
 
57
        self.failUnless(fnts)
 
58
 
 
59
 
 
60
    # to test if some files exist...
 
61
    #def XXtest_has_file_osx_10_5_sdk(self):
 
62
    #    import os
 
63
    #    f = "/Developer/SDKs/MacOSX10.5.sdk/usr/X11/include/ft2build.h"
 
64
    #    self.assertEqual(os.path.exists(f), True)
 
65
 
 
66
    #def XXtest_has_file_osx_10_4_sdk(self):
 
67
    #    import os
 
68
    #    f = "/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include/ft2build.h"
 
69
    #    self.assertEqual(os.path.exists(f), True)
 
70
 
 
71
 
 
72
 
 
73
 
 
74
 
 
75
    def test_get_fonts(self):
 
76
        fnts = pygame_font.get_fonts()
 
77
 
 
78
        if not fnts:
 
79
            raise Exception(repr(fnts))
 
80
 
 
81
        self.failUnless(fnts)
 
82
 
 
83
        if (PY_MAJOR_VERSION >= 3):
 
84
            # For Python 3.x, names will always be unicode strings.
 
85
            name_types = (str,)
 
86
        else:
 
87
            # For Python 2.x, names may be either unicode or ascii strings.
 
88
            name_types = (str, unicode)
 
89
 
 
90
        for name in fnts:
 
91
            # note, on ubuntu 2.6 they are all unicode strings.
 
92
 
 
93
            self.failUnless(isinstance(name, name_types), name)
 
94
            self.failUnless(name.islower(), name)
 
95
            self.failUnless(name.isalnum(), name)
 
96
 
 
97
    def test_get_init(self):
 
98
        self.failUnless(pygame_font.get_init())
 
99
        pygame_font.quit()
 
100
        self.failIf(pygame_font.get_init())
 
101
 
 
102
    def test_init(self):
 
103
        pygame_font.init()
 
104
 
 
105
    def test_match_font_all_exist(self):
 
106
        fonts = pygame_font.get_fonts()
 
107
 
 
108
        # Ensure all listed fonts are in fact available, and the returned file
 
109
        # name is a full path.
 
110
        for font in fonts:
 
111
            path = pygame_font.match_font(font)
 
112
            self.failIf(path is None)
 
113
            self.failUnless(os.path.isabs(path))
 
114
 
 
115
    def test_match_font_bold(self):
 
116
 
 
117
        fonts = pygame_font.get_fonts()
 
118
 
 
119
        # Look for a bold font.
 
120
        for font in fonts:
 
121
            if pygame_font.match_font(font, bold=True) is not None:
 
122
                break
 
123
        else:
 
124
            self.fail()
 
125
 
 
126
    def test_match_font_italic(self):
 
127
 
 
128
        fonts = pygame_font.get_fonts()
 
129
 
 
130
        # Look for an italic font.
 
131
        for font in fonts:
 
132
            if pygame_font.match_font(font, italic=True) is not None:
 
133
                break
 
134
        else:
 
135
            self.fail()
 
136
 
 
137
 
 
138
    def test_match_font_comma_separated(self):
 
139
 
 
140
        fonts = pygame_font.get_fonts()
 
141
 
 
142
        # Check for not found.
 
143
        self.failUnless(pygame_font.match_font('thisisnotafont') is None)
 
144
 
 
145
        # Check comma separated list.
 
146
        names = ','.join(['thisisnotafont', fonts[-1], 'anothernonfont'])
 
147
        self.failIf(pygame_font.match_font(names) is None)
 
148
        names = ','.join(['thisisnotafont1', 'thisisnotafont2', 'thisisnotafont3'])
 
149
        self.failUnless(pygame_font.match_font(names) is None)
 
150
 
 
151
 
 
152
 
 
153
    def test_quit(self):
 
154
        pygame_font.quit()
 
155
 
 
156
 
 
157
 
 
158
 
 
159
 
 
160
class FontTest(unittest.TestCase):
 
161
    def setUp(self):
 
162
        pygame_font.init()
 
163
 
 
164
    def tearDown(self):
 
165
        pygame_font.quit()
 
166
 
 
167
 
 
168
    def test_render_args(self):
 
169
        screen = pygame.display.set_mode((600, 400))
 
170
        rect = screen.get_rect()
 
171
        f = pygame_font.Font(None, 20)
 
172
        screen.fill((10, 10, 10))
 
173
        font_surface = f.render("   bar", True, (0, 0, 0), (255, 255, 255))
 
174
        font_rect = font_surface.get_rect()
 
175
        font_rect.topleft = rect.topleft
 
176
        self.assertTrue(font_surface)
 
177
        screen.blit(font_surface, font_rect, font_rect)
 
178
        pygame.display.update()
 
179
        self.assertEqual(tuple(screen.get_at((0,0)))[:3], (255, 255, 255))
 
180
        self.assertEqual(tuple(screen.get_at(font_rect.topleft))[:3], (255, 255, 255))
 
181
 
 
182
        # If we don't have a real display, don't do this test.
 
183
        # Transparent background doesn't seem to work without a read video card.
 
184
        if os.environ.get('SDL_VIDEODRIVER') != 'dummy':
 
185
            screen.fill((10, 10, 10))
 
186
            font_surface = f.render("   bar", True, (0, 0, 0), None)
 
187
            font_rect = font_surface.get_rect()
 
188
            font_rect.topleft = rect.topleft
 
189
            self.assertTrue(font_surface)
 
190
            screen.blit(font_surface, font_rect, font_rect)
 
191
            pygame.display.update()
 
192
            self.assertEqual(tuple(screen.get_at((0,0)))[:3], (10, 10, 10))
 
193
            self.assertEqual(tuple(screen.get_at(font_rect.topleft))[:3], (10, 10, 10))
 
194
 
 
195
            screen.fill((10, 10, 10))
 
196
            font_surface = f.render("   bar", True, (0, 0, 0))
 
197
            font_rect = font_surface.get_rect()
 
198
            font_rect.topleft = rect.topleft
 
199
            self.assertTrue(font_surface)
 
200
            screen.blit(font_surface, font_rect, font_rect)
 
201
            pygame.display.update(rect)
 
202
            self.assertEqual(tuple(screen.get_at((0,0)))[:3], (10, 10, 10))
 
203
            self.assertEqual(tuple(screen.get_at(font_rect.topleft))[:3], (10, 10, 10))
 
204
 
 
205
 
 
206
 
 
207
 
 
208
 
 
209
 
 
210
 
 
211
class FontTypeTest( unittest.TestCase ):
 
212
    def setUp(self):
 
213
        pygame_font.init()
 
214
 
 
215
    def tearDown(self):
 
216
        pygame_font.quit()
 
217
 
 
218
    def test_get_ascent(self):
 
219
        # Ckecking ascent would need a custom test font to do properly.
 
220
        f = pygame_font.Font(None, 20)
 
221
        ascent = f.get_ascent()
 
222
        self.failUnless(isinstance(ascent, int))
 
223
        self.failUnless(ascent > 0)
 
224
        s = f.render("X", False, (255, 255, 255))
 
225
        self.failUnless(s.get_size()[1] > ascent)
 
226
 
 
227
    def test_get_descent(self):
 
228
        # Ckecking descent would need a custom test font to do properly.
 
229
        f = pygame_font.Font(None, 20)
 
230
        descent = f.get_descent()
 
231
        self.failUnless(isinstance(descent, int))
 
232
        self.failUnless(descent < 0)
 
233
 
 
234
    def test_get_height(self):
 
235
        # Ckecking height would need a custom test font to do properly.
 
236
        f = pygame_font.Font(None, 20)
 
237
        height = f.get_height()
 
238
        self.failUnless(isinstance(height, int))
 
239
        self.failUnless(height > 0)
 
240
        s = f.render("X", False, (255, 255, 255))
 
241
        self.failUnless(s.get_size()[1] == height)
 
242
 
 
243
    def test_get_linesize(self):
 
244
        # Ckecking linesize would need a custom test font to do properly.
 
245
        # Questions: How do linesize, height and descent relate?
 
246
        f = pygame_font.Font(None, 20)
 
247
        linesize = f.get_linesize()
 
248
        self.failUnless(isinstance(linesize, int))
 
249
        self.failUnless(linesize > 0)
 
250
 
 
251
    def test_metrics(self):
 
252
        # Ensure bytes decoding works correctly. Can only compare results
 
253
        # with unicode for now.
 
254
        f = pygame_font.Font(None, 20)
 
255
        um = f.metrics(as_unicode("."))
 
256
        bm = f.metrics(as_bytes("."))
 
257
        self.assert_(len(um) == 1)
 
258
        self.assert_(len(bm) == 1)
 
259
        self.assert_(um[0] is not None)
 
260
        self.assert_(um == bm)
 
261
        u = as_unicode(r"\u212A")
 
262
        b = u.encode("UTF-16")[2:] # Keep byte order consistent. [2:] skips BOM
 
263
        bm = f.metrics(b)
 
264
        self.assert_(len(bm) == 2)
 
265
        try:
 
266
            um = f.metrics(u)
 
267
        except pygame.error:
 
268
            pass
 
269
        else:
 
270
            self.assert_(len(um) == 1)
 
271
            self.assert_(bm[0] != um[0])
 
272
            self.assert_(bm[1] != um[0])
 
273
 
 
274
        if UCS_4:
 
275
            u = as_unicode(r"\U00013000")
 
276
            bm = f.metrics(u)
 
277
            self.assert_(len(bm) == 1 and bm[0] is None)
 
278
    
 
279
        return # unfinished
 
280
        # The documentation is useless here. How large a list?
 
281
        # How do list positions relate to character codes?
 
282
        # What about unicode characters?
 
283
 
 
284
        # __doc__ (as of 2008-08-02) for pygame_font.Font.metrics:
 
285
 
 
286
          # Font.metrics(text): return list
 
287
          # Gets the metrics for each character in the pased string.
 
288
          # 
 
289
          # The list contains tuples for each character, which contain the
 
290
          # minimum X offset, the maximum X offset, the minimum Y offset, the
 
291
          # maximum Y offset and the advance offset (bearing plus width) of the
 
292
          # character. [(minx, maxx, miny, maxy, advance), (minx, maxx, miny,
 
293
          # maxy, advance), ...]
 
294
 
 
295
        self.fail() 
 
296
 
 
297
    def test_render(self):
 
298
        """ 
 
299
        """
 
300
 
 
301
        f = pygame_font.Font(None, 20)
 
302
        s = f.render("foo", True, [0, 0, 0], [255, 255, 255])
 
303
        s = f.render("xxx", True, [0, 0, 0], [255, 255, 255])
 
304
        s = f.render("", True, [0, 0, 0], [255, 255, 255])
 
305
        s = f.render("foo", False, [0, 0, 0], [255, 255, 255])
 
306
        s = f.render("xxx", False, [0, 0, 0], [255, 255, 255])
 
307
        s = f.render("xxx", False, [0, 0, 0])
 
308
        s = f.render("   ", False, [0, 0, 0])
 
309
        s = f.render("   ", False, [0, 0, 0], [255, 255, 255])
 
310
        # null text should be 1 pixel wide.
 
311
        s = f.render("", False, [0, 0, 0], [255, 255, 255])
 
312
        self.assertEqual(s.get_size()[0], 1)
 
313
        # None text should be 1 pixel wide.
 
314
        s = f.render(None, False, [0, 0, 0], [255, 255, 255])
 
315
        self.assertEqual(s.get_size()[0], 1)
 
316
        # Non-text should raise a TypeError.
 
317
        self.assertRaises(TypeError, f.render,
 
318
                          [], False, [0, 0, 0], [255, 255, 255])
 
319
        self.assertRaises(TypeError, f.render,
 
320
                          1, False, [0, 0, 0], [255, 255, 255])
 
321
        # is background transparent for antialiasing?
 
322
        s = f.render(".", True, [255, 255, 255])
 
323
        self.failUnlessEqual(s.get_at((0, 0))[3], 0)
 
324
        # is Unicode and bytes encoding correct?
 
325
        # Cannot really test if the correct characters are rendered, but
 
326
        # at least can assert the encodings differ.
 
327
        su = f.render(as_unicode("."), False, [0, 0, 0], [255, 255, 255])
 
328
        sb = f.render(as_bytes("."), False, [0, 0, 0], [255, 255, 255])
 
329
        self.assert_(equal_images(su, sb))
 
330
        u = as_unicode(r"\u212A")
 
331
        b = u.encode("UTF-16")[2:] # Keep byte order consistent. [2:] skips BOM
 
332
        sb = f.render(b, False, [0, 0, 0], [255, 255, 255])
 
333
        try:
 
334
            su = f.render(u, False, [0, 0, 0], [255, 255, 255])
 
335
        except pygame.error:
 
336
            pass
 
337
        else:
 
338
            self.assert_(not equal_images(su, sb))
 
339
 
 
340
        # If the font module is SDL_ttf based, then it can only supports  UCS-2;
 
341
        # it will raise an exception for an out-of-range UCS-4 code point.
 
342
        if UCS_4 and not hasattr(f, 'ucs4'):
 
343
            ucs_2 = as_unicode(r"\uFFEE")
 
344
            s = f.render(ucs_2, False, [0, 0, 0], [255, 255, 255])
 
345
            ucs_4 = as_unicode(r"\U00010000")
 
346
            self.assertRaises(UnicodeError, f.render,
 
347
                              ucs_4, False, [0, 0, 0], [255, 255, 255])
 
348
 
 
349
        b = as_bytes("ab\x00cd")
 
350
        self.assertRaises(ValueError, f.render, b, 0, [0, 0, 0])
 
351
        u = as_unicode("ab\x00cd")
 
352
        self.assertRaises(ValueError, f.render, b, 0, [0, 0, 0])
 
353
    
 
354
        # __doc__ (as of 2008-08-02) for pygame_font.Font.render:
 
355
 
 
356
          # Font.render(text, antialias, color, background=None): return Surface
 
357
          # draw text on a new Surface
 
358
          # 
 
359
          # This creates a new Surface with the specified text rendered on it.
 
360
          # Pygame provides no way to directly draw text on an existing Surface:
 
361
          # instead you must use Font.render() to create an image (Surface) of
 
362
          # the text, then blit this image onto another Surface.
 
363
          # 
 
364
          # The text can only be a single line: newline characters are not
 
365
          # rendered. The antialias argument is a boolean: if true the
 
366
          # characters will have smooth edges. The color argument is the color
 
367
          # of the text [e.g.: (0,0,255) for blue]. The optional background
 
368
          # argument is a color to use for the text background. If no background
 
369
          # is passed the area outside the text will be transparent.
 
370
          # 
 
371
          # The Surface returned will be of the dimensions required to hold the
 
372
          # text. (the same as those returned by Font.size()). If an empty
 
373
          # string is passed for the text, a blank surface will be returned that
 
374
          # is one pixel wide and the height of the font.
 
375
          # 
 
376
          # Depending on the type of background and antialiasing used, this
 
377
          # returns different types of Surfaces. For performance reasons, it is
 
378
          # good to know what type of image will be used. If antialiasing is not
 
379
          # used, the return image will always be an 8bit image with a two color
 
380
          # palette. If the background is transparent a colorkey will be set.
 
381
          # Antialiased images are rendered to 24-bit RGB images. If the
 
382
          # background is transparent a pixel alpha will be included.
 
383
          # 
 
384
          # Optimization: if you know that the final destination for the text
 
385
          # (on the screen) will always have a solid background, and the text is
 
386
          # antialiased, you can improve performance by specifying the
 
387
          # background color. This will cause the resulting image to maintain
 
388
          # transparency information by colorkey rather than (much less
 
389
          # efficient) alpha values.
 
390
          # 
 
391
          # If you render '\n' a unknown char will be rendered.  Usually a
 
392
          # rectangle. Instead you need to handle new lines yourself.
 
393
          # 
 
394
          # Font rendering is not thread safe: only a single thread can render
 
395
          # text any time.
 
396
 
 
397
 
 
398
    def test_set_bold(self):
 
399
        f = pygame_font.Font(None, 20)
 
400
        self.failIf(f.get_bold())
 
401
        f.set_bold(True)
 
402
        self.failUnless(f.get_bold())
 
403
        f.set_bold(False)
 
404
        self.failIf(f.get_bold())
 
405
 
 
406
    def test_set_italic(self):
 
407
        f = pygame_font.Font(None, 20)
 
408
        self.failIf(f.get_italic())
 
409
        f.set_italic(True)
 
410
        self.failUnless(f.get_italic())
 
411
        f.set_italic(False)
 
412
        self.failIf(f.get_italic())
 
413
 
 
414
    def test_set_underline(self):
 
415
        f = pygame_font.Font(None, 20)
 
416
        self.failIf(f.get_underline())
 
417
        f.set_underline(True)
 
418
        self.failUnless(f.get_underline())
 
419
        f.set_underline(False)
 
420
        self.failIf(f.get_underline())
 
421
 
 
422
    def test_size(self):
 
423
        f = pygame_font.Font(None, 20)
 
424
        text = as_unicode("Xg")
 
425
        size = f.size(text)
 
426
        w, h = size
 
427
        self.assert_(isinstance(w, int) and isinstance(h, int))
 
428
        s = f.render(text, False, (255, 255, 255))
 
429
        self.assert_(size == s.get_size())
 
430
        btext = text.encode("ascii")
 
431
        self.assert_(f.size(btext) == size)
 
432
        text = as_unicode(r"\u212A")
 
433
        btext = text.encode("UTF-16")[2:] # Keep the byte order consistent.
 
434
        bsize = f.size(btext)
 
435
        try:
 
436
            size = f.size(text)
 
437
        except pygame.error:
 
438
            pass
 
439
        else:
 
440
            self.assert_(size != bsize)
 
441
 
 
442
    def test_font_file_not_found(self):
 
443
        # A per BUG reported by Bo Jangeborg on pygame-user mailing list,
 
444
        # http://www.mail-archive.com/pygame-users@seul.org/msg11675.html
 
445
 
 
446
        pygame_font.init()
 
447
        self.failUnlessRaises(IOError,
 
448
                              pygame_font.Font,
 
449
                              'some-fictional-font.ttf', 20)
 
450
 
 
451
    def test_load_from_file(self):
 
452
        font_name = pygame_font.get_default_font()
 
453
        font_path = os.path.join(os.path.split(pygame.__file__)[0], 
 
454
                                 pygame_font.get_default_font())
 
455
        f = pygame_font.Font(font_path, 20)
 
456
 
 
457
    def test_load_from_file_obj(self):
 
458
        font_name = pygame_font.get_default_font()
 
459
        font_path = os.path.join(os.path.split(pygame.__file__)[0], 
 
460
                                 pygame_font.get_default_font())
 
461
        f = open(font_path, "rb")
 
462
        font = pygame_font.Font(f, 20)
 
463
 
 
464
    def test_load_default_font_filename(self):
 
465
        # In font_init, a special case is when the filename argument is
 
466
        # identical to the default font file name.
 
467
        f = pygame_font.Font(pygame_font.get_default_font(), 20)
 
468
 
 
469
    def test_load_from_file_unicode(self):
 
470
        base_dir = os.path.dirname(pygame.__file__)
 
471
        font_path = os.path.join(base_dir, pygame_font.get_default_font())
 
472
        if os.path.sep == '\\':
 
473
            font_path = font_path.replace('\\', '\\\\')
 
474
        ufont_path = as_unicode(font_path)
 
475
        f = pygame_font.Font(ufont_path, 20)
 
476
 
 
477
    def test_load_from_file_bytes(self):
 
478
        font_path = os.path.join(os.path.split(pygame.__file__)[0], 
 
479
                                 pygame_font.get_default_font())
 
480
        filesystem_encoding = sys.getfilesystemencoding()
 
481
        try:
 
482
            font_path = font_path.decode(filesystem_encoding,
 
483
                                         filesystem_errors)
 
484
        except AttributeError:
 
485
            pass
 
486
        bfont_path = font_path.encode(filesystem_encoding,
 
487
                                      filesystem_errors)
 
488
        f = pygame_font.Font(bfont_path, 20)
 
489
 
 
490
class VisualTests( unittest.TestCase ):
 
491
    __tags__ = ['interactive']
 
492
    
 
493
    screen = None
 
494
    aborted = False
 
495
    
 
496
    def setUp(self):
 
497
        if self.screen is None:
 
498
            pygame.init()
 
499
            self.screen = pygame.display.set_mode((600, 200))
 
500
            self.screen.fill((255, 255, 255))
 
501
            pygame.display.flip()
 
502
            self.f = pygame_font.Font(None, 32)
 
503
 
 
504
    def abort(self):
 
505
        if self.screen is not None:
 
506
            pygame.quit()
 
507
        self.aborted = True
 
508
 
 
509
    def query(self,
 
510
              bold=False, italic=False, underline=False, antialiase=False):
 
511
        if self.aborted:
 
512
            return False
 
513
        spacing = 10
 
514
        offset = 20
 
515
        y = spacing
 
516
        f = self.f
 
517
        screen = self.screen
 
518
        screen.fill((255, 255, 255))
 
519
        pygame.display.flip()
 
520
        if not (bold or italic or underline or antialiase):
 
521
            text = "normal"
 
522
        else:
 
523
            modes = []
 
524
            if bold:
 
525
                modes.append("bold")
 
526
            if italic:
 
527
                modes.append("italic")
 
528
            if underline:
 
529
                modes.append("underlined")
 
530
            if antialiase:
 
531
                modes.append("antialiased")
 
532
            text = "%s (y/n):" % ('-'.join(modes),)
 
533
        f.set_bold(bold)
 
534
        f.set_italic(italic)
 
535
        f.set_underline(underline)
 
536
        s = f.render(text, antialiase, (0, 0, 0))
 
537
        screen.blit(s, (offset, y))
 
538
        y += s.get_size()[1] + spacing
 
539
        f.set_bold(False)
 
540
        f.set_italic(False)
 
541
        f.set_underline(False)
 
542
        s = f.render("(some comparison text)", False, (0, 0, 0))
 
543
        screen.blit(s, (offset, y))
 
544
        pygame.display.flip()
 
545
        while 1:
 
546
            for evt in pygame.event.get():
 
547
                if evt.type == pygame.KEYDOWN:
 
548
                    if evt.key == pygame.K_ESCAPE:
 
549
                        self.abort()
 
550
                        return False
 
551
                    if evt.key == pygame.K_y:
 
552
                        return True
 
553
                    if evt.key == pygame.K_n:
 
554
                        return False
 
555
                if evt.type == pygame.QUIT:
 
556
                    self.abort()
 
557
                    return False
 
558
 
 
559
    def test_bold(self):
 
560
        self.failUnless(self.query(bold=True))
 
561
 
 
562
    def test_italic(self):
 
563
        self.failUnless(self.query(italic=True))
 
564
 
 
565
    def test_underline(self):
 
566
        self.failUnless(self.query(underline=True))
 
567
 
 
568
    def test_antialiase(self):
 
569
        self.failUnless(self.query(antialiase=True))
 
570
 
 
571
    def test_bold_antialiase(self):
 
572
        self.failUnless(self.query(bold=True, antialiase=True))
 
573
 
 
574
    def test_italic_underline(self):
 
575
        self.failUnless(self.query(italic=True, underline=True))
 
576
 
 
577
 
 
578
if __name__ == '__main__':
 
579
    unittest.main()