Пример #1
0
 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))
Пример #2
0
 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))
Пример #3
0
 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))
Пример #4
0
 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))
Пример #5
0
 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))