Skip to content

Commit

Permalink
QtScheduler (ReactiveX#319)
Browse files Browse the repository at this point in the history
* Clean up .travis.yml a bit

* Re-order import preferences in Qt tests, fix absolute_schedule
  • Loading branch information
erikkemperman authored and dbrattli committed Mar 12, 2019
1 parent 0906ad3 commit b333440
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 43 deletions.
32 changes: 16 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ matrix:
python: 3.6
# Coverage for the baseline 3.6 build: include some optional packages
before_script:
- pip install eventlet gevent pyyaml tornado twisted
- pip3 install eventlet gevent pyyaml tornado twisted
# pycairo / pygobject need native libraries
- sudo apt-get install -y libgirepository1.0-dev gir1.2-gtk-3.0
- pip install pycairo pygobject
- pip3 install pycairo pygobject
script:
- coverage run --source=rx setup.py test
after_success:
- coveralls

- os: linux
dist: xenial
Expand All @@ -22,27 +26,23 @@ matrix:
python: 3.8-dev

- os: osx
osx_image: xcode8.3
language: python
python: 3.7-dev
osx_image: xcode10.1
language: sh
python: 3.7

- os: windows
python: 3.7-dev
language: sh
python: 3.7
before_install:
- choco install python3
- export PATH="/c/Python37:/c/Python37/Scripts:$PATH"
- ln -s "/c/Python37/python.exe" "/c/Python37/python3.exe"
- export PATH="/c/Python37:/c/Python37/Scripts/:$PATH"

install:
- python setup.py install
- pip install coveralls coverage
- pip install pytest>=3.0.2 pytest-asyncio pytest-cov --upgrade
- python3 setup.py install
- pip3 install coveralls coverage
- pip3 install pytest>=3.0.2 pytest-asyncio pytest-cov --upgrade

script:
- coverage run --source=rx setup.py test
- python3 setup.py test

after_success:
- if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PYTHON_VERSION" == 3.6* ]];
then
coveralls;
fi
8 changes: 2 additions & 6 deletions examples/timeflies/timeflies_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
from PySide2 import QtCore
from PySide2.QtWidgets import QApplication, QLabel, QWidget
except ImportError:
try:
from PyQt4 import QtCore
from PyQt4.QtGui import QWidget, QLabel, QApplication
except ImportError:
from PySide import QtCore
from PySide.QtGui import QWidget, QLabel, QApplication
from PyQt4 import QtCore
from PyQt4.QtGui import QWidget, QLabel, QApplication


class Window(QWidget):
Expand Down
68 changes: 47 additions & 21 deletions tests/test_concurrency/test_mainloopscheduler/test_qtscheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
from PyQt5.QtWidgets import QApplication
except ImportError:
try:
from PyQt4 import QtCore
from PyQt4.QtGui import QApplication
from PySide2 import QtCore
from PySide2.QtGui import QGuiApplication as QApplication
except ImportError:
try:
from PySide2 import QtCore
from PySide2.QtGui import QGuiApplication as QApplication
from PyQt4 import QtCore
from PyQt4.QtGui import QApplication
except ImportError:
skip = True


from rx.concurrency.mainloopscheduler import QtScheduler
if not skip:
from rx.concurrency.mainloopscheduler import QtScheduler

app = None # Prevent garbage collection

Expand All @@ -44,35 +44,59 @@ def test_qt_schedule_action(self):
app = make_app()

scheduler = QtScheduler(QtCore)
ran = [False]
ran = False

def action(scheduler, state):
ran[0] = True
nonlocal ran
ran = True
scheduler.schedule(action)

def done():
app.quit()
assert ran[0]
assert ran

QtCore.QTimer.singleShot(50, done)
app.exec_()

def test_qt_schedule_action_due(self):
def test_qt_schedule_action_due_relative(self):
app = make_app()

scheduler = QtScheduler(QtCore)
starttime = datetime.utcnow()
endtime = [None]
endtime = None

def action(scheduler, state):
endtime[0] = datetime.utcnow()
nonlocal endtime
endtime = datetime.utcnow()

scheduler.schedule_relative(0.2, action)

def done():
app.quit()
assert endtime[0]
diff = endtime[0] - starttime
assert endtime
diff = endtime - starttime
assert diff > timedelta(milliseconds=180)

QtCore.QTimer.singleShot(300, done)
app.exec_()

def test_qt_schedule_action_due_absolute(self):
app = make_app()

scheduler = QtScheduler(QtCore)
starttime = datetime.utcnow()
endtime = None

def action(scheduler, state):
nonlocal endtime
endtime = datetime.utcnow()

scheduler.schedule_absolute(starttime + timedelta(seconds=0.2), action)

def done():
app.quit()
assert endtime
diff = endtime - starttime
assert diff > timedelta(milliseconds=180)

QtCore.QTimer.singleShot(300, done)
Expand All @@ -81,17 +105,18 @@ def done():
def test_qt_schedule_action_cancel(self):
app = make_app()

ran = [False]
ran = False
scheduler = QtScheduler(QtCore)

def action(scheduler, state):
ran[0] = True
nonlocal ran
ran = True
d = scheduler.schedule_relative(0.1, action)
d.dispose()

def done():
app.quit()
assert not ran[0]
assert not ran

QtCore.QTimer.singleShot(300, done)
app.exec_()
Expand All @@ -101,18 +126,19 @@ def test_qt_schedule_action_periodic(self):

scheduler = QtScheduler(QtCore)
period = 0.050
counter = [3]
counter = 3

def action(state):
nonlocal counter
if state:
counter[0] -= 1
counter -= 1
return state - 1

scheduler.schedule_periodic(period, action, counter[0])
scheduler.schedule_periodic(period, action, counter)

def done():
app.quit()
assert counter[0] == 0
assert counter == 0

QtCore.QTimer.singleShot(300, done)
app.exec_()

0 comments on commit b333440

Please sign in to comment.