test_app.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_file = osp.join(tmp_dir, 'apc2016_obj3.json')
  27. config = labelme.config.get_default_config()
  28. win = labelme.app.MainWindow(
  29. config=config,
  30. filename=filename,
  31. output_file=output_file,
  32. )
  33. qtbot.addWidget(win)
  34. win.show()
  35. def check_imageData():
  36. assert hasattr(win, 'imageData')
  37. assert win.imageData is not None
  38. qtbot.waitUntil(check_imageData) # wait for loadFile
  39. label = 'shelf'
  40. points = [
  41. (26, 70),
  42. (176, 730),
  43. (986, 742),
  44. (1184, 102),
  45. ]
  46. shape = label, points, None, None, 'polygon', {}
  47. shapes = [shape]
  48. win.loadLabels(shapes)
  49. win.saveFile()
  50. labelme.testing.assert_labelfile_sanity(output_file)