def test_connections_between_items_with_duplicated_uuids_are_connected_per_project( self): with create_memory_profile_context() as profile_context: profile = profile_context.create_profile() profile.add_project_memory() document_model = DocumentModel.DocumentModel(profile=profile) with contextlib.closing(document_model): data_item1 = DataItem.DataItem(numpy.ones((4, 4))) document_model.append_data_item(data_item1, project=profile.projects[0]) display_item1 = document_model.get_display_item_for_data_item( data_item1) data_item2 = DataItem.DataItem(numpy.ones((4, 4))) document_model.append_data_item(data_item2, project=profile.projects[0]) display_item2 = document_model.get_display_item_for_data_item( data_item2) connection = Connection.PropertyConnection(display_item1, "title", display_item2, "title", parent=data_item1) document_model.append_connection(connection) project_keys = list(profile_context.x_data_properties_map.keys()) profile_context.x_data_properties_map[ project_keys[1]] = copy.deepcopy( profile_context.x_data_properties_map[project_keys[0]]) profile_context.x_data_map[project_keys[1]] = copy.deepcopy( profile_context.x_data_map[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]] = copy.deepcopy( profile_context.x_project_properties[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]]["uuid"] = str(project_keys[1]) document_model = DocumentModel.DocumentModel( profile=profile_context.create_profile()) with contextlib.closing(document_model): project0 = document_model.profile.projects[0] project1 = document_model.profile.projects[1] self.assertEqual(4, len(document_model.data_items)) self.assertEqual(2, len(document_model.connections)) self.assertEqual(1, len(project0.connections)) self.assertEqual(1, len(project1.connections)) self.assertEqual(4, len(document_model.display_items)) self.assertEqual(2, len(project0.display_items)) self.assertEqual(2, len(project1.display_items)) for item in project0.connections[0].connected_items: self.assertEqual(project0, Project.get_project_for_item(item)) for item in project1.connections[0].connected_items: self.assertEqual(project1, Project.get_project_for_item(item))
def test_display_items_between_items_with_duplicated_uuids_are_connected_per_project( self): with create_memory_profile_context() as profile_context: profile = profile_context.create_profile() profile.add_project_memory() document_model = DocumentModel.DocumentModel(profile=profile) with contextlib.closing(document_model): data_item = DataItem.DataItem(numpy.ones((16, 1), numpy.float)) document_model.append_data_item(data_item, project=profile.projects[0]) data_item2 = DataItem.DataItem(numpy.ones((16, 1), numpy.float)) document_model.append_data_item(data_item2, project=profile.projects[0]) document_model.display_items[ 0].append_display_data_channel_for_data_item(data_item2) project_keys = list(profile_context.x_data_properties_map.keys()) profile_context.x_data_properties_map[ project_keys[1]] = copy.deepcopy( profile_context.x_data_properties_map[project_keys[0]]) profile_context.x_data_map[project_keys[1]] = copy.deepcopy( profile_context.x_data_map[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]] = copy.deepcopy( profile_context.x_project_properties[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]]["uuid"] = str(project_keys[1]) document_model = DocumentModel.DocumentModel( profile=profile_context.create_profile()) with contextlib.closing(document_model): project0 = document_model.profile.projects[0] project1 = document_model.profile.projects[1] self.assertEqual(4, len(document_model.data_items)) self.assertEqual(4, len(document_model.display_items)) self.assertEqual(2, len(project0.display_items)) self.assertEqual(2, len(project1.display_items)) self.assertEqual( 2, len( set(project0.display_items[0].data_items).intersection( set(project0.data_items)))) self.assertEqual( 2, len( set(project1.display_items[0].data_items).intersection( set(project1.data_items)))) for item in project0.display_items[0].data_items: self.assertEqual(project0, Project.get_project_for_item(item)) for item in project1.display_items[0].data_items: self.assertEqual(project1, Project.get_project_for_item(item))
def load_project(self, profile_context: typing.Optional[ProfileContext]) -> None: """Read project. The profile context is used during testing. """ if not self.project: # the project from the document model project: typing.Optional[Project.Project] = None # create project if it doesn't exist project_storage_system = self.make_storage(profile_context) if project_storage_system: project_storage_system.load_properties() project = Project.Project(project_storage_system) if project: self.__document_model = DocumentModel.DocumentModel( project, storage_cache=self.storage_cache) project.prepare_read_project() # sets up the uuid, used next. self.update_item_context(project) project.about_to_be_inserted(self) self.notify_property_changed( "project" ) # before reading, so document model has a chance to set up project.read_project() else: logging.getLogger("loader").warning( f"Project could not be loaded {self}.")
def test_computations_between_items_with_duplicated_uuids_are_connected_per_project( self): with create_memory_profile_context() as profile_context: profile = profile_context.create_profile() profile.add_project_memory() document_model = DocumentModel.DocumentModel(profile=profile) with contextlib.closing(document_model): data_item = DataItem.DataItem(numpy.ones((16, 16), numpy.float)) document_model.append_data_item(data_item, project=profile.projects[0]) document_model.get_invert_new( document_model.get_display_item_for_data_item(data_item)) project_keys = list(profile_context.x_data_properties_map.keys()) profile_context.x_data_properties_map[ project_keys[1]] = copy.deepcopy( profile_context.x_data_properties_map[project_keys[0]]) profile_context.x_data_map[project_keys[1]] = copy.deepcopy( profile_context.x_data_map[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]] = copy.deepcopy( profile_context.x_project_properties[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]]["uuid"] = str(project_keys[1]) # adjust the computations to be project-relative specifiers profile_context.x_project_properties[project_keys[0]][ "computations"][0]["variables"][0]["specifier"].pop( "context_uuid") profile_context.x_project_properties[project_keys[1]][ "computations"][0]["variables"][0]["specifier"].pop( "context_uuid") # now reload and make sure everything gets resolved properly document_model = DocumentModel.DocumentModel( profile=profile_context.create_profile()) with contextlib.closing(document_model): project0 = document_model.profile.projects[0] project1 = document_model.profile.projects[1] self.assertEqual(4, len(document_model.data_items)) self.assertEqual(2, len(document_model.computations)) self.assertEqual(1, len(project0.computations)) self.assertEqual(1, len(project1.computations)) for item in project0.computations[0].input_items: self.assertEqual(project0, Project.get_project_for_item(item)) for item in project1.computations[0].input_items: self.assertEqual(project1, Project.get_project_for_item(item))
def read_project_uuid( self, profile_context: typing.Optional["MemoryProfileContext"] = None ) -> typing.Optional[uuid.UUID]: project_storage_system = self.make_storage(profile_context) if project_storage_system: project_storage_system.load_properties() with contextlib.closing( Project.Project(project_storage_system)) as project: project.prepare_read_project() # sets up the uuid, used next. return project.uuid return None
def test_new_computation_is_bound_to_proper_project(self): with create_memory_profile_context() as profile_context: profile = profile_context.create_profile() profile.add_project_memory() document_model = DocumentModel.DocumentModel(profile=profile) with contextlib.closing(document_model): data_item = DataItem.DataItem(numpy.ones((16, 16), numpy.float)) document_model.append_data_item(data_item, project=profile.projects[0]) project_keys = list(profile_context.x_data_properties_map.keys()) profile_context.x_data_properties_map[ project_keys[1]] = copy.deepcopy( profile_context.x_data_properties_map[project_keys[0]]) profile_context.x_data_map[project_keys[1]] = copy.deepcopy( profile_context.x_data_map[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]] = copy.deepcopy( profile_context.x_project_properties[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]]["uuid"] = str(project_keys[1]) document_model = DocumentModel.DocumentModel( profile=profile_context.create_profile()) with contextlib.closing(document_model): project0 = document_model.profile.projects[0] project1 = document_model.profile.projects[1] document_model.get_invert_new( document_model.get_display_item_for_data_item( project0.data_items[0])) document_model.get_invert_new( document_model.get_display_item_for_data_item( project1.data_items[0])) for item in project0.computations[0].input_items: self.assertEqual(project0, Project.get_project_for_item(item)) for item in project1.computations[0].input_items: self.assertEqual(project1, Project.get_project_for_item(item))
def read_project_info( self, profile_context: typing.Optional[ProfileContext]) -> None: if not self.__has_project_info_been_read: try: project_storage_system = self.make_storage(profile_context) except Exception: project_storage_system = None if project_storage_system: project_storage_system.load_properties() with contextlib.closing( Project.Project(project_storage_system)) as project: if self.project_uuid != project.project_uuid: self.project_uuid = project.project_uuid self.__project_version = project.project_version self.__project_state = project.project_state self.__has_project_info_been_read = True
def read_project( self, existing_projects: typing.Sequence[Project.Project], profile_context: typing.Optional["MemoryProfileContext"] = None ) -> None: """Read the project if it is active. The profile context is used during testing. """ assert not self.__project if self.is_active: project_storage_system = self.make_storage(profile_context) if project_storage_system: project_storage_system.load_properties() self.__project = Project.Project(project_storage_system) else: logging.getLogger("loader").warning( f"Project could not be loaded {self}.") # do not allow multiple projects to load with same uuid existing_project_uuids = { project.uuid for project in existing_projects } if self.__project: self.__project.prepare_read_project( ) # sets up the uuid, used next. if not self.__project.uuid in existing_project_uuids and self.__project.uuid == self.project_uuid: self.update_item_context(self.__project) self.__project.about_to_be_inserted(self) self.notify_property_changed( "project" ) # before reading, so document model has a chance to set up self.__project.read_project() else: self.__project.close() self.__project = None
def test_undo_restores_item_with_proper_project(self): with create_memory_profile_context() as profile_context: profile = profile_context.create_profile() profile.add_project_memory() document_model = DocumentModel.DocumentModel(profile=profile) with contextlib.closing(document_model): data_item = DataItem.DataItem(numpy.ones((16, 16), numpy.float)) document_model.append_data_item(data_item, project=profile.projects[0]) project_keys = list(profile_context.x_data_properties_map.keys()) profile_context.x_data_properties_map[ project_keys[1]] = copy.deepcopy( profile_context.x_data_properties_map[project_keys[0]]) profile_context.x_data_map[project_keys[1]] = copy.deepcopy( profile_context.x_data_map[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]] = copy.deepcopy( profile_context.x_project_properties[project_keys[0]]) profile_context.x_project_properties[ project_keys[1]]["uuid"] = str(project_keys[1]) document_model = DocumentModel.DocumentModel( profile=profile_context.create_profile()) with contextlib.closing(document_model): project0 = document_model.profile.projects[0] project1 = document_model.profile.projects[1] for item in project0.display_items[0].data_items: assert item in document_model.data_items self.assertEqual(project0, Project.get_project_for_item(item)) for item in project1.display_items[0].data_items: assert item in document_model.data_items self.assertEqual(project1, Project.get_project_for_item(item)) assert project0.display_items[ 0] in document_model.display_items assert project1.display_items[ 0] in document_model.display_items with contextlib.closing( document_model.remove_data_item_with_log( project0.data_items[0], safe=True)) as undelete_log: document_model.undelete_all(undelete_log) assert project0.display_items[ 0] in document_model.display_items assert project1.display_items[ 0] in document_model.display_items for item in project0.display_items[0].data_items: assert item in document_model.data_items self.assertEqual(project0, Project.get_project_for_item(item)) for item in project1.display_items[0].data_items: assert item in document_model.data_items self.assertEqual(project1, Project.get_project_for_item(item)) with contextlib.closing( document_model.remove_data_item_with_log( project1.data_items[0], safe=True)) as undelete_log: document_model.undelete_all(undelete_log) assert project0.display_items[ 0] in document_model.display_items assert project1.display_items[ 0] in document_model.display_items for item in project0.display_items[0].data_items: assert item in document_model.data_items self.assertEqual(project0, Project.get_project_for_item(item)) for item in project1.display_items[0].data_items: assert item in document_model.data_items self.assertEqual(project1, Project.get_project_for_item(item))