def test_zipfile_bad_classes(self): with self.assertRaises(NnvisException): authorized_post(self.client, '/upload_dataset', self.access_token, data=dict(name=DATASET_NAME, description=DATASET_DESCRIPTION, file=good_zipfile_bad_classes()), mimetype='multipart/form-data')
def test_zipfile_noimgs(self): rv = authorized_post(self.client, '/upload_dataset', self.access_token, data=dict(name=DATASET_NAME, description=DATASET_DESCRIPTION, file=good_zipfile_noimgs()), mimetype='multipart/form-data') self.assertEqual(rv.status_code, 201) ds_id = self._assertDatasetCreated(1) self.assertEqual(len(Image.query.all()), 0) self.assertEqual(len(TrainingSample.query.all()), 0) dataset_folder = os.path.join(self.app.config['DATASET_FOLDER'], str(ds_id)) self.assertTrue(os.path.exists(dataset_folder)) dataset_files = os.listdir(dataset_folder) self.assertEqual(len(dataset_files), 2) self.assertIn(LABELS_FILENAME, dataset_files) self.assertIn(CLASSMAP_FILENAME, dataset_files) self._assertCsvContent(os.path.join(dataset_folder, LABELS_FILENAME), [['image', 'label', 'samplename']]) self._assertCsvContent(os.path.join(dataset_folder, CLASSMAP_FILENAME), [['class_number', 'class_name']])
def test_post(self): data = json.dumps({'name': 'new name', 'description': 'new desc'}) rv = authorized_post(self.client, '/arch/1', self.access_token, data=data, content_type='application/json') self.assertEqual(rv.status_code, 201) arch = Architecture.query.get(1) self.assertEqual(arch.name, 'new name') self.assertEqual(arch.description, 'new desc')
def test_noname(self): rv = authorized_post(self.client, '/upload_dataset', self.access_token, data=dict(description=DATASET_DESCRIPTION, file=bad_zipfile()), mimetype='multipart/form-data') rjson = response_json(rv) self.assertEqual(rv.status_code, 400) self.assertEqual(rjson['message'], 'Name for new dataset required')
def test_nofile(self): rv = authorized_post(self.client, '/upload_dataset', self.access_token, data=dict(name=DATASET_NAME, description=DATASET_DESCRIPTION), mimetype='multipart/form-data') rjson = response_json(rv) self.assertEqual(rv.status_code, 400) self.assertEqual(rjson['message'], 'No dataset file attached')
def test_zipfile_multiimg_samples(self): labels_content = [['img1', 'img2', 'img3', 'label', 'sample name'], ['01.jpg', '02.jpg', '03.jpg', '0', 'sample1'], ['04.jpg', '05.jpg', '06.jpg', '10', 'sample2'], ['69.jpg', '70.jpg', '71.jpg', '2', 'sample3']] classmap_content = [ ['class_number', 'class_name'], ['0', 'class0'], ['1', 'class1'], ['2', 'class2'], ['3', 'class3'], ['4', 'class4'], ['5', 'class5'], ['6', 'class6'], ['7', 'class7'], ['8', 'class8'], ['9', 'class9'], ['10', 'class10'], ] rv = authorized_post(self.client, '/upload_dataset', self.access_token, data=dict(name=DATASET_NAME, description=DATASET_DESCRIPTION, file=good_zipfile_imgs( labels_content, classmap_content)), mimetype='multipart/form-data') self.assertEqual(rv.status_code, 201) ds_id = self._assertDatasetCreated(3, labels=[ 'class0', 'class1', 'class2', 'class3', 'class4', 'class5', 'class6', 'class7', 'class8', 'class9', 'class10', ]) self._assertImagesCreated([ '01.jpg', '02.jpg', '03.jpg', '04.jpg', '05.jpg', '06.jpg', '69.jpg', '70.jpg', '71.jpg' ], 3) self._assertTrainingSamplesCreated(labels_content) dataset_folder = os.path.join(self.app.config['DATASET_FOLDER'], str(ds_id)) self.assertTrue(os.path.exists(dataset_folder)) dataset_files = os.listdir(dataset_folder) self.assertEqual(len(dataset_files), 11) self.assertIn('02.jpg', dataset_files) self.assertIn('01.jpg', dataset_files) self.assertIn('03.jpg', dataset_files) self.assertIn('04.jpg', dataset_files) self.assertIn('05.jpg', dataset_files) self.assertIn('06.jpg', dataset_files) self.assertIn('69.jpg', dataset_files) self.assertIn('70.jpg', dataset_files) self.assertIn('71.jpg', dataset_files) self.assertIn(LABELS_FILENAME, dataset_files) self.assertIn(CLASSMAP_FILENAME, dataset_files) self._assertCsvContent(os.path.join(dataset_folder, LABELS_FILENAME), labels_content) self._assertCsvContent(os.path.join(dataset_folder, CLASSMAP_FILENAME), classmap_content)