Coverage for scripts/tests/test_bbox_seg.py: 100%
21 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 15:22 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 15:22 +0000
1import os
2import shutil
3from scripts.annotations.bbox_seg import convert_bbox_to_segmentation
5def test_convert_bbox_to_segmentation(tmp_path):
6 # Setup fake input and output directories
7 input_dir = tmp_path / "input"
8 output_dir = tmp_path / "output"
9 input_dir.mkdir()
10 output_dir.mkdir()
12 # Create a sample label file in YOLO bbox format
13 label_file = input_dir / "sample.txt"
14 with open(label_file, "w") as f:
15 f.write("0 0.5 0.5 0.4 0.2\n") # center_x, center_y, width, height
17 # Run the conversion
18 convert_bbox_to_segmentation(str(input_dir), str(output_dir))
20 # Check if output file exists
21 output_file = output_dir / "sample.txt"
22 assert output_file.exists(), "Output file not created."
24 # Check content of the output file
25 with open(output_file, "r") as f:
26 lines = f.readlines()
28 parts = lines[0].strip().split() #whitespace
29 assert parts[0] == "0"
30 assert len(parts[1:]) == 8 # 4 points × 2 coordinates
32 # Check that all coords are in range [0.0, 1.0]
33 coords = list(map(float, parts[1:]))
34 assert all(0.0 <= c <= 1.0 for c in coords), "Coords not in [0.0, 1.0]"