test_app.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os.path as osp
  2. import shutil
  3. import tempfile
  4. import qtpy
  5. import labelme.app
  6. import labelme.config
  7. import labelme.testing
  8. here = osp.dirname(osp.abspath(__file__))
  9. data_dir = osp.join(here, 'data')
  10. def test_MainWindow_open(qtbot):
  11. win = labelme.app.MainWindow()
  12. qtbot.addWidget(win)
  13. win.show()
  14. win.close()
  15. def test_MainWindow_open_json(qtbot):
  16. if qtpy.PYQT4:
  17. # Fails to load image from JSON on Anaconda + Python2.7 + PyQt4
  18. return
  19. filename = osp.join(data_dir, 'apc2016_obj3.json')
  20. labelme.testing.assert_labelfile_sanity(filename)
  21. win = labelme.app.MainWindow(filename=filename)
  22. qtbot.addWidget(win)
  23. win.show()
  24. win.close()
  25. def test_MainWindow_annotate_jpg(qtbot):
  26. if qtpy.PYQT4:
  27. # Fails to load image from JSON on Anaconda + Python2.7 + PyQt4
  28. return
  29. tmp_dir = tempfile.mkdtemp()
  30. filename = osp.join(tmp_dir, 'apc2016_obj3.jpg')
  31. shutil.copy(osp.join(data_dir, 'apc2016_obj3.jpg'),
  32. filename)
  33. output = osp.join(tmp_dir, 'apc2016_obj3.json')
  34. config = labelme.config.get_default_config()
  35. win = labelme.app.MainWindow(
  36. config=config, filename=filename, output=output)
  37. qtbot.addWidget(win)
  38. win.show()
  39. def check_imageData():
  40. assert hasattr(win, 'imageData')
  41. assert win.imageData is not None
  42. qtbot.waitUntil(check_imageData) # wait for loadFile
  43. label = 'shelf'
  44. points = [
  45. (26, 70),
  46. (176, 730),
  47. (986, 742),
  48. (1184, 102),
  49. ]
  50. shape = label, points, None, None
  51. shapes = [shape]
  52. win.loadLabels(shapes)
  53. win.saveFile()
  54. labelme.testing.assert_labelfile_sanity(output)