Coverage for scripts/tests/test_count_labels.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.10.2, created at 2025-08-07 15:22 +0000

1import os 

2import tempfile 

3from collections import Counter 

4from scripts.annotations.count_labels import count_class_ids # Replace with the actual module name 

5 

6def test_count_class_ids_basic(): 

7 # Create a temporary directory 

8 with tempfile.TemporaryDirectory() as temp_dir: 

9 # Create sample label files 

10 file1 = os.path.join(temp_dir, "file1.txt") 

11 file2 = os.path.join(temp_dir, "file2.txt") 

12 

13 with open(file1, "w") as f: 

14 f.write("1 0.5 0.5 0.1 0.1\n2 0.6 0.6 0.2 0.2\n") 

15 

16 with open(file2, "w") as f: 

17 f.write("1 0.1 0.1 0.3 0.3\n3 0.9 0.9 0.2 0.2\n") 

18 

19 result = count_class_ids(temp_dir) 

20 

21 expected = { 

22 '1': 2, 

23 '2': 1, 

24 '3': 1 

25 } 

26 

27 assert result == expected 

28 

29def test_count_class_ids_empty_file(): 

30 with tempfile.TemporaryDirectory() as temp_dir: 

31 file1 = os.path.join(temp_dir, "empty.txt") 

32 open(file1, "w").close() # Create empty file 

33 result = count_class_ids(temp_dir) 

34 assert result == {}