[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] intermittant fails of unit test pixelarray_test.PixelArrayTest with Python 2.4



I have confirmed the problem also exists with Brian Fisher's build of Python 2.4. So here are the specifics: Windows 98, Python 2.4.0 final 0, Pygame 1.8.0rc3 rev 1126. Attached is the modified pixelarray_test.py. All four test modules are required to cause the fail. I assume they must execute in the order given, but it may be pixelarray_test.py only needs to be the last. To isolate the problem I ran the tests in a directory containing only the four test modules and run_tests.py. I will see about trying this on an XP computer.

Lenard


Lenard Lindstrom wrote:

I have narrowed it down to four unit test modules, run in this order: transform_test.py, surfarray_test.py, movie_test.py and pixelarray_test.py . It appears all are necessary to get a consistent fail. The test_contains method in pixelarray_test.py is the first method executed, so commenting out the others has no effect. Finally, putting a print statement on the first line of test_contains almost ensures it fails. At one point I was also noting fails for Python 2.5, something new. I will now try this with Brian Fisher's Pygame builds.

Lenard

René Dudfield wrote:
Yeah, good point.

Another thing to try might be to try removing one of the other tests
at a time until the test stops failing.




On Tue, Feb 26, 2008 at 11:55 AM, Casey Duncan <casey@xxxxxxxxxxx> wrote:
On Feb 25, 2008, at 4:37 PM, Lenard Lindstrom wrote:

 > Lenard Lindstrom wrote:
 >> mva@xxxxxxxxxxxx wrote:
 >>> Lenard Lindstrom <len-l@xxxxxxxxx>:
 >>>
 >> [snip]
 >>>>
 >>>> I just bring this up since it shows possible problems with
 >>>> testing more
 >>>> than one version of Python on the same system. If it is a Pygame
 >>>> bug it
 >>>> is unpredictable and hard to pin down. So please keep a watch for
 >>>> similar problems. Maybe someone using Python 2.4 and SVN version
 >>>> 1126
>>>> of Pygame can run the unit tests ten or more times consecutively to
 >>>> check if it passes consistently? My installers are available at
 >>>> http://www3.telus.net/len_l/pygame.htm along with SVN version
 >>>> 1126 of
 >>>> the Pygame 1.8 documents and examples in compressed and installer
 >>>> form.
 >>>
 >>> Interesting issue. Do you use x64 hardware to test? Maybe it's
 >>> related by
 >>> the Py_ssize_t changes we made for backwards compatibility.
 >>> I'll recheck that for my systems and try to find out, what's going
 >>> on.
 >>>
 >> No, I just have a very old Win32 machine. The fail is sporadic and
 >> appears linked to mixing Pythons. Deleting the .pyc files and
 >> rebooting the computer cleared the problem for 2.4 until I ran 2.5
 >> again. But it could be I am just seeing patterns where they don't
 >> exist and it is something unrelated. So I have just tried it again
 >> from the same Pygame source directory:
 >>
 >> Python 2.4 three times - passed,
 >> 2.5 once - passed,
 >> 2.4 three times - passed,
 >> 2.5 once - passed,
 >> 2.4 twice - failed, passed.
 >>
 > The problem could be with the Python 2.4 unit testing framework
 > itself. I put pixelarray_test.py in its own directory and ran both
 > Python 2.4 and 2.5 on it multiple times. Everything passed.


 Does the individual test case every fail in isolation? Sometimes tests
 can interfere with one another and running with different versions of
 python, a different machine or with a different copy of the file can
 affect test execution order and cause seemingly random failures.

 Should be easy to write a script that just runs that one test case
 forever to see if it ever fails (within say 1000 runs).


import unittest
import pygame

class PixelArrayTest (unittest.TestCase):

#    def test_pixel_array (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((10, 20), 0, bpp)
#            sf.fill ((0, 0, 0))
#            ar = pygame.PixelArray (sf)
#
#            if sf.mustlock():
#                self.assertTrue (sf.get_locked ())
#
#            self.assertEqual (len (ar), 10)
#            del ar
#
#            if sf.mustlock():
#                self.assertFalse (sf.get_locked ())
#
#    # Sequence interfaces
#    def test_get_column (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((10, 20), 0, bpp)
#            sf.fill ((0, 0, 0))
#            ar = pygame.PixelArray (sf)
#
#            ar2 = ar[0]
#            self.assertEqual (len(ar2), 20)
#            
#            ar2 = ar[-1]
#            self.assertEqual (len(ar2), 20)
#
#    def test_get_pixel (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((10, 20), 0, bpp)
#            sf.fill ((0, 0, 255))
#            for x in xrange (20):
#                sf.set_at ((1, x), (0, 0, 11))
#            for x in xrange (10):
#                sf.set_at ((x, 1), (0, 0, 11))
#
#            ar = pygame.PixelArray (sf)
#
#            ar2 = ar[0][0]
#            self.assertEqual (ar2, sf.map_rgb ((0, 0, 255)))
#        
#            ar2 = ar[1][0]
#            self.assertEqual (ar2, sf.map_rgb ((0, 0, 11)))
#            
#            ar2 = ar[-4][1]
#            self.assertEqual (ar2, sf.map_rgb ((0, 0, 11)))
#        
#            ar2 = ar[-4][5]
#            self.assertEqual (ar2, sf.map_rgb ((0, 0, 255)))
#
#    def test_set_pixel (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((10, 20), 0, bpp)
#            sf.fill ((0, 0, 0))
#            ar = pygame.PixelArray (sf)
#
#            ar[0][0] = (0, 255, 0)
#            self.assertEqual (ar[0][0], sf.map_rgb ((0, 255, 0)))
#
#            ar[1][1] = (128, 128, 128)
#            self.assertEqual (ar[1][1], sf.map_rgb ((128, 128, 128)))
#            
#            ar[-1][-1] = (128, 128, 128)
#            self.assertEqual (ar[9][19], sf.map_rgb ((128, 128, 128)))
#            
#            ar[-2][-2] = (128, 128, 128)
#            self.assertEqual (ar[8][-2], sf.map_rgb ((128, 128, 128)))
#
#    def test_set_column (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((6, 8), 0, bpp)
#            sf.fill ((0, 0, 0))
#            ar = pygame.PixelArray (sf)
#
#            sf2 = pygame.Surface ((6, 8), 0, bpp)
#            sf2.fill ((0, 255, 255))
#            ar2 = pygame.PixelArray (sf2)
#
#            # Test single value assignment
#            ar[2] = (128, 128, 128)
#            self.assertEqual (ar[2][0], sf.map_rgb ((128, 128, 128)))
#            self.assertEqual (ar[2][1], sf.map_rgb ((128, 128, 128)))
#        
#            ar[-1] = (0, 255, 255)
#            self.assertEqual (ar[5][0], sf.map_rgb ((0, 255, 255)))
#            self.assertEqual (ar[-1][1], sf.map_rgb ((0, 255, 255)))
#        
#            ar[-2] = (255, 255, 0)
#            self.assertEqual (ar[4][0], sf.map_rgb ((255, 255, 0)))
#            self.assertEqual (ar[-2][1], sf.map_rgb ((255, 255, 0)))
#        
#            # Test list assignment.
#            ar[0] = [(255, 255, 255)] * 8
#            self.assertEqual (ar[0][0], sf.map_rgb ((255, 255, 255)))
#            self.assertEqual (ar[0][1], sf.map_rgb ((255, 255, 255)))
#            
#            # Test tuple assignment.
#            ar[1] = ((204, 0, 204), (17, 17, 17), (204, 0, 204), (17, 17, 17),
#                     (204, 0, 204), (17, 17, 17), (204, 0, 204), (17, 17, 17))
#            self.assertEqual (ar[1][0], sf.map_rgb ((204, 0, 204)))
#            self.assertEqual (ar[1][1], sf.map_rgb ((17, 17, 17)))
#        
#            # Test pixel array assignment.
#            ar[1] = ar2[3]
#            self.assertEqual (ar[1][0], sf.map_rgb ((0, 255, 255)))
#            self.assertEqual (ar[1][1], sf.map_rgb ((0, 255, 255)))
#
#    def test_get_slice (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((10, 20), 0, bpp)
#            sf.fill ((0, 0, 0))
#            ar = pygame.PixelArray (sf)
#        
#            self.assertEqual (len (ar[0:2]), 2)
#            self.assertEqual (len (ar[3:7][3]), 20)
#        
#            self.assertRaises (IndexError, ar.__getslice__, 0, 0)
#            self.assertRaises (IndexError, ar.__getslice__, 9, 9)
#        
#            # Has to resolve to ar[7:8]
#            self.assertEqual (len (ar[-3:-2]), 20)
#
#            # Try assignments.
#
#            # 2D assignment.
#            ar[2:5] = (255, 255, 255)
#            self.assertEqual (ar[3][3], sf.map_rgb ((255, 255, 255)))
#
#            # 1D assignment
#            ar[3][3:7] = (10, 10, 10)
#            self.assertEqual (ar[3][5], sf.map_rgb ((10, 10, 10)))

    def test_contains (self):
        print 'x',
        for bpp in (8, 16, 24, 32):
            sf = pygame.Surface ((10, 20), 0, bpp)
            sf.fill ((0, 0, 0))
            sf.set_at ((8, 8), (255, 255, 255))

            ar = pygame.PixelArray (sf)
            self.assertTrue ((0, 0, 0) in ar)
            self.assertTrue ((255, 255, 255) in ar)
            self.assertFalse ((255, 255, 0) in ar)
            self.assertFalse (0x0000ff in ar)

            # Test sliced array
            self.assertTrue ((0, 0, 0) in ar[8])
            self.assertTrue ((255, 255, 255) in ar[8])
            self.assertFalse ((255, 255, 0) in ar[8])
            self.assertFalse (0x0000ff in ar[8])

#    def test_get_surface (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((10, 20), 0, bpp)
#            sf.fill ((0, 0, 0))
#            ar = pygame.PixelArray (sf)
#            self.assertEqual (sf, ar.surface)
#
#    def test_set_slice (self):
#        for bpp in (8, 16, 24, 32):
#            sf = pygame.Surface ((6, 8), 0, 32)
#            sf.fill ((0, 0, 0))
#            ar = pygame.PixelArray (sf)
#
#            # Test single value assignment
#            val = sf.map_rgb ((128, 128, 128))
#            ar[0:2] = val
#            self.assertEqual (ar[0][0], val)
#            self.assertEqual (ar[0][1], val)
#            self.assertEqual (ar[1][0], val)
#            self.assertEqual (ar[1][1], val)
#
#            val = sf.map_rgb ((0, 255, 255))
#            ar[-3:-1] = val
#            self.assertEqual (ar[3][0], val)
#            self.assertEqual (ar[-2][1], val)
#
#            val = sf.map_rgb ((255, 255, 0))
#            ar[-3:] = (255, 255, 0)
#            
#            self.assertEqual (ar[4][0], val)
#            self.assertEqual (ar[-1][1], val)
#
#            # Test list assignment.
#            val = sf.map_rgb ((0, 255, 0))
#            ar[2:4] = [val] * 8
#            self.assertEqual (ar[2][0], val)
#            self.assertEqual (ar[3][1], val)

if __name__ == '__main__':
    unittest.main()