44from .common import upload_project
55import pytest
66
7-
87sa .init (Path .home () / ".superannotate" / "config.json" )
98PROJECT_NAME_VECTOR = 'ML Functionality Test Vector'
109PROJECT_NAME_PIXEL = 'ML Functionality Test Pixel'
1413
1514MODEL_NAME = 'Instance segmentation (trained on COCO)'
1615
16+
1717@pytest .mark .skipif (
1818 "SA_STRESS_TESTS" not in os .environ ,
1919 reason = "Requires env variable to be set"
2020)
2121def test_run_prediction ():
2222
2323 upload_project (
24- Path (PROJECT_PATH_VECTOR ) ,PROJECT_NAME_VECTOR , "Test for ml functionality" , "Vector"
24+ Path (PROJECT_PATH_VECTOR ), PROJECT_NAME_VECTOR ,
25+ "Test for ml functionality" , "Vector"
2526 )
2627
2728 upload_project (
28- Path (PROJECT_PATH_PIXEL ),PROJECT_NAME_PIXEL , "Test for ml functionality" , "Pixel"
29+ Path (PROJECT_PATH_PIXEL ), PROJECT_NAME_PIXEL ,
30+ "Test for ml functionality" , "Pixel"
2931 )
3032
3133 #Tests for the case when provided images do not exist in the project
3234 with pytest .raises (SABaseException ) as e :
33- sa .run_prediction (PROJECT_NAME_VECTOR , ["NonExistantImage.jpg" ], MODEL_NAME )
35+ sa .run_prediction (
36+ PROJECT_NAME_VECTOR , ["NonExistantImage.jpg" ], MODEL_NAME
37+ )
3438 assert str (e ) == "No valid image names were provided"
3539
3640 #Tests that the argument 'project' is valid
3741 with pytest .raises (SABaseException ) as e :
38- sa .run_prediction ([PROJECT_NAME_VECTOR , PROJECT_NAME_PIXEL ], ["DoesntMatter.jpg" ], MODEL_NAME )
39- assert str (e ) == "smart prediction cannot be run on images from different projects simultaneously"
42+ sa .run_prediction (
43+ [PROJECT_NAME_VECTOR , PROJECT_NAME_PIXEL ], ["DoesntMatter.jpg" ],
44+ MODEL_NAME
45+ )
46+ assert str (
47+ e
48+ ) == "smart prediction cannot be run on images from different projects simultaneously"
4049
4150 #Tests if prediction on all available images gets run
4251 image_names_pixel = sa .search_images (PROJECT_NAME_PIXEL )
4352 image_names_vector = sa .search_images (PROJECT_NAME_VECTOR )
4453
45- succeded_imgs , failed_imgs = sa .run_prediction (PROJECT_NAME_VECTOR , image_names_vector [:4 ], MODEL_NAME )
46- assert (len (succeded_imgs ) + len (failed_imgs )) == 4
47-
48- succeded_imgs , failed_imgs = sa .run_prediction (PROJECT_NAME_PIXEL ,image_names_pixel [:4 ], MODEL_NAME )
49- assert (len (succeded_imgs ) + len (failed_imgs )) == 4
54+ succeded_imgs , failed_imgs = sa .run_prediction (
55+ PROJECT_NAME_VECTOR , image_names_vector [:4 ], MODEL_NAME
56+ )
57+ assert (len (succeded_imgs ) + len (failed_imgs )) == 4
5058
51- succeded_imgs , failed_imgs = sa .run_prediction (PROJECT_NAME_PIXEL , image_names_pixel [:4 ] + ["NA.jpg" ], MODEL_NAME )
52- assert (len (succeded_imgs ) + len (failed_imgs )) == 4
59+ succeded_imgs , failed_imgs = sa .run_prediction (
60+ PROJECT_NAME_PIXEL , image_names_pixel [:4 ], MODEL_NAME
61+ )
62+ assert (len (succeded_imgs ) + len (failed_imgs )) == 4
5363
54- succeded_imgs , failed_imgs = sa .run_prediction (PROJECT_NAME_VECTOR , image_names_vector [:4 ] + ["NA.jpg" ], MODEL_NAME )
55- assert (len (succeded_imgs ) + len (failed_imgs )) == 4
64+ succeded_imgs , failed_imgs = sa .run_prediction (
65+ PROJECT_NAME_PIXEL , image_names_pixel [:4 ] + ["NA.jpg" ], MODEL_NAME
66+ )
67+ assert (len (succeded_imgs ) + len (failed_imgs )) == 4
5668
69+ succeded_imgs , failed_imgs = sa .run_prediction (
70+ PROJECT_NAME_VECTOR , image_names_vector [:4 ] + ["NA.jpg" ], MODEL_NAME
71+ )
72+ assert (len (succeded_imgs ) + len (failed_imgs )) == 4
5773
5874
5975@pytest .mark .skipif (
@@ -66,40 +82,46 @@ def test_run_segmentation():
6682 model_generic = 'generic'
6783
6884 upload_project (
69- Path (PROJECT_PATH_PIXEL ), PROJECT_NAME_PIXEL , "Test for ml functionality" , "Pixel"
85+ Path (PROJECT_PATH_PIXEL ), PROJECT_NAME_PIXEL ,
86+ "Test for ml functionality" , "Pixel"
7087 )
7188
7289 image_names_pixel = sa .search_images (PROJECT_NAME_PIXEL )
7390 with pytest .raises (SABaseException ) as e :
74- res = sa .run_segmentation (PROJECT_NAME_VECTOR , image_names_pixel , model_auto )
91+ res = sa .run_segmentation (
92+ PROJECT_NAME_VECTOR , image_names_pixel , model_auto
93+ )
7594 assert str (e ) == "Operation not supported for given project type"
7695 with pytest .raises (SABaseException ) as e :
7796 sa .run_segmentation (
7897 PROJECT_NAME_PIXEL , image_names_pixel [:2 ], "NonExistantModel"
79-
8098 )
8199 assert str (e ) == "Model Does not exist"
82100
83101 with pytest .raises (SABaseException ) as e :
84- sa .run_segmentation (PROJECT_NAME_PIXEL , ["NonExistantImage.jpg" ], MODEL_NAME )
102+ sa .run_segmentation (
103+ PROJECT_NAME_PIXEL , ["NonExistantImage.jpg" ], MODEL_NAME
104+ )
85105 assert str (e ) == "No valid image names were provided"
86106
87- succeded_imgs , failed_imgs = sa .run_segmentation (PROJECT_NAME_PIXEL , image_names_pixel [:4 ] + ["NA.jpg" ], model_generic )
88- assert (len (succeded_imgs ) + len (failed_imgs )) == 4
107+ succeded_imgs , failed_imgs = sa .run_segmentation (
108+ PROJECT_NAME_PIXEL , image_names_pixel [:4 ] + ["NA.jpg" ], model_generic
109+ )
110+ assert (len (succeded_imgs ) + len (failed_imgs )) == 4
89111
90- succeded_imgs , failed_imgs = sa .run_segmentation (ROJECT_NAME_PIXEL , image_names_pixel [:4 ] + ["NA.jpg" ], Pmodel_auto )
112+ succeded_imgs , failed_imgs = sa .run_segmentation (
113+ ROJECT_NAME_PIXEL , image_names_pixel [:4 ] + ["NA.jpg" ], Pmodel_auto
114+ )
115+
116+ assert (len (succeded_imgs ) + len (failed_imgs )) == 4
91117
92- assert (len (succeded_imgs ) + len (failed_imgs )) == 4
93118
94119def test_download_model (tmpdir ):
95120 print (tmpdir )
96121 export_dir = Path (tmpdir / 'export' )
97122 export_dir .mkdir (parents = True , exist_ok = True )
98123
99- ml_model = sa .search_models (include_global = True )[0 ]
124+ ml_model = sa .search_models (include_global = True )[0 ]
100125 Path .rmdir (Path (tmpdir ) / './export' )
101126 assert (sa .download_model (ml_model , './export' ) == True )
102127 assert (sa .download_model (ml_model ['name' ], './export' ) == True )
103-
104-
105-
0 commit comments