add unit testing via 'make test'
This commit is contained in:
parent
2beed27cf2
commit
b6d1929306
12
.travis.yml
12
.travis.yml
@ -24,7 +24,7 @@ matrix:
|
|||||||
before_install:
|
before_install:
|
||||||
- sudo pip install lxml
|
- sudo pip install lxml
|
||||||
- make qt4py2
|
- make qt4py2
|
||||||
- ( xvfb-run python2.7 labelImg.py ) & sleep 10 ; kill $!
|
- xvfb-run make testpy2
|
||||||
|
|
||||||
# Python 2 + QT5
|
# Python 2 + QT5
|
||||||
# disabled; can't get it to work
|
# disabled; can't get it to work
|
||||||
@ -47,7 +47,7 @@ matrix:
|
|||||||
# - sudo pip install lxml
|
# - sudo pip install lxml
|
||||||
# - pyrcc5 --help || true # does QT5 support python2 out of the box?
|
# - pyrcc5 --help || true # does QT5 support python2 out of the box?
|
||||||
# - make qt5py3
|
# - make qt5py3
|
||||||
# - ( xvfb-run python2.7 labelImg.py ) & sleep 10 ; kill $!
|
# - xvfb-run make testpy2
|
||||||
|
|
||||||
# Python 3 + QT4
|
# Python 3 + QT4
|
||||||
- os: linux
|
- os: linux
|
||||||
@ -69,7 +69,7 @@ matrix:
|
|||||||
- sudo apt-get install -y python3-pip
|
- sudo apt-get install -y python3-pip
|
||||||
- sudo pip3 install lxml
|
- sudo pip3 install lxml
|
||||||
- make qt4py3
|
- make qt4py3
|
||||||
- ( xvfb-run python3 labelImg.py ) & sleep 10 ; kill $!
|
- xvfb-run make testpy3
|
||||||
|
|
||||||
# Python 3 + QT5
|
# Python 3 + QT5
|
||||||
- os: linux
|
- os: linux
|
||||||
@ -90,7 +90,7 @@ matrix:
|
|||||||
- sudo apt-get install -y python3-pip
|
- sudo apt-get install -y python3-pip
|
||||||
- sudo pip3 install lxml
|
- sudo pip3 install lxml
|
||||||
- make qt5py3
|
- make qt5py3
|
||||||
- ( xvfb-run python3 labelImg.py ) & sleep 10 ; kill $!
|
- xvfb-run make testpy3
|
||||||
|
|
||||||
# OS X Python 3 + QT5
|
# OS X Python 3 + QT5
|
||||||
- os: osx
|
- os: osx
|
||||||
@ -112,7 +112,9 @@ matrix:
|
|||||||
- python3 -c 'import lxml'
|
- python3 -c 'import lxml'
|
||||||
- make qt5py3
|
- make qt5py3
|
||||||
- python3 -c 'help("modules")'
|
- 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:
|
script:
|
||||||
- exit 0
|
- exit 0
|
||||||
|
|||||||
10
Makefile
10
Makefile
@ -1,6 +1,15 @@
|
|||||||
|
# ex: set ts=8 noet:
|
||||||
|
|
||||||
all: qt4
|
all: qt4
|
||||||
|
|
||||||
|
test: testpy2
|
||||||
|
|
||||||
|
testpy2:
|
||||||
|
python -m unittest discover tests
|
||||||
|
|
||||||
|
testpy3:
|
||||||
|
python3 -m unittest discover tests
|
||||||
|
|
||||||
qt4: qt4py2
|
qt4: qt4py2
|
||||||
|
|
||||||
qt5: qt4py3
|
qt5: qt4py3
|
||||||
@ -14,3 +23,4 @@ qt4py3:
|
|||||||
qt5py3:
|
qt5py3:
|
||||||
pyrcc5 -o resources.py resources.qrc
|
pyrcc5 -o resources.py resources.qrc
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
|||||||
12
labelImg.py
12
labelImg.py
@ -1187,13 +1187,21 @@ def read(filename, default=None):
|
|||||||
except:
|
except:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def main(argv):
|
def get_main_app(argv=[]):
|
||||||
"""Standard boilerplate Qt application code."""
|
"""
|
||||||
|
Standard boilerplate Qt application code.
|
||||||
|
Do everything but app.exec_() -- so that we can test the application in one thread
|
||||||
|
"""
|
||||||
app = QApplication(argv)
|
app = QApplication(argv)
|
||||||
app.setApplicationName(__appname__)
|
app.setApplicationName(__appname__)
|
||||||
app.setWindowIcon(newIcon("app"))
|
app.setWindowIcon(newIcon("app"))
|
||||||
win = MainWindow(argv[1] if len(argv) == 2 else None)
|
win = MainWindow(argv[1] if len(argv) == 2 else None)
|
||||||
win.show()
|
win.show()
|
||||||
|
return app, win
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
'''construct main app and run it'''
|
||||||
|
app, _win = get_main_app(argv)
|
||||||
return app.exec_()
|
return app.exec_()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
21
tests/test.py
Normal file
21
tests/test.py
Normal 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
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user