Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 650 lines (547 sloc) 25.143 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
#!/usr/bin/env python

import unittest
import VisionEgg
import VisionEgg.Core
import VisionEgg.FlowControl
import OpenGL.GL as gl

# for some specific test cases:
import VisionEgg.ParameterTypes
import VisionEgg.Dots
import VisionEgg.Gratings
import VisionEgg.MoreStimuli
import VisionEgg.SphereMap
import VisionEgg.Textures
import Numeric
import Image
import ImageDraw
import os
import time

# Use Python's bool constants if available, make aliases if not
try:
    True
except NameError:
    True = 1==1
    False = 1==0

# Define "sum" if it's not available as Python function
try:
    sum
except NameError:
    import operator
    def sum( values ):
        return reduce(operator.add, values )

# start logging to file
try:
    import logging
    import logging.handlers
except ImportError:
    import VisionEgg.py_logging as logging

log_fname = 'conform.log'
log_handler_logfile = logging.FileHandler( log_fname )
print "saving log file to",log_fname
log_handler_logfile.setFormatter( VisionEgg.log_formatter )
VisionEgg.logger.addHandler( log_handler_logfile )
 
  
    
class VETestCase(unittest.TestCase):
    def setUp(self):
        kw_params = {'size' : (512,512),
                     'fullscreen' : False,
                     'preferred_bpp' : 32,
                     'maxpriority' : False,
                     'hide_mouse' : False,
                     'frameless' : False,
                     'bgcolor' : (0.0, 0.0, 1.0),
                     'sync_swap' : True,
                     }
        try:
            self.screen = VisionEgg.Core.Screen( **kw_params )
        except Exception, x:
            try:
                kw_params['preferred_bpp'] = 24
                self.screen = VisionEgg.Core.Screen( **kw_params )
            except Exception, x:
                kw_params['preferred_bpp'] = 0
                self.screen = VisionEgg.Core.Screen( **kw_params )
        self.screen.clear()
        VisionEgg.Core.swap_buffers()
        self.ortho_viewport = VisionEgg.Core.Viewport( screen = self.screen )
        
    def tearDown(self):
        VisionEgg.Core.swap_buffers() # just for a brief flash...
        del self.screen

    def pickle_test(self, pickleable):
        import pickle
        a = pickleable
        a_pickle = pickle.dumps(a)
        a_test = pickle.loads(a_pickle)
        for attr_name in dir(a):
            if hasattr(a,attr_name):
                attr_orig = getattr(a,attr_name)
                attr_test = getattr(a_test,attr_name)
                self.failUnless(type(attr_orig) == type(attr_test))
                if hasattr(attr_orig,'__dict__'):
                    for k in attr_orig.__dict__.keys():
                        self.failUnless(type(attr_orig.__dict__[k]) == type(attr_test.__dict__[k]))

    def test_feedback_mode(self):
        l = 250
        r = 300
        b = 200
        t = 350
        
        stimulus = VisionEgg.MoreStimuli.Target2D(
            position=(l,b),
            anchor='lowerleft',
            size=(r-l,t-b),
            )
        
        self.ortho_viewport.parameters.stimuli = [ stimulus ]

        gl.glFeedbackBuffer(1000,gl.GL_3D)
        
        gl.glRenderMode( gl.GL_FEEDBACK )
        self.ortho_viewport.draw()
        feedback_buffer = gl.glRenderMode( gl.GL_RENDER )

        sent_verts = [(l,b,0),
                      (r,b,0),
                      (r,t,0),
                      (l,t,0)]
        recv_verts = feedback_buffer[0][1]

        self.failUnless( len(sent_verts) == len(recv_verts),
                         'feedback received wrong number of verts')

        for s,r in zip(sent_verts,recv_verts):
            s=Numeric.asarray(s)
            r=Numeric.asarray(r)
            diff = abs(s-r)
            err = sum(diff)
            self.failUnless( err < 1e-10,
                             'verts changed')
            
    def test_ve3d_simple(self):
        import VisionEgg.ThreeDeeMath as ve3d

        l = 250
        r = 300
        b = 200
        t = 350
        
        sent_verts = [(l,b,0),
                      (r,b,0),
                      (r,t,0),
                      (l,t,0)]

        recv_verts = self.ortho_viewport.eye_2_window(sent_verts)
        for s,r in zip(sent_verts,recv_verts):
            s=Numeric.asarray(s[:2]) # only testing 2D
            r=Numeric.asarray(r[:2]) # only testing 2D
            diff = abs(s-r)
            err = sum(diff)
            self.failUnless( err < 1e-10,
                             'verts changed')
            
    def test_ve3d_transforms1(self):
        import VisionEgg.ThreeDeeMath as ve3d
        
        gl.glMatrixMode(gl.GL_PROJECTION)

        # identity
        M = ve3d.TransformMatrix()
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'identity matrix different')

        # translate
        args=(10,20,30)
        M = ve3d.TransformMatrix()
        M.translate(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glTranslatef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'translation matrix different')
        
        # rotate
        args=(-22.5,10,20,-30)
        M = ve3d.TransformMatrix()
        M.rotate(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glRotatef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'rotation matrix different')

        # scale
        args=(1,10.5,123.2)
        M = ve3d.TransformMatrix()
        M.scale(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glScalef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'scale matrix different')
        
    def test_ve3d_transforms2(self):
        import VisionEgg.ThreeDeeMath as ve3d
        
        translate1 = (1,2,3)
        rotate = (45, 2, 5, 10)
        scale = (.1, 2.0, 4.0)
        translate2 = (-10,25,300)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glTranslatef(*translate1)
        gl.glRotatef(*rotate)
        gl.glScalef(*scale)
        gl.glTranslatef(*translate2)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)

        M = ve3d.TransformMatrix()
        M.translate(*translate1)
        M.rotate(*rotate)
        M.scale(*scale)
        M.translate(*translate2)
        ve3d_m = M.matrix

        diff = abs(gl_m-ve3d_m)
        err = sum(diff)
        self.failUnless( err < 1e-10,
                         'matrices different')
        
    def test_ve3d_mixed_transforms(self):
        import VisionEgg.ThreeDeeMath as ve3d

        l = 250
        r = 300
        b = 200
        t = 350
        
        stimulus = VisionEgg.MoreStimuli.Target2D(
            position=(l,b),
            anchor='lowerleft',
            size=(r-l,t-b),
            )

        # M mimics the projection matrix (modelview matrix is effectively identity)
        M = self.ortho_viewport.parameters.projection.get_matrix().copy()
        M = ve3d.TransformMatrix(M)
        M.translate(10,20,0)
        self.ortho_viewport.parameters.projection.translate(10,20,0)
        
        self.ortho_viewport.parameters.stimuli = [ stimulus ]

        gl.glFeedbackBuffer(1000,gl.GL_3D)
        
        gl.glRenderMode( gl.GL_FEEDBACK )
        self.ortho_viewport.draw()
        feedback_buffer = gl.glRenderMode( gl.GL_RENDER )

        sent_verts = [(l,b,0),
                      (r,b,0),
                      (r,t,0),
                      (l,t,0)]
        gl_recv_verts = feedback_buffer[0][1]

        clip_coords = M.transform_vertices( sent_verts )
        norm_device = ve3d.normalize_homogeneous_rows(clip_coords)
        ve3d_recv_verts = self.ortho_viewport.norm_device_2_window(norm_device)

        # check x and y coords
        for g,v in zip(gl_recv_verts,ve3d_recv_verts):
            g=Numeric.asarray(g[:2])
            v=Numeric.asarray(v[:2])
            diff = abs(g-v)
            err = sum(diff)
            self.failUnless( err < 1e-10,
                             'VisionEgg.ThreeDeeMath calculated window position wrong')
        
        # check z coord
        for g,v in zip(gl_recv_verts,ve3d_recv_verts):
            err = abs(g[2]-v[2])
            self.failUnless( err < 1e-10,
                             'VisionEgg.ThreeDeeMath calculated window depth wrong')
        
    def test_ClassWithParameters_pickle_ability(self):
        self.pickle_test( VisionEgg.ClassWithParameters() )
            
    def test_parameter_types_simple(self):
        ve_types = VisionEgg.ParameterTypes
        b = ve_types.Boolean
        ui = ve_types.UnsignedInteger
        i = ve_types.Integer
        r = ve_types.Real
        ve_types.assert_type(b,ui)
        ve_types.assert_type(b,i)
        ve_types.assert_type(b,r)
        ve_types.assert_type(ui,i)
        ve_types.assert_type(ui,r)
        ve_types.assert_type(i,r)

    def test_parameter_types_sequence(self):
        ve_types = VisionEgg.ParameterTypes
        sr = ve_types.Sequence( ve_types.Real )
        s4r = ve_types.Sequence4( ve_types.Real )
        s3r = ve_types.Sequence3( ve_types.Real )
        s2r = ve_types.Sequence2( ve_types.Real )
        ve_types.assert_type(s4r,sr)
        ve_types.assert_type(s3r,sr)
        ve_types.assert_type(s2r,sr)
        s4i = ve_types.Sequence4( ve_types.Integer )
        s3i = ve_types.Sequence3( ve_types.Integer )
        s2i = ve_types.Sequence2( ve_types.Integer )
        ve_types.assert_type(s4i,sr)
        ve_types.assert_type(s3i,sr)
        ve_types.assert_type(s2i,sr)
        
    def test_parameter_types_instance(self):
        ve_types = VisionEgg.ParameterTypes
        istim = ve_types.Instance( VisionEgg.Core.Stimulus )
        itext = ve_types.Instance( VisionEgg.Text.Text )
        ve_types.assert_type(itext,istim)
        
        class A: # classic classes
            pass
        class B(A):
            pass
        ia = ve_types.Instance( A )
        ib = ve_types.Instance( B )
        ve_types.assert_type(ib, ia)
        
        class An(object): # new style classes
            pass
        class Bn(An):
            pass
        ian = ve_types.Instance( An )
        ibn = ve_types.Instance( Bn )
        ve_types.assert_type(ibn, ian)

    def test_presentation_go(self):
        p = VisionEgg.FlowControl.Presentation(go_duration=(5,'frames'))
        p.go()

    def test_presentation_go_twice(self):
        p = VisionEgg.FlowControl.Presentation(go_duration=(5,'frames'))
        p.go()
        p.go() # check to make sure it works a second time

    def test_presentation_go_duration(self):
        p = VisionEgg.FlowControl.Presentation(go_duration=(1,'frames'))
        p.go()
        p.parameters.go_duration = (2,'frames')
        p.go()
        p.parameters.go_duration = (3,'frames')
        p.go()
        p.parameters.go_duration = (0,'frames')
        p.go()
        p.parameters.go_duration = (0.05,'seconds')
        p.go()

    def test_presentation_go_not(self):
        p = VisionEgg.FlowControl.Presentation(go_duration=(0,'frames'))
        p.go() # make sure it works with 0 duration

    def test_presentation_frame_drop_test(self):
        p = VisionEgg.FlowControl.Presentation(go_duration=(0,'frames'))
        p.go() # make sure it works with 0 duration
        p.were_frames_dropped_in_last_go_loop()
        self.failUnless(not p.were_frames_dropped_in_last_go_loop(),'frame drop test false positive')

        orig_framerate_setting = VisionEgg.config.VISIONEGG_MONITOR_REFRESH_HZ
        fake_hz = 200.0
        VisionEgg.config.VISIONEGG_MONITOR_REFRESH_HZ = fake_hz
        skip_frame = VisionEgg.FlowControl.FunctionController(
            during_go_func = lambda t: time.sleep(2.0/fake_hz))
        p.add_controller(None,None,skip_frame)
        p.parameters.go_duration = 3,'frames'
        orig_threshold = p.parameters.warn_longest_frame_threshold
        p.parameters.warn_longest_frame_threshold = 1.1
        p.go()
        p.remove_controller(None,None,skip_frame)
        
        VisionEgg.config.VISIONEGG_MONITOR_REFRESH_HZ = orig_framerate_setting
        p.parameters.warn_longest_frame_threshold = orig_threshold
        self.failUnless(p.were_frames_dropped_in_last_go_loop(),'missed simulated dropped frame')

    def test_core_screen_query_refresh_rate(self):
        fps = self.screen.query_refresh_rate()

    def test_core_screen_measure_refresh_rate(self):
        fps = self.screen.measure_refresh_rate()

    def test_core_refresh_rates_match(self):
        fps1 = self.screen.query_refresh_rate()
        # measure frame rate over a longish period for accuracy
        fps2 = self.screen.measure_refresh_rate(average_over_seconds=1.0)
        percent_diff = abs(fps1-fps2)/max(fps1,fps2)*100.0
        self.failUnless(percent_diff < 5.0,'measured (%.1f fps) and queried (%.1f fps) frame rates different (swap buffers may not be synced to vsync)'%(fps2,fps1))

    def test_core_fixation_spot(self):
        stimulus = VisionEgg.Core.FixationSpot()
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_dots_dotarea2d(self):
        stimulus = VisionEgg.Dots.DotArea2D()
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_gratings_singrating2d(self):
        stimulus = VisionEgg.Gratings.SinGrating2D()
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_gratings_singrating2d_2colors(self):
        stimulus = VisionEgg.Gratings.SinGrating2D(color1=(1,0,0),
                                                  color2=(0,0,1))
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_gratings_singrating2d_mask(self):
        mask = VisionEgg.Textures.Mask2D()
        stimulus = VisionEgg.Gratings.SinGrating2D(mask=mask)
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_spheremap_azelgrid(self):
        stimulus = VisionEgg.SphereMap.AzElGrid(my_viewport=self.ortho_viewport)
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_spheremap_spheremap(self):
        filename = os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,"data","az_el.png")
        texture = VisionEgg.Textures.Texture(filename)
        stimulus = VisionEgg.SphereMap.SphereMap(texture=texture,
                                                 shrink_texture_ok=True)
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_spheremap_spherewindow(self):
        stimulus = VisionEgg.SphereMap.SphereWindow()
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_texture_pil(self):
        width, height = self.screen.size
        orig = Image.new("RGB",(width,height),(255,0,0))
        orig_draw = ImageDraw.Draw(orig)
        # white cross
        orig_draw.line( (0,0,width,height), fill=(255,255,255) )
        orig_draw.line( (0,height,width,0), fill=(255,255,255) )
        # blue vertical line
        orig_draw.line( (10,0,10,height), fill=(0,0,255) )
        texture = VisionEgg.Textures.Texture(orig)
        result = texture.get_texels_as_image()
        self.failUnless(result.tostring()==orig.tostring(),'exact texture reproduction with PIL textures failed')

    def test_texture_stimulus_3d(self):
        stimulus = VisionEgg.Textures.TextureStimulus3D()
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_textures_spinning_drum(self):
        stimulus1 = VisionEgg.Textures.SpinningDrum()
        stimulus2 = VisionEgg.Textures.SpinningDrum()
        self.ortho_viewport.parameters.stimuli = [ stimulus1, stimulus2 ]
        self.ortho_viewport.draw()

    def test_textures_spinning_drum_flat(self):
        stimulus = VisionEgg.Textures.SpinningDrum(flat=1,
                                                   anchor='center',
                                                   )
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_textures_fixation_cross(self):
        stimulus = VisionEgg.Textures.FixationCross()
        self.ortho_viewport.parameters.stimuli = [ stimulus ]
        self.ortho_viewport.draw()

    def test_texture_stimulus_pil_rgb(self):
        width, height = self.screen.size
        orig = Image.new("RGB",(width,height),(0,255,0))
        orig_draw = ImageDraw.Draw(orig)
        # white cross
        orig_draw.line( (0,0,width,height), fill=(255,255,255) )
        orig_draw.line( (0,height,width,0), fill=(255,255,255) )
        # blue vertical line
        orig_draw.line( (10,0,10,height), fill=(0,0,255) )
        texture_stimulus = VisionEgg.Textures.TextureStimulus(
            texture = VisionEgg.Textures.Texture(orig),
            internal_format = gl.GL_RGB,
            position = (0,0),
            anchor = 'lowerleft',
            texture_min_filter = gl.GL_NEAREST, # XXX shouldn't have to do this!
            texture_mag_filter = gl.GL_NEAREST, # XXX shouldn't have to do this!
            )

        self.ortho_viewport.parameters.stimuli = [ texture_stimulus ]
        self.ortho_viewport.draw()
        result = self.screen.get_framebuffer_as_image(format=gl.GL_RGB)
        self.failUnless(result.tostring()==orig.tostring(),'exact texture stimulus reproduction with PIL RGB textures failed')

    def test_texture_stimulus_pil_rgba(self):
        width, height = self.screen.size
        
        # Note: all alpha should be 255 (=OpenGL 1.0) for this test to
        # work because otherwise the test image gets blended with
        # whatever OpenGL has in the background
        
        orig = Image.new("RGBA",(width,height),(0,255,0,255)) # green, full alpha background
        orig_draw = ImageDraw.Draw(orig)
        # white cross
        orig_draw.line( (0,0,width,height), fill=(255,255,255,255) )
        orig_draw.line( (0,height,width,0), fill=(255,255,255,255) )
        # blue vertical line
        orig_draw.line( (10,0,10,height), fill=(0,0,255,255) )
        # this breaks test (alpha != 255)
        # orig_draw.line( (20,0,20,height), fill=(0,0,255,127) )
        # orig_draw.line( (30,0,30,height), fill=(255,0,0,127) )
        texture_stimulus = VisionEgg.Textures.TextureStimulus(
            texture = VisionEgg.Textures.Texture(orig),
            internal_format = gl.GL_RGBA,
            position = (0,0),
            anchor = 'lowerleft',
            texture_min_filter = gl.GL_NEAREST, # XXX shouldn't have to do this!
            texture_mag_filter = gl.GL_NEAREST, # XXX shouldn't have to do this!
            )

        self.ortho_viewport.parameters.stimuli = [ texture_stimulus ]
        self.ortho_viewport.draw()
        result = self.screen.get_framebuffer_as_image(format=gl.GL_RGBA)
        self.failUnless(result.tostring()==orig.tostring(),'exact texture stimulus reproduction with PIL RGBA textures failed')

    def test_texture_stimulus_numpy_rgb(self):
        width, height = self.screen.size

        orig = Numeric.zeros((height,width,3),Numeric.UnsignedInt8)
        # sprinkle a few test pixels
        orig[ 4, 4, :]=255
        orig[ 6, 6, 0]=255
        orig[ 8, 8, 1]=127
        # more text pixels as border
        orig[ :, 0,:]=255
        orig[ :,-1,:]=255
        orig[ 0, :,:]=255
        orig[-1, :,:]=255
        texture_stimulus = VisionEgg.Textures.TextureStimulus(
            texture = VisionEgg.Textures.Texture(orig),
            internal_format = gl.GL_RGB,
            position = (0,0),
            anchor = 'lowerleft',
            mipmaps_enabled = False, # not (yet?) supported for Numeric arrays
            )

        self.ortho_viewport.parameters.stimuli = [ texture_stimulus ]
        self.ortho_viewport.draw()
        result = self.screen.get_framebuffer_as_array(format=gl.GL_RGB)
        orig_test = orig.astype(Numeric.Int) # allow signed addition
        result_test = result.astype(Numeric.Int) # allow signed addition
        abs_diff = sum(abs(Numeric.ravel(orig_test) - Numeric.ravel(result_test)))
        self.failUnless(abs_diff == 0,'exact texture reproduction with Numeric RGB textures failed')
        
    def test_texture_stimulus_numpy_rgba(self):
        width, height = self.screen.size

        orig = Numeric.zeros((height,width,4),Numeric.UnsignedInt8)
        
        # Note: all alpha should be 255 (=OpenGL 1.0) for this test to
        # work because otherwise the test image gets blended with
        # whatever OpenGL has in the background
        
        # set alpha all on
        orig[ :, :, 3]=255
        # sprinkle a few test pixels
        orig[ 4, 4, :]=255
        orig[ 6, 6, 0]=255
        orig[ 8, 8, 1]=127
        # alpha breaks the test:
        #orig[ 2, 2, 3]=0
        #orig[ 9, 9, 0]=255
        #orig[ 9, 9, 3]=127
        # more text pixels as border
        orig[ :, 0,:]=255
        orig[ :,-1,:]=255
        orig[ 0, :,:]=255
        orig[-1, :,:]=255
        texture_stimulus = VisionEgg.Textures.TextureStimulus(
            texture = VisionEgg.Textures.Texture(orig),
            internal_format = gl.GL_RGBA,
            position = (0,0),
            anchor = 'lowerleft',
            mipmaps_enabled = False, # not (yet?) supported for Numeric arrays
            )

        self.ortho_viewport.parameters.stimuli = [ texture_stimulus ]
        self.ortho_viewport.draw()
        result = self.screen.get_framebuffer_as_array(format=gl.GL_RGBA)

        orig_test = orig.astype(Numeric.Int) # allow signed addition
        result_test = result.astype(Numeric.Int) # allow signed addition

        abs_diff = sum(abs(Numeric.ravel(orig_test) - Numeric.ravel(result_test)))
        
        self.failUnless(abs_diff == 0,'exact texture reproduction with Numeric RGBA textures failed')
        
def suite():
    ve_test_suite = unittest.TestSuite()
    ve_test_suite.addTest( VETestCase("test_feedback_mode") )
    ve_test_suite.addTest( VETestCase("test_ve3d_simple") )
    ve_test_suite.addTest( VETestCase("test_ve3d_transforms1") )
    ve_test_suite.addTest( VETestCase("test_ve3d_transforms2") )
    ve_test_suite.addTest( VETestCase("test_ve3d_mixed_transforms") )
    ve_test_suite.addTest( VETestCase("test_ClassWithParameters_pickle_ability") )
    ve_test_suite.addTest( VETestCase("test_parameter_types_simple") )
    ve_test_suite.addTest( VETestCase("test_parameter_types_sequence") )
    ve_test_suite.addTest( VETestCase("test_parameter_types_instance") )
    ve_test_suite.addTest( VETestCase("test_presentation_go") )
    ve_test_suite.addTest( VETestCase("test_presentation_go_twice") )
    ve_test_suite.addTest( VETestCase("test_presentation_go_duration") )
    ve_test_suite.addTest( VETestCase("test_presentation_go_not") )
    ve_test_suite.addTest( VETestCase("test_presentation_frame_drop_test") )
    ve_test_suite.addTest( VETestCase("test_core_refresh_rates_match") )
    ve_test_suite.addTest( VETestCase("test_core_screen_query_refresh_rate") )
    ve_test_suite.addTest( VETestCase("test_core_screen_measure_refresh_rate") )
    ve_test_suite.addTest( VETestCase("test_core_fixation_spot") )
    ve_test_suite.addTest( VETestCase("test_dots_dotarea2d") )
    ve_test_suite.addTest( VETestCase("test_gratings_singrating2d") )
    ve_test_suite.addTest( VETestCase("test_gratings_singrating2d_mask") )
    ve_test_suite.addTest( VETestCase("test_gratings_singrating2d_2colors") )
    ve_test_suite.addTest( VETestCase("test_spheremap_azelgrid") )
    ve_test_suite.addTest( VETestCase("test_spheremap_spheremap") )
    ve_test_suite.addTest( VETestCase("test_spheremap_spherewindow") )
    ve_test_suite.addTest( VETestCase("test_texture_pil") )
    ve_test_suite.addTest( VETestCase("test_texture_stimulus_3d") )
    ve_test_suite.addTest( VETestCase("test_textures_spinning_drum") )
    ve_test_suite.addTest( VETestCase("test_textures_spinning_drum_flat") )
    ve_test_suite.addTest( VETestCase("test_textures_fixation_cross") )
    ve_test_suite.addTest( VETestCase("test_texture_stimulus_numpy_rgb") )
    ve_test_suite.addTest( VETestCase("test_texture_stimulus_numpy_rgba") )
    ve_test_suite.addTest( VETestCase("test_texture_stimulus_pil_rgb") )
    ve_test_suite.addTest( VETestCase("test_texture_stimulus_pil_rgba") )
    
    return ve_test_suite

runner = unittest.TextTestRunner()
runner.run(suite())
Something went wrong with that request. Please try again.