test_app.py 1.4 KB

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