Skip to content

Commit ae045ac

Browse files
committed
fixup! fixup! fixup! fixup! Trying to make it cross platform
1 parent 98ff2bd commit ae045ac

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/util/test_folderparser.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import json
2+
import os
23
import unittest
3-
from os.path import abspath, dirname
44

55
from roboflow.util import folderparser
66

7-
thisdir = dirname(abspath(__file__))
7+
thisdir = os.path.dirname(os.path.abspath(__file__))
8+
9+
10+
def _find_test_image(image, images):
11+
image = image.replace("/", os.sep)
12+
return next(i for i in images if i["file"] == image)
813

914

1015
class TestFolderParser(unittest.TestCase):
@@ -18,15 +23,15 @@ def test_parse_sharks_coco(self):
1823
parsed = folderparser.parsefolder(sharksfolder)
1924
testImagePath = "/train/sharks_mp4-20_jpg.rf.90ba2e8e9ca0613f71359efb7ed48b26.jpg"
2025
print("PARSED", parsed["images"])
21-
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
26+
testImage = _find_test_image(testImagePath, parsed["images"])
2227
assert len(json.loads(testImage["annotationfile"]["rawText"])["annotations"]) == 5
2328

2429
def test_parse_sharks_createml(self):
2530
sharksfolder = f"{thisdir}/../datasets/sharks-tiny-createml"
2631
parsed = folderparser.parsefolder(sharksfolder)
2732
print("PARSED", parsed["images"])
2833
testImagePath = "/train/sharks_mp4-20_jpg.rf.5359121123e86e016401ea2731e47949.jpg"
29-
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
34+
testImage = _find_test_image(testImagePath, parsed["images"])
3035
imgParsedAnnotations = json.loads(testImage["annotationfile"]["rawText"])
3136
assert len(imgParsedAnnotations) == 1
3237
imgReference = imgParsedAnnotations[0]
@@ -36,7 +41,7 @@ def test_parse_sharks_yolov9(self):
3641
def test(sharksfolder):
3742
parsed = folderparser.parsefolder(sharksfolder)
3843
testImagePath = "/train/images/sharks_mp4-20_jpg.rf.5359121123e86e016401ea2731e47949.jpg"
39-
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
44+
testImage = _find_test_image(testImagePath, parsed["images"])
4045
expectAnnotationFile = "/train/labels/sharks_mp4-20_jpg.rf.5359121123e86e016401ea2731e47949.txt"
4146
assert testImage["annotationfile"]["file"] == expectAnnotationFile
4247
assert testImage["annotationfile"]["labelmap"] == {0: "fish", 1: "primary", 2: "shark"}
@@ -48,7 +53,7 @@ def test_parse_mosquitos_csv(self):
4853
folder = f"{thisdir}/../datasets/mosquitos"
4954
parsed = folderparser.parsefolder(folder)
5055
testImagePath = "/train_10308.jpeg"
51-
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
56+
testImage = _find_test_image(testImagePath, parsed["images"])
5257
assert testImage["annotationfile"]["name"] == "annotation.csv"
5358
expected = "img_fName,img_w,img_h,class_label,bbx_xtl,bbx_ytl,bbx_xbr,bbx_ybr\n"
5459
expected += "train_10308.jpeg,1058,943,japonicus/koreicus,28,187,908,815\n"
@@ -58,7 +63,7 @@ def test_paligemma_format(self):
5863
folder = f"{thisdir}/../datasets/paligemma"
5964
parsed = folderparser.parsefolder(folder)
6065
testImagePath = "/dataset/de48275e1ff70fab78bee31e09fc896d_png.rf.01a97b1ad053aa1e6525ac0451cee8b7.jpg"
61-
testImage = [i for i in parsed["images"] if i["file"] == testImagePath][0]
66+
testImage = _find_test_image(testImagePath, parsed["images"])
6267
assert testImage["annotationfile"]["name"] == "annotation.jsonl"
6368
expected = (
6469
'{"image": "de48275e1ff70fab78bee31e09fc896d_png.rf.01a97b1ad053aa1e6525ac0451cee8b7.jpg",'

0 commit comments

Comments
 (0)