def test_42_graph_order_by_version_number(self): init_repository(DATASETS, self) self.create_file_in_ws(DATASETS, 'file', '1') api.add(DATASETS, DATASET_NAME, file_path=['file']) api.commit(DATASETS, DATASET_NAME) self.create_file_in_ws(DATASETS, 'file2', '1') api.add(DATASETS, DATASET_NAME, bumpversion=True, file_path=['file2']) api.commit(DATASETS, DATASET_NAME) self.create_file_in_ws(DATASETS, 'file3', '1') api.add(DATASETS, DATASET_NAME, file_path=['file3']) self.assertNotIn( ERROR_MESSAGE, check_output(MLGIT_COMMIT % (DATASETS, DATASET_NAME, '--version=10'))) local_manager = api.init_local_entity_manager() entities_relationships = local_manager.get_project_entities_relationships( export_type=FileType.DOT.value) graph_path = local_manager.export_graph(entities_relationships) self.assertTrue(os.path.exists(graph_path)) with open(graph_path, 'r') as graph_file: content = graph_file.read() self.assertIn( '\\"{} (1)\\" -> \\"{} (2)\\"'.format(DATASET_NAME, DATASET_NAME), content) self.assertIn( '\\"{} (2)\\" -> \\"{} (10)\\"'.format(DATASET_NAME, DATASET_NAME), content)
def test_38_local_export_graph(self): self.init_entities_with_relationships() model_name = 'models-ex' label_name = 'labels-ex' local_manager = api.init_local_entity_manager() entities_relationships = local_manager.get_project_entities_relationships( export_type=FileType.DOT.value) graph_path = local_manager.export_graph(entities_relationships) self.assertTrue(os.path.exists(graph_path)) with open(graph_path, 'r') as graph_file: content = graph_file.read() self.assertIn( '\\"{} (2)\\" -> \\"{} (1)\\"'.format(model_name, DATASET_NAME), content) self.assertIn( '\\"{} (1)\\" -> \\"{} (2)\\"'.format(model_name, model_name), content) self.assertIn( '\\"{} (2)\\" -> \\"{} (1)\\"'.format(model_name, label_name), content) self.assertIn( '\\"{} (1)\\" -> \\"{} (1)\\"'.format(label_name, DATASET_NAME), content)
def test_37_local_get_project_entities_relationships(self): self.init_entities_with_relationships() model_name = 'models-ex' label_name = 'labels-ex' tag = 'computer-vision__images__{}__1' local_manager = api.init_local_entity_manager() entities = local_manager.get_project_entities_relationships() self.assertIn(model_name, entities) relations = [e for e in entities[model_name] if e.version == 2] self.assertEqual(len(relations), 1) self.assertEqual(len(relations[0].relationships), 2) for r in relations[0].relationships: self.assertIn(r.name, [DATASET_NAME, label_name, model_name]) self.assertIn(r.tag, [ tag.format(DATASET_NAME), tag.format(label_name), tag.format(model_name) ]) relations = [e for e in entities[label_name] if e.version == 1] self.assertEqual(len(relations), 1) self.assertEqual(len(relations[0].relationships), 1) for r in relations[0].relationships: self.assertEqual(r.name, DATASET_NAME) self.assertEqual(r.tag, tag.format(DATASET_NAME))
def test_41_local_export_graph_empty_remote(self): self._initialize_entity('datasets') local_manager = api.init_local_entity_manager() local_manager.display_graph(export_path=os.getcwd()) output = ';'.join([record.message for record in self.caplog.records]) self.assertIn('Could not get the entities to list its relationships.', output)
def test_40_local_export_graph_without_relationships(self): self.init_entities_with_relationships(only_dataset=True) local_manager = api.init_local_entity_manager() entities_relationships = local_manager.get_project_entities_relationships( export_type=FileType.DOT.value) graph_path = local_manager.export_graph(entities_relationships) self.assertTrue(os.path.exists(graph_path)) with open(graph_path, 'r') as graph_file: content = graph_file.read() self.assertIn( '\\" {{ \\"{} (1)\\" [color=\\"{}\\"]; }}";'.format( DATASET_NAME, GraphEntityColors.DATASET_COLOR.value), content)
def test_35_local_get_linked_entities(self): self.init_entities_with_relationships() model_name = 'models-ex' label_name = 'labels-ex' local_manager = api.init_local_entity_manager() entities = local_manager.get_linked_entities(model_name, '2', MODELS) self.assertEqual(len(entities), 2) entities_name = [DATASET_NAME, label_name] for e in entities: self.assertIn(e.name, entities_name) self.assertEqual(e.version, '1') entities = local_manager.get_linked_entities(model_name, '1', MODELS) self.assertEqual(len(entities), 0)
def test_39_local_export_graph_without_entities(self): api.init('repository') self._clean_up_local_config() local_manager = api.init_local_entity_manager() local_manager.display_graph(export_path=os.getcwd()) output = ';'.join([record.message for record in self.caplog.records]) self.assertIn( output_messages['WARN_REPOSITORY_NOT_FOUND_FOR_ENTITY'] % 'datasets', output) self.assertIn( output_messages['WARN_REPOSITORY_NOT_FOUND_FOR_ENTITY'] % 'labels', output) self.assertIn( output_messages['WARN_REPOSITORY_NOT_FOUND_FOR_ENTITY'] % 'models', output) self.assertIn(output_messages['INFO_ENTITIES_RELATIONSHIPS_NOT_FOUND'], output)
def test_34_local_get_entity_versions(self): init_repository(DATASETS, self) self.create_file_in_ws(DATASETS, 'file', '1') api.add(DATASETS, DATASET_NAME, bumpversion=True, fsck=False, file_path=['file']) api.commit(DATASETS, DATASET_NAME) head = os.path.join(self.tmp_dir, ML_GIT_DIR, DATASETS, 'refs', DATASET_NAME, 'HEAD') self.assertTrue(os.path.exists(head)) self.create_file_in_ws(DATASETS, 'file2', '2') api.add(DATASETS, DATASET_NAME, bumpversion=True, fsck=False, file_path=['file2']) api.commit(DATASETS, DATASET_NAME) self.create_file_in_ws(DATASETS, 'file3', '3') api.add(DATASETS, DATASET_NAME, bumpversion=True, fsck=False, file_path=['file3']) api.commit(DATASETS, DATASET_NAME) tag = 'computer-vision__images__{}__'.format(DATASET_NAME) local_manager = api.init_local_entity_manager() spec_versions = local_manager.get_entity_versions( DATASET_NAME, DATASETS) self.assertEqual(len(spec_versions), 3) for spec_version in spec_versions: self.assertIn(spec_version.version, range(1, 4)) self.assertTrue(spec_version.tag.startswith(tag))
def test_33_local_get_entities(self): init_repository(DATASETS, self) self.create_file_in_ws(DATASETS, 'file', '1') api.add(DATASETS, DATASET_NAME, bumpversion=True, fsck=False, file_path=['file']) api.commit(DATASETS, DATASET_NAME) head = os.path.join(self.tmp_dir, ML_GIT_DIR, DATASETS, 'refs', DATASET_NAME, 'HEAD') self.assertTrue(os.path.exists(head)) tag = 'computer-vision__images__{}__1' label_name = 'labels-ex' init_repository(LABELS, self) self.create_file_in_ws(LABELS, 'file', '0') api.add(LABELS, label_name, bumpversion=True, fsck=False, file_path=['file']) api.commit(LABELS, label_name, related_dataset=DATASET_NAME) labels_metadata = os.path.join(self.tmp_dir, ML_GIT_DIR, LABELS, 'metadata') with open( os.path.join(labels_metadata, label_name, '{}.spec'.format(label_name))) as y: spec = yaml_processor.load(y) head = os.path.join(self.tmp_dir, ML_GIT_DIR, LABELS, 'refs', label_name, 'HEAD') self.assertTrue(os.path.exists(head)) self.assertEqual(tag.format(DATASET_NAME), spec[LABELS_SPEC_KEY][DATASET_SPEC_KEY]['tag']) model_name = 'models-ex' init_repository(MODELS, self) self.create_file_in_ws(MODELS, 'file', '0') api.add(MODELS, model_name, bumpversion=True, fsck=False, file_path=['file']) api.commit(MODELS, model_name, related_dataset=DATASET_NAME, related_labels=label_name) models_metadata = os.path.join(self.tmp_dir, ML_GIT_DIR, MODELS, 'metadata') with open( os.path.join(models_metadata, model_name, '{}.spec'.format(model_name))) as y: spec = yaml_processor.load(y) head = os.path.join(self.tmp_dir, ML_GIT_DIR, MODELS, 'refs', model_name, 'HEAD') self.assertTrue(os.path.exists(head)) self.assertEqual(tag.format(DATASET_NAME), spec[MODEL_SPEC_KEY][DATASET_SPEC_KEY]['tag']) self.assertEqual(tag.format(label_name), spec[MODEL_SPEC_KEY][LABELS_SPEC_KEY]['tag']) local_manager = api.init_local_entity_manager() entities = local_manager.get_entities() self.assertEqual(len(entities), 3) entities_name = [DATASET_NAME, label_name, model_name] for e in entities: self.assertIn(e.name, entities_name)
def graph(ctx, dot, export_path): check_project_exists(ctx) local_entity_manager = api.init_local_entity_manager() local_entity_manager.display_graph(export_path, dot)