Commits

Anonymous committed 7b7a17e

Updated unit tests for the Font API.

Comments (0)

Files changed (3)

src/freetype/ft_font.c

     FreeTypeInstance *ft;
     ASSERT_GRAB_FREETYPE(ft, NULL);
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iOii", kwlist, 
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iii", kwlist, 
                 &text, &style, &rotation, &ptsize))
         return NULL;
 
     if (PGFT_BuildRenderMode(ft, font, &render, 
                 ptsize, style, rotation) != 0)
     {
-        PyErr_SetString(PyExc_PyGameError, PGFT_GetError(ft));
+        PyErr_SetString(PyExc_ValueError, PGFT_GetError(ft));
         return NULL;
     }
 
     if (PGFT_BuildRenderMode(ft, font, 
                 &render, ptsize, FT_STYLE_NORMAL, 0) != 0)
     {
-        PyErr_SetString(PyExc_PyGameError, PGFT_GetError(ft));
+        PyErr_SetString(PyExc_ValueError, PGFT_GetError(ft));
         return NULL;
     }
 
     if (PGFT_BuildRenderMode(ft, font, 
                 &render, ptsize, FT_STYLE_NORMAL, 0) != 0)
     {
-        PyErr_SetString(PyExc_PyGameError, PGFT_GetError(ft));
+        PyErr_SetString(PyExc_ValueError, PGFT_GetError(ft));
         return NULL;
     }
 
 
     if (PGFT_BuildRenderMode(ft, font, &render, ptsize, style, rotation) != 0)
     {
-        PyErr_SetString(PyExc_PyGameError, PGFT_GetError(ft));
+        PyErr_SetString(PyExc_ValueError, PGFT_GetError(ft));
         return NULL;
     }
 
 
         if (!r_surface)
         {
-            PyErr_SetString(PyExc_PyGameError, PGFT_GetError(ft));
+            PyErr_SetString(PyExc_ValueError, PGFT_GetError(ft));
             return NULL;
         }
 

src/freetype/ft_wrap.c

         }
     }
 
-    if (ft_msg)
+    if (error_id && ft_msg)
         sprintf(ft->_error_msg, "%s: %s", error_msg, ft_msg);
     else
         strcpy(ft->_error_msg, error_msg);

test/freetype_font_test.py

         test_size(size_bolden)
         self.assertTrue(size_bolden > size_default)
 
-        size_vert = font.get_size("ABCDabcd", ptsize=24, vertical=True)
+        font.vertical = True
+        size_vert = font.get_size("ABCDabcd", ptsize=24)
         test_size(size_vert)
         self.assertTrue(size_vert[0] < size_vert[1])
+        font.vertical = False
 
         # TODO: Slanted text is slightly wider!
         size_italic = font.get_size("ABCDabcd", ptsize=24, style=ft_const.STYLE_ITALIC)
         color = pygame2.base.Color(0, 0, 0)
 
         # make sure we always have a valid fg color
-        self.assertRaises(TypeError, font.render, 'FoobarBaz')
-        self.assertRaises(TypeError, font.render, 'FoobarBaz', None)
+        self.assertRaises(TypeError, font.render, None, 'FoobarBaz')
+        self.assertRaises(TypeError, font.render, None, 'FoobarBaz', None)
 
         # render to new surface
-        rend = font.render('FoobarBaz', pygame2.base.Color(0, 0, 0), None, None, ptsize=24)
+        rend = font.render(None, 'FoobarBaz', pygame2.base.Color(0, 0, 0), None, ptsize=24)
+        self.assertTrue(isinstance(rend, tuple))
+        self.assertTrue(isinstance(rend[0], pygame2.base.Surface))
+        self.assertTrue(isinstance(rend[1], int))
+        self.assertTrue(isinstance(rend[2], int))
+
+        # render to existing surface
+        rend = font.render((surf, 32, 32), 'FoobarBaz', color, None, ptsize=24)
         self.assertTrue(isinstance(rend, tuple))
         self.assertTrue(isinstance(rend[0], int))
         self.assertTrue(isinstance(rend[1], int))
-        self.assertTrue(isinstance(rend[2], pygame2.base.Surface))
-
-        # render to existing surface
-        rend = font.render('FoobarBaz', color, None, surf, ptsize=24)
-        self.assertTrue(isinstance(rend, tuple))
-        self.assertTrue(isinstance(rend[0], int))
-        self.assertTrue(isinstance(rend[1], int))
-        self.assertTrue(isinstance(rend[2], pygame2.base.Surface))
-        self.assertEqual(rend[2], surf)
 
         # misc parameter test
-        self.assertRaises(pygame2.base.Error, font.render, 'foobar', color)
-        self.assertRaises(TypeError, font.render, 'foobar', color, "", ptsize=24)
-        self.assertRaises(TypeError, font.render, 'foobar', color,
-                None, 42, ptsize=24)
-        self.assertRaises(TypeError, font.render, 'foobar', color,
-                None, None, antialias=3, ptsize=24)
-        self.assertRaises(TypeError, font.render, 'foobar', color,
-                None, None, style=None, ptsize=24)
-        self.assertRaises(pygame2.base.Error, font.render, 'foobar', color,
-                None, None, style=97, ptsize=24)
+        self.assertRaises(ValueError, font.render, None, 'foobar', color)
+        self.assertRaises(TypeError, font.render, None, 'foobar', color, "",
+                ptsize=24)
+        self.assertRaises(ValueError, font.render, None, 'foobar', color, None,
+                style=42, ptsize=24)
+        self.assertRaises(TypeError, font.render, None, 'foobar', color, None,
+                style=None, ptsize=24)
+        self.assertRaises(ValueError, font.render, None, 'foobar', color, None,
+                style=97, ptsize=24)
 
         pygame2.sdl.video.quit()