AMMICO/misinformation/test/test_objects.py
Petr Andriushchenko a5c43b6488
Test debugging (#62)
* deleted lavis from utils

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixed test_objects

* added 'not gcv' to CI

* fixed multimodal search and summary tests

* disable doc build on PR for now

* restrict ipywidgets version to avoid dummycomm error

* limit deepface version

* original repositories for retinaface lavis

* update gcv test results

* update display test outputs

* update test env

* run all tests

* wo xdist to avoid segfault

* remove widgets ref

* skip long-running tests

* skip long

* verbose codecov upload

* refactor summary test 2

* finish summary test refactor

* reduce memory overhead of SummaryDetector

* remove VQA models from self

* remove VQA models from self

* update notebook for changes

* update notebook for changes

* fixed multimodal search tests

* fixed tests in multimodal search after precommit

* run all tests

* update doc notebook for summary changes

* skip long-running multimodal

* exclude blip2 from testing

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Inga Ulusoy <inga.ulusoy@uni-heidelberg.de>
2023-03-30 10:33:05 +02:00

94 строки
2.6 KiB
Python

import json
import pytest
import misinformation.objects as ob
import misinformation.objects_cvlib as ob_cvlib
OBJECT_1 = "cell phone"
OBJECT_2 = "motorcycle"
OBJECT_3 = "traffic light"
TEST_IMAGE_1 = "IMG_2809.png"
JSON_1 = "example_objects_cvlib.json"
@pytest.fixture()
def default_objects():
return ob.init_default_objects()
def test_objects_from_cvlib(default_objects):
objects_list = [OBJECT_1, OBJECT_2, OBJECT_3]
objects = ob_cvlib.objects_from_cvlib(objects_list)
out_objects = default_objects
for obj in objects_list:
out_objects[obj] = "yes"
assert str(objects) == str(out_objects)
def test_analyse_image_cvlib(get_path):
mydict = {"filename": get_path + TEST_IMAGE_1}
ob_cvlib.ObjectCVLib().analyse_image(mydict)
with open(get_path + JSON_1, "r") as file:
out_dict = json.load(file)
out_dict["filename"] = get_path + out_dict["filename"]
for key in mydict.keys():
assert mydict[key] == out_dict[key]
def test_init_default_objects():
default_obj_list = [
"person",
"bicycle",
"car",
OBJECT_2,
"airplane",
"bus",
"train",
"truck",
"boat",
OBJECT_3,
OBJECT_1,
]
init_objects = ob_cvlib.init_default_objects()
for obj in default_obj_list:
assert init_objects[obj] == "no"
def test_analyse_image_from_file_cvlib(get_path):
file_path = get_path + TEST_IMAGE_1
objs = ob_cvlib.ObjectCVLib().analyse_image_from_file(file_path)
with open(get_path + JSON_1, "r") as file:
out_dict = json.load(file)
out_dict["filename"] = get_path + out_dict["filename"]
for key in objs.keys():
assert objs[key] == out_dict[key]
def test_detect_objects_cvlib(get_path):
file_path = get_path + TEST_IMAGE_1
objs = ob_cvlib.ObjectCVLib().detect_objects_cvlib(file_path)
with open(get_path + JSON_1, "r") as file:
out_dict = json.load(file)
for key in objs.keys():
assert objs[key] == out_dict[key]
def test_set_keys(default_objects, get_path):
mydict = {"filename": get_path + TEST_IMAGE_1}
key_objs = ob.ObjectDetector(mydict).set_keys()
assert str(default_objects) == str(key_objs)
def test_analyse_image(get_path):
mydict = {"filename": get_path + TEST_IMAGE_1}
ob.ObjectDetector.set_client_to_cvlib()
ob.ObjectDetector(mydict).analyse_image()
with open(get_path + JSON_1, "r") as file:
out_dict = json.load(file)
out_dict["filename"] = get_path + out_dict["filename"]
assert str(mydict) == str(out_dict)