Пример #1
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)
Пример #2
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)
Пример #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)