1010@pytest .mark .skipif (
1111 os .getenv ('VCAP_SERVICES' ) is None , reason = 'requires VCAP_SERVICES' )
1212class IntegrationTestVisualRecognitionV3 (TestCase ):
13- def setUp (self ):
14- self .visual_recognition = watson_developer_cloud .VisualRecognitionV3 (
13+ visual_recognition = None
14+ classifier_id = None
15+
16+ @classmethod
17+ def setup_class (cls ):
18+ cls .visual_recognition = watson_developer_cloud .VisualRecognitionV3 (
1519 '2016-05-20' , api_key = os .environ .get ('YOUR API KEY' ))
16- self .visual_recognition .set_default_headers ({
20+ cls .visual_recognition .set_default_headers ({
1721 'X-Watson-Learning-Opt-Out' :
1822 '1' ,
1923 'X-Watson-Test' :
2024 '1'
2125 })
22- self .classifier_id = 'CarsvsTrucksxDO_NOT_DELETE_771019274'
26+
27+ @classmethod
28+ def teardown_class (cls ):
29+ classifiers = cls .visual_recognition .list_classifiers ()['classifiers' ]
30+
31+ if classifiers :
32+ for classifier in classifiers :
33+ if 'CarsVsTrucks' in classifier ['name' ]:
34+ cls .visual_recognition .delete_classifier (classifier ['classifier_id' ])
2335
2436 def test_classify (self ):
25- car_path = join (dirname (__file__ ), '../../resources/cars.zip ' )
37+ car_path = join (dirname (__file__ ), '../../resources/dog.jpg ' )
2638 with open (car_path , 'rb' ) as images_file :
27- parameters = json .dumps ({
28- 'threshold' :
29- 0.1 ,
30- 'classifier_ids' : [self .classifier_id , 'default' ]
31- })
3239 car_results = self .visual_recognition .classify (
33- images_file = images_file , parameters = parameters )
40+ images_file = images_file ,
41+ threshold = '0.1' ,
42+ classifier_ids = ['default' ])
3443 assert car_results is not None
3544
3645 def test_detect_faces (self ):
@@ -45,7 +54,7 @@ def test_custom_classifier(self):
4554 with open (os .path .join (os .path .dirname (__file__ ), '../../resources/cars.zip' ), 'rb' ) as cars , \
4655 open (os .path .join (os .path .dirname (__file__ ), '../../resources/trucks.zip' ), 'rb' ) as trucks :
4756 classifier = self .visual_recognition .create_classifier (
48- 'Cars vs Trucks ' ,
57+ 'CarsVsTrucks ' ,
4958 cars_positive_examples = cars ,
5059 negative_examples = trucks ,
5160 )
@@ -56,9 +65,6 @@ def test_custom_classifier(self):
5665 output = self .visual_recognition .get_classifier (classifier_id )
5766 assert output is not None
5867
59- classifiers = self .visual_recognition .list_classifiers ()
60- assert classifiers is not None
61-
6268 output = self .visual_recognition .delete_classifier (classifier_id )
6369
6470 def test_core_ml_model (self ):
0 commit comments