1414
1515import bioformats .formatreader as formatreader
1616import bioformats .metadatatools as metadatatools
17- from bioformats import load_image
17+ from bioformats import load_image , load_image_url
1818from bioformats import log4j
19+ import urllib
1920
2021class TestLoadUsingBioformats (unittest .TestCase ):
2122
@@ -38,4 +39,37 @@ def test_file_not_found(self):
3839 self .assertRaises (exceptions .IOError ,
3940 lambda :load_image (path ))
4041
42+ class TestLoadUsingBioformatsURL (unittest .TestCase ):
43+ def setUp (self ):
44+ javabridge .attach ()
45+ log4j .basic_config ()
46+
47+ def tearDown (self ):
48+ javabridge .detach ()
4149
50+ def test_01_01_open_file (self ):
51+ path = os .path .join (os .path .dirname (__file__ ), 'Channel1-01-A-01.tif' )
52+ url = "file:" + urllib .pathname2url (path ).encode ("utf-8" )
53+ image , scale = load_image_url (
54+ url , rescale = False , wants_max_intensity = True )
55+ self .assertEqual (image .shape [0 ], 640 )
56+
57+ def test_01_02_open_http (self ):
58+ url = "https://github.com/CellProfiler/python-bioformats" + \
59+ "/raw/master/bioformats/tests/Channel1-01-A-01.tif"
60+ image , scale = load_image_url (
61+ url , rescale = False , wants_max_intensity = True )
62+ self .assertEqual (image .shape [0 ], 640 )
63+
64+ def test_01_03_unicode_url (self ):
65+ #
66+ # Regression test of issue #17: ensure that this does not
67+ # raise an exception when converting URL to string
68+ #
69+ path = os .path .join (os .path .dirname (__file__ ), 'Channel1-01-A-01.tif' )
70+ url = u"file:" + urllib .pathname2url (path ).encode ("utf-8" )
71+ image , scale = load_image_url (
72+ url , rescale = False , wants_max_intensity = True )
73+ self .assertEqual (image .shape [0 ], 640 )
74+
75+
0 commit comments