test_app.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os.path as osp
  2. import shutil
  3. import tempfile
  4. import labelme.app
  5. import labelme.testing
  6. here = osp.dirname(osp.abspath(__file__))
  7. data_dir = osp.join(here, 'data')
  8. def test_MainWindow_open(qtbot):
  9. win = labelme.app.MainWindow()
  10. qtbot.addWidget(win)
  11. win.show()
  12. win.close()
  13. def test_MainWindow_open_json(qtbot):
  14. filename = osp.join(data_dir, 'apc2016_obj3.json')
  15. labelme.testing.assert_labelfile_sanity(filename)
  16. win = labelme.app.MainWindow(filename=filename)
  17. qtbot.addWidget(win)
  18. win.show()
  19. win.close()
  20. def test_MainWindow_annotate_jpg(qtbot):
  21. tmp_dir = tempfile.mkdtemp()
  22. filename = osp.join(tmp_dir, 'apc2016_obj3.jpg')
  23. shutil.copy(osp.join(data_dir, 'apc2016_obj3.jpg'),
  24. filename)
  25. output = osp.join(tmp_dir, 'apc2016_obj3.json')
  26. win = labelme.app.MainWindow(filename=filename, output=output)
  27. qtbot.addWidget(win)
  28. win.show()
  29. def check_imageData():
  30. assert hasattr(win, 'imageData')
  31. assert win.imageData is not None
  32. qtbot.waitUntil(check_imageData) # wait for loadFile
  33. label = 'shelf'
  34. points = [
  35. (26, 70),
  36. (176, 730),
  37. (986, 742),
  38. (1184, 102),
  39. ]
  40. shape = label, points, None, None
  41. shapes = [shape]
  42. win.loadLabels(shapes)
  43. win.saveFile()
  44. labelme.testing.assert_labelfile_sanity(output)