add unit testing via 'make test'

This commit is contained in:
Ryan Flynn 2017-01-02 21:54:08 -05:00
parent 2beed27cf2
commit b6d1929306
4 changed files with 48 additions and 7 deletions

View File

@ -24,7 +24,7 @@ matrix:
before_install:
- sudo pip install lxml
- make qt4py2
- ( xvfb-run python2.7 labelImg.py ) & sleep 10 ; kill $!
- xvfb-run make testpy2
# Python 2 + QT5
# disabled; can't get it to work
@ -47,7 +47,7 @@ matrix:
# - sudo pip install lxml
# - pyrcc5 --help || true # does QT5 support python2 out of the box?
# - make qt5py3
# - ( xvfb-run python2.7 labelImg.py ) & sleep 10 ; kill $!
# - xvfb-run make testpy2
# Python 3 + QT4
- os: linux
@ -69,7 +69,7 @@ matrix:
- sudo apt-get install -y python3-pip
- sudo pip3 install lxml
- make qt4py3
- ( xvfb-run python3 labelImg.py ) & sleep 10 ; kill $!
- xvfb-run make testpy3
# Python 3 + QT5
- os: linux
@ -90,7 +90,7 @@ matrix:
- sudo apt-get install -y python3-pip
- sudo pip3 install lxml
- make qt5py3
- ( xvfb-run python3 labelImg.py ) & sleep 10 ; kill $!
- xvfb-run make testpy3
# OS X Python 3 + QT5
- os: osx
@ -112,7 +112,9 @@ matrix:
- python3 -c 'import lxml'
- make qt5py3
- python3 -c 'help("modules")'
- ( python3 labelImg.py ) & sleep 10 ; kill $!
#- make testpy3 # FIXME: does not work, segfault on travis-ci
# just make sure the app runs... :-/
- ( python3 labelImg.py ) & sleep 10; kill $!
script:
- exit 0

View File

@ -1,6 +1,15 @@
# ex: set ts=8 noet:
all: qt4
test: testpy2
testpy2:
python -m unittest discover tests
testpy3:
python3 -m unittest discover tests
qt4: qt4py2
qt5: qt4py3
@ -14,3 +23,4 @@ qt4py3:
qt5py3:
pyrcc5 -o resources.py resources.qrc
.PHONY: test

View File

@ -1187,13 +1187,21 @@ def read(filename, default=None):
except:
return default
def main(argv):
"""Standard boilerplate Qt application code."""
def get_main_app(argv=[]):
"""
Standard boilerplate Qt application code.
Do everything but app.exec_() -- so that we can test the application in one thread
"""
app = QApplication(argv)
app.setApplicationName(__appname__)
app.setWindowIcon(newIcon("app"))
win = MainWindow(argv[1] if len(argv) == 2 else None)
win.show()
return app, win
def main(argv):
'''construct main app and run it'''
app, _win = get_main_app(argv)
return app.exec_()
if __name__ == '__main__':

21
tests/test.py Normal file
View File

@ -0,0 +1,21 @@
from unittest import TestCase
from labelImg import get_main_app
class TestMainWindow(TestCase):
app = None
win = None
def setUp(self):
self.app, self.win = get_main_app()
def tearDown(self):
self.win.close()
self.app.quit()
def test_noop(self):
pass