def test_18_recover_corrupted_file_added(self): entity_init(DATASETS, self) add_file(self, DATASETS, '--bumpversion', 'new') corrupted_file = os.path.join(self.tmp_dir, DATASETS, DATASET_NAME, 'newfile0') with open(corrupted_file) as f: content = f.read() os.chmod(corrupted_file, S_IWUSR | S_IREAD) with open(corrupted_file, 'wb') as z: z.write(b'0' * 0) command_output = check_output( MLGIT_ADD % (DATASETS, DATASET_NAME, '--bumpversion')) self.assertIn(output_messages['WARN_CORRUPTED_CANNOT_BE_ADD'], command_output) self.assertIn('newfile0', command_output) os.chmod(corrupted_file, S_IWUSR | S_IREAD) with open(corrupted_file, 'w') as z: z.write(content) command_output = check_output( MLGIT_ADD % (DATASETS, DATASET_NAME, '--bumpversion')) self.assertNotIn(output_messages['WARN_CORRUPTED_CANNOT_BE_ADD'], command_output) self.assertNotIn('newfile0', command_output)
def test_14_add_with_ignore_file(self): entity_init(DATASETS, self) workspace = os.path.join(self.tmp_dir, DATASETS, DATASET_NAME) os.mkdir(os.path.join(workspace, 'data')) os.mkdir(os.path.join(workspace, 'ignored-folder')) create_file(workspace, 'image.png', '0') create_file(workspace, 'image2.jpg', '1', file_path='ignored-folder') create_file(workspace, 'file1', '0') create_file(workspace, 'file2', '1') create_ignore_file(workspace) output = check_output(MLGIT_ADD % (DATASETS, DATASET_NAME, '')) self.assertIn(output_messages['INFO_ADDING_PATH'] % DATASETS, output) self.assertNotIn(ERROR_MESSAGE, output) metadata = os.path.join(self.tmp_dir, ML_GIT_DIR, DATASETS, 'index', 'metadata', DATASET_NAME) metadata_file = os.path.join(metadata, 'MANIFEST.yaml') index_file = os.path.join(metadata, 'INDEX.yaml') ignore_file = os.path.join(metadata, MLGIT_IGNORE_FILE_NAME) self.assertTrue(os.path.exists(metadata_file)) self.assertTrue(os.path.exists(ignore_file)) self.assertTrue(os.path.exists(index_file)) self._check_index(index_file, ['data/file1', 'data/file2'], ['data/image.png', 'ignored-folder/image2.jpg'])
def test_06_create_with_wizard_enabled(self): entity_type = DATASETS entity_init(entity_type, self) add_file(self, entity_type, '--bumpversion', 'new') runner = CliRunner() result = runner.invoke(entity.datasets, ['create', 'ENTITY-NAME', '--wizard'], input='test\nstrict') self.assertIn(prompt_msg.CATEGORIES_MESSAGE, result.output)
def _commit_entity(self, entity_type): entity_init(entity_type, self) add_file(self, entity_type, '--bumpversion', 'new') self.assertIn(output_messages['INFO_COMMIT_REPO'] % (os.path.join(self.tmp_dir, ML_GIT_DIR, entity_type, 'metadata'), entity_type + '-ex'), check_output(MLGIT_COMMIT % (entity_type, entity_type + '-ex', ''))) HEAD = os.path.join(self.tmp_dir, ML_GIT_DIR, entity_type, 'refs', entity_type + '-ex', 'HEAD') self.assertTrue(os.path.exists(HEAD))
def set_up_test(self, repo_type=MODELS): self.TAG_TIMES = [] entity_name = '{}-ex'.format(repo_type) entity_init(repo_type, self) data_path = os.path.join(self.tmp_dir, repo_type, entity_name) create_file(data_path, 'file', '0', '') metrics_options = '--metric Accuracy 10 --metric Recall 10' self.assertNotIn( ERROR_MESSAGE, check_output(MLGIT_ADD % (repo_type, entity_name, metrics_options))) self.assertNotIn( ERROR_MESSAGE, check_output(MLGIT_COMMIT % (repo_type, entity_name, ''))) self._git_commit_time() metrics_options = '--metric Accuracy 20 --metric Recall 20' workspace = os.path.join(self.tmp_dir, repo_type, entity_name) os.makedirs(os.path.join(workspace, 'data')) create_file(workspace, 'file1', '0') self.assertNotIn( ERROR_MESSAGE, check_output(MLGIT_ADD % (repo_type, entity_name, metrics_options))) self.assertNotIn( ERROR_MESSAGE, check_output(MLGIT_COMMIT % (repo_type, entity_name, ' --version=2'))) self._git_commit_time()
def test_05_commit_with_wizard_enabled(self): entity_type = LABELS entity_init(entity_type, self) add_file(self, entity_type, '--bumpversion', 'new') runner = CliRunner() result = runner.invoke(entity.labels, ['commit', entity_type + '-ex', '--wizard'], input='\n'.join(['', 'message'])) self.assertIn(prompt_msg.COMMIT_VERSION.format('labels', '1'), result.output) self.assertIn(prompt_msg.COMMIT_MESSAGE, result.output)
def test_13_commit_with_invalid_related_entity_name(self): entity_type = MODELS entity_name = entity_type + '-ex' entity_init(entity_type, self) add_file(self, entity_type, '--bumpversion', 'new') self.assertIn(output_messages['ERROR_ENTITY_NOT_FIND'].format('wrong-entity'), check_output(MLGIT_COMMIT % (entity_type, entity_name, ' --labels=wrong-entity'))) HEAD = os.path.join(self.tmp_dir, ML_GIT_DIR, entity_type, 'refs', entity_name, 'HEAD') self.assertFalse(os.path.exists(HEAD))
def test_12_commit_with_empty_related_entity_name(self): entity_type = MODELS entity_name = entity_type + '-ex' entity_init(entity_type, self) add_file(self, entity_type, '--bumpversion', 'new') self.assertIn(output_messages['ERROR_INVALID_VALUE_FOR'] % ('--labels', 'Value cannot be empty'), check_output(MLGIT_COMMIT % (entity_type, entity_name, ' --labels='))) HEAD = os.path.join(self.tmp_dir, ML_GIT_DIR, entity_type, 'refs', entity_name, 'HEAD') self.assertFalse(os.path.exists(HEAD))
def test_19_commit_files_to_labels_with_wizard_enabled(self): entity_type = LABELS entity_init(entity_type, self) add_file(self, entity_type, '--bumpversion', 'new') runner = CliRunner() result = runner.invoke(entity.labels, ['commit', entity_type + '-ex', '--wizard'], input='\n'.join(['', 'message', 'y', ' ', 'dataset-ex'])) self.assertIn(prompt_msg.COMMIT_VERSION.format('labels', '1'), result.output) self.assertIn(prompt_msg.COMMIT_MESSAGE, result.output) self.assertIn(prompt_msg.WANT_LINK_TO_LABEL_ENTITY.format(parse_entity_type_to_singular(DATASETS)), result.output) self.assertIn(prompt_msg.DEFINE_LINKED_DATASET, result.output)
def test_06_add_command_with_corrupted_file_added(self): entity_init('dataset', self) add_file(self, 'dataset', '--bumpversion', 'new') corrupted_file = os.path.join(self.tmp_dir, 'dataset', 'dataset-ex', 'newfile0') os.chmod(corrupted_file, S_IWUSR | S_IREAD) with open(corrupted_file, 'wb') as z: z.write(b'0' * 0) self.assertIn(messages[67], check_output(MLGIT_ADD % ('dataset', 'dataset-ex', '--bumpversion')))
def test_16_commit_with_multiple_related_entities(self): entity_type = MODELS entity_name = entity_type + '-ex' entity_init(entity_type, self) add_file(self, entity_type, '--bumpversion', 'new') self.assertIn(output_messages['ERROR_OPTION_WITH_MULTIPLE_VALUES'].format('wrong-entity'), check_output(MLGIT_COMMIT % (entity_type, entity_name, ' --labels=A --labels=B'))) self.assertIn(output_messages['ERROR_OPTION_WITH_MULTIPLE_VALUES'], check_output(MLGIT_COMMIT % (entity_type, entity_name, ' --labels=A --labels=B'))) self.assertIn(output_messages['ERROR_OPTION_WITH_MULTIPLE_VALUES'], check_output(MLGIT_COMMIT % (entity_type, entity_name, ' --dataset=A --dataset=B'))) HEAD = os.path.join(self.tmp_dir, ML_GIT_DIR, entity_type, 'refs', entity_name, 'HEAD') self.assertFalse(os.path.exists(HEAD))
def test_09_commit_with_ignore_file(self): entity_init(DATASETS, self) workspace = os.path.join(self.tmp_dir, DATASETS, DATASET_NAME) os.mkdir(os.path.join(workspace, 'data')) create_file(workspace, 'image.png', '0') create_file(workspace, 'file1', '0') create_ignore_file(workspace) self.assertNotIn(ERROR_MESSAGE, check_output(MLGIT_ADD % (DATASETS, DATASET_NAME, ''))) self.assertNotIn(ERROR_MESSAGE, check_output(MLGIT_COMMIT % (DATASETS, DATASET_NAME, ''))) metadata = os.path.join(self.tmp_dir, ML_GIT_DIR, DATASETS, 'metadata', DATASET_NAME) manifest_file = os.path.join(metadata, 'MANIFEST.yaml') ignore_file = os.path.join(metadata, MLGIT_IGNORE_FILE_NAME) self.assertTrue(os.path.exists(ignore_file)) self.assertTrue(os.path.exists(manifest_file))
def set_up_test(self, repo_type=DATASETS, with_metrics=False): entity = '{}-ex'.format(repo_type) entity_init(repo_type, self) data_path = os.path.join(self.tmp_dir, repo_type, entity) create_file(data_path, 'file', '0', '') metrics_options = '' if with_metrics: metrics_options = '--metric Accuracy 1 --metric Recall 2' self.assertIn( output_messages['INFO_ADDING_PATH'] % repo_type, check_output(MLGIT_ADD % (repo_type, entity, metrics_options))) self.assertIn( output_messages['INFO_COMMIT_REPO'] % (os.path.join( self.tmp_dir, ML_GIT_DIR, repo_type, 'metadata'), entity), check_output(MLGIT_COMMIT % (repo_type, entity, '-m ' + self.COMMIT_MESSAGE)))
def test_13_add_entity_with_readme_file_in_data(self): entity_init(DATASETS, self) workspace = os.path.join(self.tmp_dir, DATASETS, DATASET_NAME) create_file(workspace, 'README.md', '0', file_path='') os.mkdir(os.path.join(workspace, 'data')) create_file(workspace, 'README.md', '0', file_path='data') output = check_output(MLGIT_ADD % (DATASETS, DATASET_NAME, '')) self.assertIn(output_messages['INFO_ADDING_PATH'] % DATASETS, output) self.assertNotIn(ERROR_MESSAGE, output) metadata = os.path.join(self.tmp_dir, ML_GIT_DIR, DATASETS, 'index', 'metadata', DATASET_NAME) metadata_file = os.path.join(metadata, 'MANIFEST.yaml') index_file = os.path.join(metadata, 'INDEX.yaml') self.assertTrue(os.path.exists(metadata_file)) self.assertTrue(os.path.exists(index_file))
def test_04_add_files_with_bumpversion(self): entity_init(DATASETS, self) add_file(self, DATASETS, '--bumpversion', 'new')
def test_03_add_files_to_labels(self): entity_init(LABELS, self) add_file(self, LABELS, '', 'new')
def test_02_add_files_to_model(self): entity_init(MODELS, self) add_file(self, MODELS, '', 'new')
def test_01_add_files_to_dataset(self): entity_init(DATASETS, self) add_file(self, DATASETS, '', 'new')
def test_14_first_commit_without_add(self): entity_type = DATASETS entity_init(entity_type, self) self.assertIn(output_messages['ERROR_COMMIT_WITHOUT_ADD'].format(DATASETS), check_output(MLGIT_COMMIT % (entity_type, entity_type + '-ex', ''))) HEAD = os.path.join(self.tmp_dir, ML_GIT_DIR, entity_type, 'refs', entity_type + '-ex', 'HEAD') self.assertFalse(os.path.exists(HEAD))
def test_01_add_files_to_dataset(self): entity_init('dataset', self) add_file(self, 'dataset', '', 'new')
def test_02_add_files_to_model(self): entity_init('model', self) add_file(self, 'model', '', 'new')
def test_03_add_files_to_labels(self): entity_init('labels', self) add_file(self, 'labels', '', 'new')
def test_04_add_files_with_bumpversion(self): entity_init('dataset', self) add_file(self, 'dataset', '--bumpversion', 'new')