Commits

Anonymous committed 4d8ea3e

Added pygame.scrap unittest. scrap.set_mode() raises an exception on wrong modes now. Minor pixelarray unittest changes.

Comments (0)

Files changed (4)

 test_module_re = re.compile('^(.+_test)\.py$')
 for file in os.listdir(test_subdir):
     for module in test_module_re.findall(file):
+        if module == "scrap_test":
+            continue
         print 'loading ' + module
         __import__( module )
         test = unittest.defaultTestLoader.loadTestsFromName( module )
     if (!PyArg_ParseTuple (args, "i", &_currentmode))
         return NULL;
 
+    if (_currentmode != SCRAP_CLIPBOARD && _currentmode != SCRAP_SELECTION)
+        return RAISE (PyExc_ValueError, "invalid clipboard mode");
+
 #ifndef X11_SCRAP
     /* Force the clipboard, if not in a X11 environment. */
     _currentmode = SCRAP_CLIPBOARD;

test/pixelarray_test.py

         sf.fill ((0, 0, 0))
         ar = pygame.PixelArray (sf)
 
+        sf2 = pygame.Surface ((6, 8), 0, 32)
+        sf2.fill ((0, 255, 255))
+        ar2 = pygame.PixelArray (sf2)
+
         # Test single value assignment
         ar[2] = 0x808080
         self.assertEqual (ar[2][0], 0x808080)
         self.assertEqual (ar[1][1], 0x111111)
 
         # Test pixel array assignment.
-        ar[1] = ar[3]
-        self.assertEqual (ar[1][0], 0x000000)
-        self.assertEqual (ar[1][1], 0x000000)
+        ar[1] = ar2[3]
+        self.assertEqual (ar[1][0], 0x00FFFF)
+        self.assertEqual (ar[1][1], 0x00FFFF)
 
     def test_get_slice (self):
         sf = pygame.Surface ((10, 20), 0, 32)
         # Has to resolve to ar[7:8]
         self.assertEqual (len (ar[-3:-2]), 20)
 
-##    def test_set_slice (self):
+##     def test_set_slice (self):
 ##         sf = pygame.Surface ((6, 8), 0, 32)
 ##         sf.fill ((0, 0, 0))
 ##         ar = pygame.PixelArray (sf)
 
-        # Test single value assignment
+##         # Test single value assignment
 ##         ar[0:2] = 0x808080
 ##         print ar
 ##         self.assertEqual (ar[0][0], 0x808080)
 ##         self.assertEqual (ar[4][0], 0xFFFF00)
 ##         self.assertEqual (ar[-1][1], 0xFFFF00)
 
-        # Test list assignment.
+##         # Test list assignment.
 ##         ar[2:4] = [0xFFFFFF] * 16
 ##         print ar
 ##         self.assertEqual (ar[2][0], 0xFFFFFF)

test/scrap_test.py

+import unittest
+import pygame
+from pygame.locals import *
+import pygame.scrap as scrap
+
+class ScrapTest (unittest.TestCase):
+
+    def test_scrap_mode (self):
+        scrap.set_mode (SCRAP_SELECTION)
+        scrap.set_mode (SCRAP_CLIPBOARD)
+        self.assertRaises (ValueError, scrap.set_mode, 1099)
+
+    def test_scrap_put_text (self):
+        scrap.put (SCRAP_TEXT, "Hello world")
+        self.assertEquals (scrap.get (SCRAP_TEXT), "Hello world")
+
+        scrap.put (SCRAP_TEXT, "Another String")
+        self.assertEquals (scrap.get (SCRAP_TEXT), "Another String")
+
+    def test_scrap_put_image (self):
+        sf = pygame.image.load ("examples/data/asprite.bmp")
+        string = pygame.image.tostring (sf, "RGBA")
+        scrap.put (SCRAP_BMP, string)
+        self.assertEquals (scrap.get (SCRAP_BMP), string)
+        
+if __name__ == '__main__':
+    pygame.init ()
+    pygame.display.set_mode ((1, 1))
+    scrap.init ()
+    unittest.main()