def test_get_filename_obj(tmpdir): with tmpdir.as_cwd(): imgdir = build_img_dir(tmpdir, 'folderx') imgdir.join('abc.jpeg').write_binary(b'') imgdir.join('abc.jpg').write_binary(b'') imgdir.join('a-b.png').write_binary(b'') imgdir.join('ccc.bmp').write_binary(b'') xmldir = build_xml_dir(tmpdir, 'folderx') ex_xml = create_xml_data() xmldir.join('a.xml').write(ex_xml) app = testapp(server.app) ret = app.post_json('/api/get_filename_obj', {'username': '******', 'all': False}) #filename_list = [*ret.json['filename_list']] filename_obj = [] for key in ret.json['filename_obj']: filename_obj.append(key) undef_img_list = ret.json['undef_img_list'] dup_img_list = ret.json['dup_img_list'] print(filename_obj) print(undef_img_list) #assert filename_list ==['ccc.bmp','a.jpeg','b.jpg'] assert undef_img_list == ['a-b.png'] assert dup_img_list == ['abc.jpeg']
def test_get_thumbnail(tmpdir): with tmpdir.as_cwd(): imgdir = build_img_dir(tmpdir, 'folderx') im = Image.new("RGB", (512, 512)) im.save(imgdir.join('a.png').strpath, 'PNG') app = testapp(server.app) ret = app.get('/t/folderx/a.png') assert len(ret.body) == 94
def test_delete_xml(tmpdir): with tmpdir.as_cwd(): xmldir = build_xml_dir(tmpdir, 'folderx') ex_xml = create_xml_data() xmldir.join('target.xml').write(ex_xml) app = testapp(server.app) ret = app.post_json('/api/delete_xml', {'username': '******', 'target_filename': 'target.png'}) assert ret.json_body == {'result': 121}
def test_load_label_candidates_dict(tmpdir): with tmpdir.as_cwd(): xmldir = build_xml_dir(tmpdir, 'folderx') d = {'0': {'label': 'car', 'shortcut': '4'}} jsonfile = tmpdir.join(server.DIR_ROOT, 'folderx', server.SAVE_JSON_FILE_PATH) with open(jsonfile.strpath, 'w') as f: f.write(json.dumps(d)) app = testapp(server.app) ret = app.post_json('/api/load_label_candidates_dict', {'username': '******'}) assert ret.json_body == [{'id': 0, 'label': 'car', 'shortcut': '4'}]
def test_delete_annotation(tmpdir): with tmpdir.as_cwd(): xmldir = build_xml_dir(tmpdir, 'folderx') ex_xml = create_xml_data() xmldir.join('target.xml').write(ex_xml) app = testapp(server.app) ret = app.post_json('/api/delete_annotation', {'username': '******', 'target_filename': 'target.png', 'task_id': Task.DETECTION.value }) assert ret.json_body == {'xml_result': 121}
def test_save_label_candidates_dict(tmpdir): with tmpdir.as_cwd(): xmldir = build_xml_dir(tmpdir, 'folderx') app = testapp(server.app) app.post_json('/api/save_label_candidates_dict', {'username': '******', 'labels': [{'id': 0, 'label': 'car', 'shortcut': '4'}, {'id': 1, 'label': 'dhjs', 'shortcut': 'g'}]}) jsonfile = tmpdir.join(server.DIR_ROOT, 'folderx', server.SAVE_JSON_FILE_PATH) saved = json.load(open(jsonfile.strpath)) assert saved == {'0': {'label': 'car', 'shortcut': '4'}, '1': {'label': 'dhjs', 'shortcut': 'g'}}
def test_save_annotation(tmpdir): with tmpdir.as_cwd(): xmldir = build_xml_dir(tmpdir, 'folderx') json = {'task_id': Task.DETECTION.value, 'username': '******', 'value': {'annotation': {'path': 'a.jpg', 'source': { 'database': 'Unknown', 'comment': { 'admin': '', 'subord': '' }, 'reviewresult': '' }, 'size': {'width': 500, 'height': 375, 'depth': 3}, 'segments': 0, 'objects': [ {'object': {'name': 'asda', 'pose': 'Unspecified', 'truncated': 0, 'difficult': 0, 'bndbox': {'xmin': 10, 'xmax': 100, 'ymin': 20, 'ymax': 200 }}}]}}} app = testapp(server.app) app.post_json('/api/save_annotation', json) xml = xmldir.join('a.xml').read_text('utf8') d = xmltodict.parse(xml, xml_attribs=True) ann = d['annotation'] assert ann['path'] == 'a.jpg' assert ann['size']['width'] == '500' assert ann['size']['height'] == '375' assert ann['folder'] == 'dataset' assert ann['filename'] == 'a.jpg'
def test_make_dir(tmpdir): with tmpdir.as_cwd(): app = testapp(server.app) ret = app.post_json('/api/make_dir', {'working_dir': str(tmpdir), 'username': '******'}) assert ret.json_body == {'result': 111}