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)
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)
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)