Esempio n. 1
0
 def setupClass(cls):
     """
     Override.  Called by nosetests.
     """
     if not have_dvid:
         return
     cls._tmp_dir = tempfile.mkdtemp()
     cls.test_filepath = os.path.join( cls._tmp_dir, "test_data.h5" )
     cls._generate_testdata_h5(cls.test_filepath)
     cls.server_proc, cls.shutdown_event = H5MockServer.create_and_start( cls.test_filepath, "localhost", 8000 )
 def _start_mockserver(cls, h5filepath, same_process=False, disable_server_logging=True):
     """
     Start the mock DVID server in a separate process.
     
     h5filepath: The file to serve up.
     same_process: If True, start the server in this process as a 
                   separate thread (useful for debugging).
                   Otherwise, start the server in its own process (default).
     disable_server_logging: If true, disable the normal HttpServer logging of every request.
     """
     return H5MockServer.create_and_start( h5filepath, "localhost", 8000, same_process, disable_server_logging )
 def setupClass(cls):
     """
     Override.  Called by nosetests.
     """
     if not have_dvid:
         return
     cls._tmp_dir = tempfile.mkdtemp()
     cls.test_filepath = os.path.join( cls._tmp_dir, "test_data.h5" )
     cls._generate_empty_h5(cls.test_filepath)
     cls.server_proc, cls.shutdown_event = H5MockServer.create_and_start( cls.test_filepath, "localhost", 8000, 
                                                                          same_process=True, disable_server_logging=True )
Esempio n. 4
0
    def testBasic_Dvid(self):
        if _skip_dvid:
            raise nose.SkipTest

        # Spin up a mock dvid server to test with.
        dvid_dataset, data_uuid, data_name = "datasetA", "abcde", "indices_data"
        mockserver_data_file = self._tmpdir + '/mockserver_data.h5'
        with H5MockServerDataFile(mockserver_data_file) as test_h5file:
            test_h5file.add_node(dvid_dataset, data_uuid)
        server_proc, shutdown_event = H5MockServer.create_and_start(
            mockserver_data_file,
            "localhost",
            8000,
            same_process=False,
            disable_server_logging=True)

        try:
            data = 255 * numpy.random.random((100, 100, 4))
            data = data.astype(numpy.uint8)
            data = vigra.taggedView(data, vigra.defaultAxistags('xyc'))

            graph = Graph()

            opPiper = OpArrayPiper(graph=graph)
            opPiper.Input.setValue(data)

            opExport = OpExportSlot(graph=graph)
            opExport.Input.connect(opPiper.Output)
            opExport.OutputFormat.setValue('dvid')
            url = 'http://localhost:8000/api/node/{data_uuid}/{data_name}'.format(
                **locals())
            opExport.OutputFilenameFormat.setValue(url)

            assert opExport.ExportPath.ready()
            assert opExport.ExportPath.value == url
            opExport.run_export()

            try:
                opRead = OpInputDataReader(graph=graph)
                opRead.FilePath.setValue(opExport.ExportPath.value)
                expected_data = data.view(numpy.ndarray)
                read_data = opRead.Output[:].wait()
                assert (read_data == expected_data
                        ).all(), "Read data didn't match exported data!"
            finally:
                opRead.cleanUp()
        finally:
            shutdown_event.set()
            server_proc.join()
Esempio n. 5
0
 def _start_mockserver(cls,
                       h5filepath,
                       same_process=False,
                       disable_server_logging=True):
     """
     Start the mock DVID server in a separate process.
     
     h5filepath: The file to serve up.
     same_process: If True, start the server in this process as a 
                   separate thread (useful for debugging).
                   Otherwise, start the server in its own process (default).
     disable_server_logging: If true, disable the normal HttpServer logging of every request.
     """
     return H5MockServer.create_and_start(h5filepath, "localhost", 8000,
                                          same_process,
                                          disable_server_logging)
Esempio n. 6
0
    def testBasic_Dvid(self):
        if _skip_dvid:
            raise nose.SkipTest
        
        # Spin up a mock dvid server to test with.
        dvid_dataset, data_uuid, data_name = "datasetA", "abcde", "indices_data"
        mockserver_data_file = self._tmpdir + '/mockserver_data.h5'
        with H5MockServerDataFile( mockserver_data_file ) as test_h5file:
            test_h5file.add_node( dvid_dataset, data_uuid )
        server_proc, shutdown_event = H5MockServer.create_and_start( mockserver_data_file, "localhost", 8000,
                                                                     same_process=False, disable_server_logging=True )

        try:            
            data = 255 * numpy.random.random( (100,100, 4) )
            data = data.astype( numpy.uint8 )
            data = vigra.taggedView( data, vigra.defaultAxistags('xyc') )
            
            graph = Graph()
            
            opPiper = OpArrayPiper(graph=graph)
            opPiper.Input.setValue( data )
            
            opExport = OpExportSlot(graph=graph)
            opExport.Input.connect( opPiper.Output )
            opExport.OutputFormat.setValue( 'dvid' )
            url = 'http://localhost:8000/api/node/{data_uuid}/{data_name}'.format( **locals() )
            opExport.OutputFilenameFormat.setValue( url )
            
            assert opExport.ExportPath.ready()
            assert opExport.ExportPath.value == url
            opExport.run_export()

            try:
                opRead = OpInputDataReader( graph=graph )
                opRead.FilePath.setValue( opExport.ExportPath.value )
                expected_data = data.view(numpy.ndarray)
                read_data = opRead.Output[:].wait()
                assert (read_data == expected_data).all(), "Read data didn't match exported data!"
            finally:
                opRead.cleanUp()
        finally:
            shutdown_event.set()
            server_proc.join()
        print "*******************************************************"
        print "No args provided.  Starting with special debug args...."
        print "*******************************************************"
        sys.argv.append("--mock-server-hdf5=/magnetic/mockdvid_gigacube_fortran.h5")
        #sys.argv.append("--mode=specify_new")
        sys.argv.append("localhost:8000")

    parsed_args = parser.parse_args()
    
    server_proc = None
    if parsed_args.mock_server_hdf5:
        from mockserver.h5mockserver import H5MockServer
        hostname, port = parsed_args.hostname.split(":")
        server_proc, shutdown_event = H5MockServer.create_and_start( parsed_args.mock_server_hdf5,
                                                     hostname,
                                                     int(port),
                                                     same_process=False,
                                                     disable_server_logging=False )
    
    app = QApplication([])
    browser = DvidDataSelectionBrowser([parsed_args.hostname], parsed_args.mode)

    try:
        if browser.exec_() == DvidDataSelectionBrowser.Accepted:
            print "The dialog was accepted with result: ", browser.get_selection()
            print "Subvolume roi:", browser.get_subvolume_roi()
        else:
            print "The dialog was rejected."
    finally:
        if server_proc:
            shutdown_event.set()
Esempio n. 8
0
        print "*******************************************************"
        print "No args provided.  Starting with special debug args...."
        print "*******************************************************"
        sys.argv.append("--mock-server-hdf5=/magnetic/mockdvid_gigacube_fortran.h5")
        #sys.argv.append("--mode=specify_new")
        sys.argv.append("localhost:8000")

    parsed_args = parser.parse_args()
    
    server_proc = None
    if parsed_args.mock_server_hdf5:
        from mockserver.h5mockserver import H5MockServer
        hostname, port = parsed_args.hostname.split(":")
        server_proc, shutdown_event = H5MockServer.create_and_start( parsed_args.mock_server_hdf5,
                                                     hostname,
                                                     int(port),
                                                     same_process=False,
                                                     disable_server_logging=False )
    
    app = QApplication([])
    browser = DvidDataSelectionBrowser([parsed_args.hostname], parsed_args.mode)

    try:
        if browser.exec_() == DvidDataSelectionBrowser.Accepted:
            print "The dialog was accepted with result: ", browser.get_selection()
            print "Subvolume roi:", browser.get_subvolume_roi()
        else:
            print "The dialog was rejected."
    finally:
        if server_proc:
            shutdown_event.set()