Skip to content

Commit

Permalink
Merge pull request #1361 from hoechenberger/event
Browse files Browse the repository at this point in the history
TEST: Improve event.py tests
  • Loading branch information
peircej committed Mar 6, 2017
2 parents a3fa576 + 3c1d612 commit 5029631
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions psychopy/tests/test_misc/test_event.py
@@ -1,4 +1,5 @@

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from psychopy.visual import Window, ShapeStim
from psychopy import event, core, monitors
Expand All @@ -14,6 +15,7 @@
import copy
import threading
import os
import numpy as np

"""test with both pyglet and pygame:
cd psychopy/psychopy/
Expand Down Expand Up @@ -149,22 +151,20 @@ def test_keys(self):
assert result[0][0] == k
assert result[0][1] - delay < .01 # should be ~0 except for execution time

def test_misc(self):
assert event.xydist([0,0], [1,1]) == sqrt(2)
def test_xydist(self):
assert event.xydist([0,0], [1,1]) == np.sqrt(2)

def test_mouseMoved(self):

if travis:
pytest.skip() # failing on travis-ci

m = event.Mouse()
m.prevPos = [0,0]
m.lastPos = [0, 0]
m.prevPos[0] = 1 # fake movement
m.prevPos = [0, 0]
m.lastPos = [0, 1]
assert m.mouseMoved() # call to mouseMoved resets prev and last
m.prevPos = [0,0]
m.lastPos = [0, 0]
m.prevPos[0] = 1 # fake movement

m.prevPos = [0, 0]
m.lastPos = [0, 1]
assert m.mouseMoved(distance=0.5)
for reset in [True, 'here', (1,2)]:
assert not m.mouseMoved(reset=reset)
Expand Down Expand Up @@ -224,11 +224,17 @@ def setup_class(self):
mon.setWidth(40.0)
mon.setSizePix([1024,768])
self.win = Window([128,128], monitor=mon, winType='pyglet', pos=[50,50], autoLog=False)
assert pygame.display.get_init() == 0
if havePygame:
assert pygame.display.get_init() == 0

class xxxTestPygameNorm(_baseTest):
@classmethod
def setup_class(self):
self.win = Window([128,128], winType='pygame', pos=[50,50], autoLog=False)
assert pygame.display.get_init() == 1
assert event.havePygame


if __name__ == '__main__':
import pytest
pytest.main()

0 comments on commit 5029631

Please sign in to comment.