test_app.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. filename = osp.join(data_dir, 'apc2016_obj3.json')
  17. labelme.testing.assert_labelfile_sanity(filename)
  18. win = labelme.app.MainWindow(filename=filename)
  19. qtbot.addWidget(win)
  20. win.show()
  21. win.close()
  22. def test_MainWindow_annotate_jpg(qtbot):
  23. if qtpy.QT_VERSION == 'pyqt4v2':
  24. # Fails to load image from JSON on Anaconda + Python2.7 + PyQt4
  25. return
  26. tmp_dir = tempfile.mkdtemp()
  27. filename = osp.join(tmp_dir, 'apc2016_obj3.jpg')
  28. shutil.copy(osp.join(data_dir, 'apc2016_obj3.jpg'),
  29. filename)
  30. output = osp.join(tmp_dir, 'apc2016_obj3.json')
  31. config = labelme.config.get_default_config()
  32. win = labelme.app.MainWindow(
  33. config=config, filename=filename, output=output)
  34. qtbot.addWidget(win)
  35. win.show()
  36. def check_imageData():
  37. assert hasattr(win, 'imageData')
  38. assert win.imageData is not None
  39. qtbot.waitUntil(check_imageData) # wait for loadFile
  40. label = 'shelf'
  41. points = [
  42. (26, 70),
  43. (176, 730),
  44. (986, 742),
  45. (1184, 102),
  46. ]
  47. shape = label, points, None, None
  48. shapes = [shape]
  49. win.loadLabels(shapes)
  50. win.saveFile()
  51. labelme.testing.assert_labelfile_sanity(output)