Ejemplo n.º 1
0
 def test07_write_html(self):
     s=IIIFStatic()
     # bad output dir
     self.assertRaises( Exception, s.write_html, '/tmp/path_does_no_exist_(i_hope)' )
     # write to good path
     tmp = tempfile.mkdtemp()
     s.identifier='abc1'
     s.write_html(tmp)
     self.assertTrue( os.path.isfile( os.path.join(tmp,'abc1.html') ) )
     # write to subdir of good path
     tmp = tempfile.mkdtemp()
     s.identifier='abc2'
     tmp2 = os.path.join(tmp,'xyz')
     s.write_html(tmp2)
     self.assertTrue( os.path.isfile( os.path.join(tmp2,'abc2.html') ) )
     # write to good path with osd
     tmp = tempfile.mkdtemp()
     s.identifier='abc3'
     s.write_html(tmp, include_osd=True)
     self.assertTrue( os.path.isfile( os.path.join(tmp,'abc3.html') ) )
     self.assertTrue( os.path.isfile( os.path.join(tmp,'osd/openseadragon.min.js') ) )
     # bad write to existing path
     tmp = tempfile.mkdtemp()
     tmp2 = os.path.join(tmp,'file')
     open(tmp2,'w').close()
     s.identifier='abc4'
     self.assertRaises( Exception, s.write_html, tmp2 )
Ejemplo n.º 2
0
 def test08_setup_destination(self):
     """Test setip_destination."""
     s = IIIFStatic()
     # no dst
     self.assertRaises(Exception, s.setup_destination)
     # now really create dir
     tmp = tempfile.mkdtemp()
     try:
         # no dst
         s.identifier = 'a'
         s.dst = None
         self.assertRaises(IIIFStaticError, s.setup_destination)
         # dst and no identifier
         s.src = 'a/b.ext'
         s.dst = os.path.join(tmp, 'xyz')
         s.identifier = None
         s.setup_destination()
         self.assertTrue(os.path.isdir(tmp))
         self.assertTrue(os.path.isdir(s.dst))
         self.assertTrue(os.path.isdir(os.path.join(s.dst, 'b')))
         self.assertEqual(s.identifier, 'b')
         # dst and identifier
         s.src = 'a/b.ext'
         s.dst = os.path.join(tmp, 'zyx')
         s.identifier = 'c'
         s.setup_destination()
         self.assertTrue(os.path.isdir(s.dst))
         self.assertTrue(os.path.isdir(os.path.join(s.dst, 'c')))
         self.assertEqual(s.identifier, 'c')
         # dst path is file
         s.dst = os.path.join(tmp, 'exists1')
         open(s.dst, 'w').close()
         self.assertRaises(Exception, s.setup_destination)
         # dst and identifier, path is file
         s.identifier = 'exists2'
         s.dst = tmp
         open(os.path.join(s.dst, s.identifier), 'w').close()
         self.assertRaises(Exception, s.setup_destination)
         # dst and identifier, both dirs exist and OK
         s.dst = tmp
         s.identifier = 'id1'
         os.mkdir(os.path.join(s.dst, s.identifier))
         s.setup_destination()  # nothing created, no exception
     finally:
         shutil.rmtree(tmp)
Ejemplo n.º 3
0
 def test04_setup_destination(self):
     s = IIIFStatic()
     # no dst
     self.assertRaises(Exception, s.setup_destination)
     # now really create dir
     tmp = tempfile.mkdtemp()
     try:
         # dst and no identifier
         s.dst = os.path.join(tmp, 'xyz')
         s.identifier = None
         s.setup_destination()
         self.assertTrue(os.path.isdir(s.dst))
         self.assertEqual(s.outd, tmp)
         self.assertEqual(s.identifier, 'xyz')
         # dst and identifier
         s.dst = os.path.join(tmp, 'zyx')
         s.identifier = 'abc'
         s.setup_destination()
         self.assertTrue(os.path.isdir(s.dst))
         self.assertTrue(os.path.isdir(os.path.join(s.dst, 'abc')))
         self.assertEqual(s.outd, s.dst)
         self.assertEqual(s.identifier, 'abc')
         # dst path is file
         s.dst = os.path.join(tmp, 'exists1')
         open(s.dst, 'w').close()
         self.assertRaises(Exception, s.setup_destination)
         # dst and identifier, path is file
         s.identifier = 'exists2'
         s.dst = tmp
         open(os.path.join(s.dst, s.identifier), 'w').close()
         self.assertRaises(Exception, s.setup_destination)
         # dst and identifier, both dirs exist and OK
         s.outd = None
         s.dst = tmp
         s.identifier = 'id1'
         os.mkdir(os.path.join(s.dst, s.identifier))
         s.setup_destination()
         self.assertEqual(s.outd, tmp)
     finally:
         shutil.rmtree(tmp)
Ejemplo n.º 4
0
 def test04_setup_destination(self):
     s=IIIFStatic()
     # no dst
     self.assertRaises( Exception, s.setup_destination )
     # now really create dir
     tmp = tempfile.mkdtemp()
     try:
         # dst and no identifier
         s.dst=os.path.join(tmp,'xyz')
         s.identifier=None
         s.setup_destination()
         self.assertTrue( os.path.isdir(s.dst) )
         self.assertEqual( s.outd, tmp )
         self.assertEqual( s.identifier, 'xyz' )
         # dst and identifier
         s.dst=os.path.join(tmp,'zyx')
         s.identifier='abc'
         s.setup_destination()
         self.assertTrue( os.path.isdir(s.dst) )
         self.assertTrue( os.path.isdir(os.path.join(s.dst,'abc')) )
         self.assertEqual( s.outd, s.dst )
         self.assertEqual( s.identifier, 'abc' )
         # dst path is file
         s.dst=os.path.join(tmp,'exists1')
         open(s.dst, 'w').close()
         self.assertRaises( Exception, s.setup_destination )
         # dst and identifier, path is file
         s.identifier='exists2'
         s.dst=tmp
         open(os.path.join(s.dst,s.identifier), 'w').close()
         self.assertRaises( Exception, s.setup_destination )
         # dst and identifier, both dirs exist and OK
         s.outd=None
         s.dst=tmp
         s.identifier='id1'
         os.mkdir( os.path.join(s.dst,s.identifier) )
         s.setup_destination()
         self.assertEqual( s.outd, tmp )
     finally:
         shutil.rmtree(tmp) 
Ejemplo n.º 5
0
 def test03_generate_tile(self):
     # most tested via other calls, make sure zero size skip works
     tmp1 = tempfile.mkdtemp()
     os.mkdir( os.path.join(tmp1,'a') )
     try:
         s=IIIFStatic( dst=tmp1, tilesize=512, api_version='2.0' )
         s.identifier = 'fgh'
         s.src = 'testimages/starfish_1500x2000.png'
         with capture_stdout() as capturer:
             s.generate_tile( region='full', size=[0,1] )
         self.assertTrue( re.search(r'zero size, skipped', capturer.result) )
     finally:
         shutil.rmtree(tmp1)
Ejemplo n.º 6
0
 def test04_generate_tile(self):
     """Test generation of a tile."""
     # most tested via other calls, make sure zero size skip works
     tmp1 = tempfile.mkdtemp()
     os.mkdir(os.path.join(tmp1, 'a'))
     try:
         s = IIIFStatic(dst=tmp1, tilesize=512, api_version='2.0')
         s.identifier = 'fgh'
         s.src = 'testimages/starfish_1500x2000.png'
         with MyLogCapture('iiif.static') as lc:
             s.generate_tile(region='full', size=[0, 1])
         self.assertTrue(re.search(r'zero size, skipped', lc.all_msgs))
     finally:
         shutil.rmtree(tmp1)
Ejemplo n.º 7
0
 def test08_write_html(self):
     """Test write_html."""
     s = IIIFStatic()
     # bad output dir
     self.assertRaises(Exception, s.write_html,
                       '/tmp/path_does_no_exist_(i_hope)')
     # write to good path
     tmp = tempfile.mkdtemp()
     s.identifier = 'abc1'
     s.write_html(tmp)
     self.assertTrue(os.path.isfile(os.path.join(tmp, 'abc1.html')))
     # write to subdir of good path
     tmp = tempfile.mkdtemp()
     s.identifier = 'abc2'
     tmp2 = os.path.join(tmp, 'xyz')
     s.write_html(tmp2)
     self.assertTrue(os.path.isfile(os.path.join(tmp2, 'abc2.html')))
     # write to good path with osd
     tmp = tempfile.mkdtemp()
     s.identifier = 'abc3'
     s.write_html(tmp, include_osd=True)
     self.assertTrue(os.path.isfile(os.path.join(tmp, 'abc3.html')))
     self.assertTrue(os.path.isfile(os.path.join(
         tmp, 'openseadragon200/openseadragon.min.js')))
     self.assertTrue(s.copied_osd)
     # add another, with osd already present (and marked as such)
     s.identifier = 'abc4'
     with LogCapture('iiif.static') as lc:
         s.write_html(tmp, include_osd=True)
     self.assertTrue(os.path.isfile(os.path.join(tmp, 'abc4.html')))
     self.assertTrue(os.path.isfile(os.path.join(
         tmp, 'openseadragon200/openseadragon.min.js')))
     self.assertTrue(s.copied_osd)
     self.assertEqual(lc.records[-1].msg, 'OpenSeadragon already copied')
     # add yet another, with osd already present (but not marked)
     s.identifier = 'abc5'
     s.copied_osd = False
     with LogCapture('iiif.static') as lc:
         s.write_html(tmp, include_osd=True)
     self.assertTrue(os.path.isfile(os.path.join(tmp, 'abc5.html')))
     self.assertTrue(os.path.isfile(os.path.join(
         tmp, 'openseadragon200/openseadragon.min.js')))
     self.assertTrue(s.copied_osd)
     self.assertTrue(re.search(r'OpenSeadragon images directory .* already exists',
                               lc.records[-1].msg))
     # add another but with a prefix
     s.identifier = 'abc6'
     s.prefix = 'z/y/x'
     s.copied_osd = False
     s.write_html(tmp, include_osd=True)
     html_file = os.path.join(tmp, 'abc6.html')
     self.assertTrue(os.path.isfile(html_file))
     with open(html_file, 'r') as x:
         html = x.read()
     self.assertTrue(re.search(r'z/y/x/abc6/info.json', html))
     # bad write to existing path
     tmp = tempfile.mkdtemp()
     tmp2 = os.path.join(tmp, 'file')
     open(tmp2, 'w').close()
     s.identifier = 'abc4'
     self.assertRaises(Exception, s.write_html, tmp2)