提交 6db878e8 编写于 作者: K Kentaro Wada

Add test for labelme/app.py

上级 14890e2c
# flake8: noqa
from labelme import testing
from labelme import utils
import json
import os.path as osp
import labelme.utils
def assert_labelfile_sanity(filename):
assert osp.exists(filename)
data = json.load(open(filename))
assert 'imagePath' in data
imageData = data.get('imageData', None)
if imageData is None:
assert osp.exists(data['imagePath'])
img = labelme.utils.img_b64_to_arr(imageData)
H, W = img.shape[:2]
assert 'shapes' in data
for shape in data['shapes']:
assert 'label' in shape
assert 'points' in shape
for x, y in shape['points']:
assert 0 <= x <= W
assert 0 <= y <= H
import os.path as osp
import shutil
import tempfile
import labelme.app
import labelme.testing
here = osp.dirname(osp.abspath(__file__))
data_dir = osp.join(here, 'data')
def test_MainWindow_open(qtbot):
win = labelme.app.MainWindow()
qtbot.addWidget(win)
win.show()
win.close()
def test_MainWindow_open_json(qtbot):
filename = osp.join(data_dir, 'apc2016_obj3.json')
labelme.testing.assert_labelfile_sanity(filename)
win = labelme.app.MainWindow(filename=filename)
qtbot.addWidget(win)
win.show()
win.close()
def test_MainWindow_annotate_jpg(qtbot):
tmp_dir = tempfile.mkdtemp()
filename = osp.join(tmp_dir, 'apc2016_obj3.jpg')
shutil.copy(osp.join(data_dir, 'apc2016_obj3.jpg'),
filename)
output = osp.join(tmp_dir, 'apc2016_obj3.json')
win = labelme.app.MainWindow(filename=filename, output=output)
qtbot.addWidget(win)
win.show()
def check_imageData():
assert hasattr(win, 'imageData')
assert win.imageData is not None
qtbot.waitUntil(check_imageData) # wait for loadFile
label = 'shelf'
points = [
(26, 70),
(176, 730),
(986, 742),
(1184, 102),
]
shape = label, points, None, None
shapes = [shape]
win.loadLabels(shapes)
win.saveFile()
labelme.testing.assert_labelfile_sanity(output)
......@@ -57,9 +57,9 @@ def test_LabelDialog_popUp(qtbot):
# popUp(text='cat')
def interact():
qtbot.keyClick(widget.edit, QtCore.Qt.Key_P) # enter 'p' for 'person'
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter)
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter)
qtbot.keyClick(widget.edit, QtCore.Qt.Key_P) # enter 'p' for 'person' # NOQA
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
QtCore.QTimer.singleShot(500, interact)
text = widget.popUp('cat')
......@@ -68,8 +68,8 @@ def test_LabelDialog_popUp(qtbot):
# popUp()
def interact():
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter)
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter)
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
QtCore.QTimer.singleShot(500, interact)
text = widget.popUp()
......@@ -78,9 +78,9 @@ def test_LabelDialog_popUp(qtbot):
# popUp() + key_Up
def interact():
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Up) # 'person' -> 'dog'
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter)
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter)
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Up) # 'person' -> 'dog' # NOQA
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
QtCore.QTimer.singleShot(500, interact)
text = widget.popUp()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册