diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 037d5423..73ab5ddc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,8 +58,8 @@ jobs: run: | pytest --junitxml report.xml --cov=. -m "not integration_tests" - - name: "Upload coverage to Codecov" - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: true + # - name: Upload coverage reports to Codecov + # uses: codecov/codecov-action@v4.0.1 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # slug: makseq/label-studio-converter diff --git a/tests/test_export_yolo.py b/tests/test_export_yolo.py index b85bb150..38043aa0 100644 --- a/tests/test_export_yolo.py +++ b/tests/test_export_yolo.py @@ -1,9 +1,12 @@ -from label_studio_converter import Converter import os import pytest import tempfile import shutil + from label_studio_converter.utils import convert_annotation_to_yolo, convert_annotation_to_yolo_obb +from label_studio_converter import Converter +from .utils import almost_equal_1d, almost_equal_2d + BASE_DIR = os.path.dirname(__file__) TEST_DATA_PATH = os.path.join(BASE_DIR, "data", "test_export_yolo") @@ -136,18 +139,18 @@ def test_convert_to_yolo_obb(create_temp_folder): ), f"Generated file: \n {generated_paths} \n does not match expected ones: \n {expected_paths}" # Check all the annotations have been converted to yolo - axpected_annotations = [23, 1, 1] + expected_annotations = [23, 1, 1] for fidx, file in enumerate(expected_paths): with open(file) as f: lines = f.readlines() - assert len(lines) == axpected_annotations[fidx], f"Expect different number of annotations in file {file}." + assert len(lines) == expected_annotations[fidx], f"Expect different number of annotations in file {file}." for idx, line in enumerate(lines): parameters = line.split(' ') total_parameters = len(parameters) assert total_parameters == 9, f'Expected 9 parameters but got {total_parameters} in line {idx}' def test_convert_polygons_to_yolo(create_temp_folder): - """Check converstion label_studio json exported file to yolo with polygons""" + """Check conversion label_studio json exported file to yolo with polygons""" # Generates a temporary folder and return the absolute path # The temporary folder contains all the data generate by the following function @@ -184,7 +187,6 @@ def test_convert_polygons_to_yolo(create_temp_folder): len(lines) == 1 ), f"Expect different number of annotations in file {file}." - def test_convert_annotation_to_yolo_format(): """ Verify conversion from LS annotation to normalized Yolo format. @@ -228,7 +230,9 @@ def test_convert_annotation_to_yolo_format(): for idx, annotation in enumerate(annotations): result = convert_annotation_to_yolo(annotation) - assert result == expectations[idx], f'Converted LS annotation to normalized Yolo format does not match expected result at index {idx}' + assert almost_equal_1d( + result, expectations[idx] + ), f'Converted LS annotation to normalized Yolo format does not match expected result at index {idx}' def test_convert_invalid_annotation_to_yolo_format(): """ @@ -271,7 +275,7 @@ def test_convert_invalid_annotation_to_yolo_format(): for idx, annotation in enumerate(annotations): result = convert_annotation_to_yolo(annotation) - assert result == None, f'Expected annotation at index {idx} to be invalid' + assert result is None, f'Expected annotation at index {idx} to be invalid' def test_convert_annotation_to_yolo_obb_format(): @@ -340,7 +344,10 @@ def test_convert_annotation_to_yolo_obb_format(): for idx, annotation in enumerate(annotations): result = convert_annotation_to_yolo_obb(annotation) - assert result == expectations[idx], f'Converted LS annotation to normalized Yolo OBB-format does not match expected result at index {idx}' + print('result = ', result) + assert almost_equal_2d( + result, expectations[idx] + ), f'Converted LS annotation to normalized Yolo OBB-format does not match expected result at index {idx}' def test_convert_invalid_annotation_to_yolo_obb_format(): """ @@ -421,4 +428,4 @@ def test_convert_invalid_annotation_to_yolo_obb_format(): for idx, annotation in enumerate(annotations): result = convert_annotation_to_yolo_obb(annotation) - assert result == None, f'Expected annotation for OBB at index {idx} to be invalid' \ No newline at end of file + assert result is None, f'Expected annotation for OBB at index {idx} to be invalid' diff --git a/tests/test_import_yolo.py b/tests/test_import_yolo.py index 7df762df..13366de0 100644 --- a/tests/test_import_yolo.py +++ b/tests/test_import_yolo.py @@ -33,8 +33,8 @@ def test_base_import_yolo(): #generated labels from config xml label_element = ET.parse(out_config_file).getroot()[2] - lables_generated = [x.attrib['value'] for x in label_element.getchildren()] - assert set(labels) == set(lables_generated), "> generated class labels do not match original labels" + labels_generated = [x.attrib['value'] for x in label_element.getchildren()] + assert set(labels) == set(labels_generated), "> generated class labels do not match original labels" #total image files in the input folder img_files = glob.glob(os.path.join(input_data_dir,'images','*')) @@ -72,9 +72,9 @@ def test_base_import_yolo_with_img_dims(): # generated labels from config xml label_element = ET.parse(out_config_file).getroot()[2] - lables_generated = [x.attrib['value'] for x in label_element.getchildren()] + labels_generated = [x.attrib['value'] for x in label_element.getchildren()] assert set(labels) == set( - lables_generated + labels_generated ), "> generated class labels do not match original labels" #total image files in the input folder diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 00000000..1af8d47f --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,10 @@ +import math + + +def almost_equal_1d(a, b, tol=1e-9): + return all(math.isclose(x, y, abs_tol=tol) for x, y in zip(a, b)) + +def almost_equal_2d(a, b, tol=1e-9): + a = [z for x in a for z in x] + b = [z for x in b for z in x] + return all(math.isclose(x, y, abs_tol=tol) for x, y in zip(a, b)) \ No newline at end of file