1111import allensdk .brain_observatory .ecephys .ecephys_project_cache as epc
1212import allensdk .brain_observatory .ecephys .write_nwb .__main__ as write_nwb
1313from allensdk .brain_observatory .ecephys .ecephys_project_api .http_engine import (
14- write_from_stream , write_bytes_from_coroutine , AsyncHttpEngine
14+ write_from_stream , write_bytes_from_coroutine , AsyncHttpEngine , HttpEngine
1515)
1616
1717
@@ -195,14 +195,6 @@ def tmpdir_cache(shared_tmpdir, mock_api):
195195 )
196196
197197
198- def test_stream_writer_method_default_correct ():
199- """Checks that the stream_writer contained in the rma engine is used
200- when one is not supplied to the __init__ method.
201- """
202- cache = epc .EcephysProjectCache (stream_writer = None )
203- assert cache .stream_writer == cache .fetch_api .rma_engine .write_bytes
204-
205-
206198def lazy_cache_test (cache , cache_name , api_name , expected , * args , ** kwargs ):
207199 obtained_one = getattr (cache , cache_name )(* args , ** kwargs )
208200 obtained_two = getattr (cache , cache_name )(* args , ** kwargs )
@@ -389,5 +381,83 @@ def test_from_lims_default(tmpdir_factory):
389381 cache = epc .EcephysProjectCache .from_lims (
390382 manifest = os .path .join (tmpdir , "manifest.json" )
391383 )
392- assert isinstance (cache .fetch_api .app_engine , AsyncHttpEngine )
393- assert cache .stream_writer is epc .write_bytes_from_coroutine
384+ assert isinstance (cache .fetch_api .app_engine , HttpEngine )
385+ assert cache .stream_writer is write_from_stream
386+ assert cache .fetch_api .app_engine .scheme == "http"
387+ assert cache .fetch_api .app_engine .host == "lims2"
388+
389+
390+ def test_from_warehouse_default (tmpdir_factory ):
391+ tmpdir = str (tmpdir_factory .mktemp ("test_from_warehouse_default" ))
392+
393+ cache = epc .EcephysProjectCache .from_warehouse (
394+ manifest = os .path .join (tmpdir , "manifest.json" )
395+ )
396+ assert isinstance (cache .fetch_api .rma_engine , HttpEngine )
397+ assert cache .stream_writer is write_from_stream
398+ assert cache .fetch_api .rma_engine .scheme == "http"
399+ assert cache .fetch_api .rma_engine .host == "api.brain-map.org"
400+
401+
402+ def test_init_default (tmpdir_factory ):
403+ tmpdir = str (tmpdir_factory .mktemp ("test_init_default" ))
404+ cache = epc .EcephysProjectCache (
405+ manifest = os .path .join (tmpdir , "manifest.json" )
406+ )
407+ assert isinstance (cache .fetch_api .rma_engine , HttpEngine )
408+ assert cache .stream_writer is cache .fetch_api .rma_engine .write_bytes
409+ assert cache .fetch_api .rma_engine .scheme == "http"
410+ assert cache .fetch_api .rma_engine .host == "api.brain-map.org"
411+
412+
413+ @pytest .mark .parametrize (
414+ ("cache_constructor, asynchronous, engine_attr, expected_engine,"
415+ "expected_scheme, expected_host, expected_stream_writer" ), [
416+ (
417+ epc .EcephysProjectCache .from_lims , True ,
418+ "app_engine" , AsyncHttpEngine , "http" , "lims2" ,
419+ write_bytes_from_coroutine
420+ ),
421+ (
422+ epc .EcephysProjectCache .from_warehouse , True ,
423+ "rma_engine" , AsyncHttpEngine , "http" , "api.brain-map.org" ,
424+ write_bytes_from_coroutine
425+ ),
426+ (
427+ epc .EcephysProjectCache .from_warehouse , False ,
428+ "rma_engine" , HttpEngine , "http" , "api.brain-map.org" ,
429+ write_from_stream
430+ ),
431+ (
432+ epc .EcephysProjectCache .from_lims , False ,
433+ "app_engine" , HttpEngine , "http" , "lims2" ,
434+ write_from_stream
435+ ),
436+ ])
437+ def test_stream_asynchronous_arg (
438+ cache_constructor , asynchronous , engine_attr , expected_engine ,
439+ expected_scheme , expected_host , expected_stream_writer ,
440+ tmpdir_factory ):
441+ """ Ensure the proper stream engine is chosen from the `asynchronous`
442+ argument in the EcephysProjectCache constructors (using other default
443+ values)."""
444+ tmpdir = str (tmpdir_factory .mktemp ("test_stream_async_args" ))
445+ cache = cache_constructor (
446+ asynchronous = asynchronous ,
447+ manifest = os .path .join (tmpdir , "manifest.json" )
448+ )
449+ engine = getattr (cache .fetch_api , engine_attr )
450+ assert isinstance (engine , expected_engine )
451+ assert cache .stream_writer is expected_stream_writer
452+ assert engine .scheme == expected_scheme
453+ assert engine .host == expected_host
454+
455+
456+ def test_stream_writer_method_default_correct (tmpdir_factory ):
457+ """Checks that the stream_writer contained in the rma engine is used
458+ when one is not supplied to the __init__ method.
459+ """
460+ tmpdir = str (tmpdir_factory .mktemp ("test_from_warehouse_default" ))
461+ manifest = os .path .join (tmpdir , "manifest.json" )
462+ cache = epc .EcephysProjectCache (stream_writer = None , manifest = manifest )
463+ assert cache .stream_writer == cache .fetch_api .rma_engine .write_bytes
0 commit comments