mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-22 10:56:36 +00:00
Update test results directory structure and enhance Docker configurations
- Modified `.gitignore` to reflect the new path for test results. - Updated `docker-compose.test.yml` to mount the correct test results directory. - Adjusted `Dockerfile.test` to set the `PYTHONPATH` and ensure test results are saved in the updated location. - Added `boto3` and `netron` to `requirements-test.txt` to support new functionalities. - Updated `pytest.ini` to include the new `pythonpath` for test discovery. These changes streamline the testing process and ensure compatibility with the updated directory structure.
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
import random
|
||||
import shutil
|
||||
import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
if "matplotlib" not in sys.modules:
|
||||
_mpl = types.ModuleType("matplotlib")
|
||||
_plt = types.ModuleType("matplotlib.pyplot")
|
||||
_mpl.pyplot = _plt
|
||||
sys.modules["matplotlib"] = _mpl
|
||||
sys.modules["matplotlib.pyplot"] = _plt
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
@@ -41,6 +32,7 @@ def _augment_annotation_with_total(monkeypatch):
|
||||
def test_bt_aug_01_augment_inner_returns_eight_image_labels(
|
||||
tmp_path, monkeypatch, fixture_images_dir, fixture_labels_dir
|
||||
):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
_seed()
|
||||
from augmentation import Augmentator
|
||||
@@ -63,11 +55,14 @@ def test_bt_aug_01_augment_inner_returns_eight_image_labels(
|
||||
labels_path=str(proc_lbl),
|
||||
labels=labels,
|
||||
)
|
||||
# Act
|
||||
out = aug.augment_inner(img_ann)
|
||||
# Assert
|
||||
assert len(out) == 8
|
||||
|
||||
|
||||
def test_bt_aug_02_naming_convention(tmp_path, monkeypatch, fixture_images_dir, fixture_labels_dir):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
_seed()
|
||||
from augmentation import Augmentator
|
||||
@@ -89,7 +84,9 @@ def test_bt_aug_02_naming_convention(tmp_path, monkeypatch, fixture_images_dir,
|
||||
labels_path=str(proc_lbl),
|
||||
labels=labels,
|
||||
)
|
||||
# Act
|
||||
out = aug.augment_inner(img_ann)
|
||||
# Assert
|
||||
names = [Path(o.image_path).name for o in out]
|
||||
expected = [f"{stem}.jpg"] + [f"{stem}_{i}.jpg" for i in range(1, 8)]
|
||||
assert names == expected
|
||||
@@ -110,6 +107,7 @@ def _all_coords_in_unit(labels_list):
|
||||
def test_bt_aug_03_all_bbox_coords_in_zero_one(
|
||||
tmp_path, monkeypatch, fixture_images_dir, fixture_labels_dir
|
||||
):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
_seed()
|
||||
from augmentation import Augmentator
|
||||
@@ -131,7 +129,9 @@ def test_bt_aug_03_all_bbox_coords_in_zero_one(
|
||||
labels_path=str(proc_lbl),
|
||||
labels=labels,
|
||||
)
|
||||
# Act
|
||||
out = aug.augment_inner(img_ann)
|
||||
# Assert
|
||||
for o in out:
|
||||
for row in o.labels:
|
||||
assert len(row) >= 5
|
||||
@@ -139,13 +139,16 @@ def test_bt_aug_03_all_bbox_coords_in_zero_one(
|
||||
|
||||
|
||||
def test_bt_aug_04_correct_bboxes_clips_edge(tmp_path, monkeypatch):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
from augmentation import Augmentator
|
||||
|
||||
aug = Augmentator()
|
||||
m = aug.correct_margin
|
||||
inp = [[0.99, 0.5, 0.2, 0.1, 0]]
|
||||
# Act
|
||||
res = aug.correct_bboxes(inp)
|
||||
# Assert
|
||||
assert len(res) == 1
|
||||
x, y, w, h, _ = res[0]
|
||||
hw, hh = 0.5 * w, 0.5 * h
|
||||
@@ -156,18 +159,22 @@ def test_bt_aug_04_correct_bboxes_clips_edge(tmp_path, monkeypatch):
|
||||
|
||||
|
||||
def test_bt_aug_05_tiny_bbox_removed_after_clipping(tmp_path, monkeypatch):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
from augmentation import Augmentator
|
||||
|
||||
aug = Augmentator()
|
||||
inp = [[0.995, 0.5, 0.01, 0.5, 0]]
|
||||
# Act
|
||||
res = aug.correct_bboxes(inp)
|
||||
# Assert
|
||||
assert res == []
|
||||
|
||||
|
||||
def test_bt_aug_06_empty_label_eight_outputs_empty_labels(
|
||||
tmp_path, monkeypatch, fixture_images_dir
|
||||
):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
_seed()
|
||||
from augmentation import Augmentator
|
||||
@@ -187,7 +194,9 @@ def test_bt_aug_06_empty_label_eight_outputs_empty_labels(
|
||||
labels_path=str(proc_lbl),
|
||||
labels=[],
|
||||
)
|
||||
# Act
|
||||
out = aug.augment_inner(img_ann)
|
||||
# Assert
|
||||
assert len(out) == 8
|
||||
for o in out:
|
||||
assert o.labels == []
|
||||
@@ -196,6 +205,7 @@ def test_bt_aug_06_empty_label_eight_outputs_empty_labels(
|
||||
def test_bt_aug_07_full_pipeline_five_images_forty_outputs(
|
||||
tmp_path, monkeypatch, sample_images_labels
|
||||
):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
_augment_annotation_with_total(monkeypatch)
|
||||
_seed()
|
||||
@@ -211,7 +221,9 @@ def test_bt_aug_07_full_pipeline_five_images_forty_outputs(
|
||||
shutil.copy2(p, img_dir / p.name)
|
||||
for p in src_lbl.glob("*.txt"):
|
||||
shutil.copy2(p, lbl_dir / p.name)
|
||||
# Act
|
||||
Augmentator().augment_annotations()
|
||||
# Assert
|
||||
proc_img = Path(c.config.processed_images_dir)
|
||||
proc_lbl = Path(c.config.processed_labels_dir)
|
||||
assert len(list(proc_img.glob("*.jpg"))) == 40
|
||||
@@ -219,6 +231,7 @@ def test_bt_aug_07_full_pipeline_five_images_forty_outputs(
|
||||
|
||||
|
||||
def test_bt_aug_08_skips_already_processed(tmp_path, monkeypatch, sample_images_labels):
|
||||
# Arrange
|
||||
_patch_augmentation_paths(monkeypatch, tmp_path)
|
||||
_augment_annotation_with_total(monkeypatch)
|
||||
_seed()
|
||||
@@ -244,7 +257,9 @@ def test_bt_aug_08_skips_already_processed(tmp_path, monkeypatch, sample_images_
|
||||
dst = proc_img / p.name
|
||||
shutil.copy2(p, dst)
|
||||
markers.append(dst.read_bytes())
|
||||
# Act
|
||||
Augmentator().augment_annotations()
|
||||
# Assert
|
||||
after_jpgs = list(proc_img.glob("*.jpg"))
|
||||
assert len(after_jpgs) == 19
|
||||
assert len(list(proc_lbl.glob("*.txt"))) == 16
|
||||
|
||||
Reference in New Issue
Block a user