예제 #1
0
 def test_ndata_write_to_then_read_from_temp_file(self):
     document_model = DocumentModel.DocumentModel()
     with contextlib.closing(document_model):
         current_working_directory = os.getcwd()
         file_path = os.path.join(current_working_directory, "__file.ndata")
         handler = ImportExportManager.NDataImportExportHandler("ndata1-io-handler", "ndata", ["ndata"])
         data_item = DataItem.DataItem(numpy.zeros((16, 16), dtype=numpy.double))
         document_model.append_data_item(data_item)
         display_item = document_model.get_display_item_for_data_item(data_item)
         handler.write_display_item(None, display_item, file_path, "ndata")
         self.assertTrue(os.path.exists(file_path))
         try:
             data_items = handler.read_data_items(None, "ndata", file_path)
             self.assertEqual(len(data_items), 1)
             data_item = data_items[0]
         finally:
             os.remove(file_path)
예제 #2
0
 def test_ndata_write_to_then_read_from_temp_file(self):
     with TestContext.create_memory_context() as test_context:
         document_model = test_context.create_document_model()
         current_working_directory = os.getcwd()
         file_path = os.path.join(current_working_directory, "__file.ndata")
         handler = ImportExportManager.NDataImportExportHandler(
             "ndata1-io-handler", "ndata", ["ndata"])
         data_item = DataItem.DataItem(
             numpy.zeros((16, 16), dtype=numpy.double))
         document_model.append_data_item(data_item)
         display_item = document_model.get_display_item_for_data_item(
             data_item)
         handler.write_display_item(display_item, pathlib.Path(file_path),
                                    "ndata")
         self.assertTrue(os.path.exists(file_path))
         try:
             data_items = handler.read_data_items("ndata",
                                                  pathlib.Path(file_path))
             self.assertEqual(len(data_items), 1)
             data_item = data_items[0]
             for data_item in data_items:
                 data_item.close()
         finally:
             os.remove(file_path)