def test_diff_refs_modified_file(self): repo_type = DATASETS mdpath = os.path.join(self.test_dir, '.ml-git', repo_type, 'metadata') entity = 'dataset-ex' specpath = os.path.join('vision-computer', 'images', entity) config_test = deepcopy(config) config_test['mlgit_path'] = '.ml-git' m = Metadata(entity, mdpath, config_test, repo_type) m.init() ensure_path_exists(os.path.join(mdpath, specpath, entity)) manifestpath = os.path.join(os.path.join(mdpath, specpath), 'MANIFEST.yaml') shutil.copy('hdata/dataset-ex.spec', os.path.join(mdpath, specpath, '{}.spec'.format(entity))) yaml_save(files_mock, manifestpath) sha1 = m.commit(manifestpath, 'test') files_mock_copy = deepcopy(files_mock) del files_mock_copy[ 'zdj7WZzR8Tw87Dx3dm76W5aehnT23GSbXbQ9qo73JgtwREGwB'] files_mock_copy['NewHash'] = {'7.jpg'} yaml_save(files_mock_copy, manifestpath) sha2 = m.commit(manifestpath, 'test') added_files, deleted_files, modified_file = m.diff_refs_with_modified_files( entity, sha1, sha2) self.assertTrue(len(added_files) == 0) self.assertTrue(len(deleted_files) == 0) self.assertTrue(len(modified_file) == 1)
def test_diff_refs_add_file(self): repo_type = DATASETS mdpath = os.path.join(self.test_dir, '.ml-git', repo_type, 'metadata') entity = 'dataset-ex' specpath = os.path.join('vision-computer', 'images', entity) config_test = deepcopy(config) config_test['mlgit_path'] = '.ml-git' m = Metadata(entity, mdpath, config_test, repo_type) m.init() ensure_path_exists(os.path.join(mdpath, specpath, entity)) manifestpath = os.path.join(os.path.join(mdpath, specpath), 'MANIFEST.yaml') shutil.copy('hdata/dataset-ex.spec', os.path.join(mdpath, specpath, '{}.spec'.format(entity))) yaml_save(files_mock, manifestpath) sha1 = m.commit(manifestpath, 'test') files_mock_copy = deepcopy(files_mock) files_mock_copy[ 'zPaksM5tNewHashQ2VABPvvfC3VW6wFRTWKvFhUW5QaDx6JMoma'] = { '11.jpg' } yaml_save(files_mock_copy, manifestpath) sha2 = m.commit(manifestpath, 'test') added_files, deleted_files, modified_file = m.diff_refs_with_modified_files( entity, sha1, sha2) self.assertTrue(len(added_files) == 1) self.assertTrue(len(deleted_files) == 0) self.assertTrue(len(modified_file) == 0)
def test_get_metrics(self): repo_type = MODELS mdpath = os.path.join(self.test_dir, 'mdata', repo_type, 'metadata') specpath = os.path.join('vision-computer', 'images') entity = 'model-ex' m = Metadata(entity, self.test_dir, config, repo_type) m.init() ensure_path_exists(os.path.join(mdpath, specpath, entity)) spec_metadata_path = os.path.join(mdpath, specpath, entity, 'model-ex.spec') shutil.copy('hdata/dataset-ex.spec', spec_metadata_path) spec_file = yaml_load(spec_metadata_path) spec_file[MODEL_SPEC_KEY] = deepcopy(spec_file[DATASET_SPEC_KEY]) del spec_file[DATASET_SPEC_KEY] spec_file[MODEL_SPEC_KEY]['metrics'] = {'metric_1': 0, 'metric_2': 1} yaml_save(spec_file, spec_metadata_path) tag = 'vision-computer__images__model-ex__1' sha = m.commit(spec_metadata_path, specpath) m.tag_add(tag) metrics = m._get_metrics(entity, sha) test_table = PrettyTable() test_table.field_names = ['Name', 'Value'] test_table.align['Name'] = 'l' test_table.align['Value'] = 'l' test_table.add_row(['metric_1', 0]) test_table.add_row(['metric_2', 1]) test_metrics = '\nmetrics:\n{}'.format(test_table.get_string()) self.assertEqual(metrics, test_metrics)
def test_get_spec_content_from_ref(self): mdpath = os.path.join(self.test_dir, 'mdata', DATASETS, 'metadata') specpath = 'dataset-ex' m = Metadata(specpath, self.test_dir, config, DATASETS) m.init() ensure_path_exists(os.path.join(mdpath, specpath)) spec_metadata_path = os.path.join(mdpath, specpath) + '/dataset-ex.spec' shutil.copy('hdata/dataset-ex.spec', spec_metadata_path) sha = m.commit(spec_metadata_path, specpath) tag = m.tag_add(sha) path = 'dataset-ex/dataset-ex.spec' content = yaml_load_str(m._get_spec_content_from_ref(tag.commit, path)) spec_file = yaml_load(spec_metadata_path) self.assertEqual(content, spec_file)
def test_get_specs_to_compare(self): mdpath = os.path.join(self.test_dir, 'mdata', DATASETS, 'metadata') specpath = 'dataset-ex' m = Metadata(specpath, self.test_dir, config, DATASETS) m.init() ensure_path_exists(os.path.join(mdpath, specpath)) spec_metadata_path = os.path.join(mdpath, specpath) + '/dataset-ex.spec' shutil.copy('hdata/dataset-ex.spec', spec_metadata_path) sha = m.commit(spec_metadata_path, specpath) m.tag_add(sha) specs = m.get_specs_to_compare(specpath) spec_file = yaml_load(spec_metadata_path) for c, v in specs: self.assertEqual(c, spec_file[DATASETS]['manifest']) self.assertIsNotNone(v, {DATASETS: {'manifest': {}}})
def test_get_metrics_without_metrics(self): repo_type = MODELS mdpath = os.path.join(self.test_dir, 'mdata', repo_type, 'metadata') specpath = os.path.join('vision-computer', 'images') entity = 'model-ex' m = Metadata(entity, self.test_dir, config, repo_type) m.init() ensure_path_exists(os.path.join(mdpath, specpath, entity)) spec_metadata_path = os.path.join(mdpath, specpath, entity) + '/model-ex.spec' shutil.copy('hdata/dataset-ex.spec', spec_metadata_path) spec_file = yaml_load(spec_metadata_path) spec_file[MODEL_SPEC_KEY] = deepcopy(spec_file[DATASET_SPEC_KEY]) del spec_file[DATASET_SPEC_KEY] yaml_save(spec_file, spec_metadata_path) tag = 'vision-computer__images__model-ex__1' sha = m.commit(spec_metadata_path, specpath) m.tag_add(tag) metrics = m._get_metrics(entity, sha) self.assertEqual(metrics, '')