Esempio n. 1
0
    def testSaveAndLoad(self):
        h5 = open_file(self.path, mode='w')
        for order in self.orders:
            saveExecutionOrder(h5, order)
        h5.close()

        h5 = open_file(self.path)
        orders = loadExecutionOrders(h5)
        h5.close()
        self.assertEquals(sorted(orders), sorted(self.orders))
Esempio n. 2
0
 def testGetHTTPFile(self):
     host = "pyphant.sourceforge.net"
     remote_dir = ""
     url = "http://" + host + remote_dir + "/knowledgemanager-http-test.h5"
     # Get remote file and load DataContainer
     filename, headers = urllib.urlretrieve(url)
     h5 = open_file(filename, 'r')
     for g in h5.walk_groups("/results"):
         if (len(g._v_attrs.TITLE)>0) \
                 and (r"\Psi" in g._v_attrs.shortname):
             http_fc = ptp.loadField(h5, g)
     h5.close()
     km = KnowledgeManager.getInstance()
     km.registerURL(url, temporary=True)
     km_fc = km.getDataContainer(http_fc.id)
     self.assertEqual(http_fc, km_fc)
     os.remove(filename)
Esempio n. 3
0
 def testGetLocalFile(self):
     h5fileid, h5name = tempfile.mkstemp(suffix='.h5', prefix='test-')
     os.close(h5fileid)
     h5 = open_file(h5name, 'w')
     resultsGroup = h5.create_group("/", "results")
     ptp.saveResult(self._fc, h5)
     h5.close()
     km = KnowledgeManager.getInstance()
     from urllib import pathname2url
     url = pathname2url(h5name)
     if not url.startswith('///'):
         url = '//' + url
     url = 'file:' + url
     km.registerURL(url, temporary=True)
     km_fc = km.getDataContainer(self._fc.id)
     self.assertEqual(self._fc, km_fc)
     os.remove(h5name)
Esempio n. 4
0
 def __init__(self, filename, mode='a'):
     """
     Opens an HDF5 file.
     filename -- path to the file that should be opened
     mode -- mode in which file is opened. Possible values: 'r', 'w', 'a'
             meaning 'read only', 'overwrite' and 'append'.
             'a' is only allowed for files that are valid HDF5 files
             already.
     """
     assert mode in ['r', 'w', 'a']
     exists = os.path.isfile(filename)
     if mode == 'r' and not exists:
         raise IOError("File '%s' does not exist!" % (filename, ))
     self.filename = filename
     self.mode = mode
     if mode == 'w':
         tmphandle = tables_version_handler.open_file(self.filename, 'w')
         tmphandle.close()
         self.mode = 'a'
     self.handle = None
Esempio n. 5
0
 def setUp(self):
     self.testData = scipy.array([[0., 1., 2.], [3., 4., 5.], [6., 7., 8.]])
     self.longname = u"Sampled Data"
     self.shortname = u"I\\omega"
     self.unit = Quantity('3.14 m')
     self.attributes = {
         'id': 'dummy id',
         'author': 'dummy author',
         'version': 'dummy version',
         'unit': self.unit
     }
     self.eln = open_file(
         'FieldContainerTestCase.h5',
         'w',
         title='Testing the saving and restoring of FieldContainers.')
     self.eln.create_group(self.eln.root, 'results')
     self.field = FieldContainer(self.testData,
                                 longname=self.longname,
                                 shortname=self.shortname,
                                 unit=self.unit,
                                 attributes=self.attributes)
Esempio n. 6
0
 def __enter__(self):
     assert self.handle is None
     self.handle = tables_version_handler.open_file(self.filename,
                                                    self.mode)
     return self