Example #1
0
 def test_glob(self):
     d = Path(self.tpath, 'glob.d')
     d.mkdir()
     for i in range(3):
         (d + str(i)).open()
     self.assertEqual([f.basename for f in sorted(d.glob('[0-9]'))],
                      ['0', '1', '2'])
Example #2
0
 def _test_get_files_simple(self):
     #"""Retrieve files in basedir properly."""
     fileset = ('bar', 'far', 'tar')
     subdir = Path(self.dir, 'get_files_simple')
     subdir.mkdir()
     obj = Initer(files=(subdir,), pattern='*')
     # no files
     ofiles = obj.get_files()
     #print 'ofiles =', repr(ofiles), vars(ofiles)
     self.assertEqual(list(obj.get_files(('*',))), [])
     for n in fileset:
         f = subdir + n #V['basedir'] + n  # subdir + n
         logging.error('n %s = f %s', n, f)
         f.open('w').close()
     # test simple glob
     result = obj.get_files()
     #print 'results =', repr(result), vars(result)
     self.assertEqual(sorted(result), list(fileset))
     # test single file
     self.assertEqual(list(obj.get_files(('bar',))),
                      ['bar'])
     # test single file, no glob
     obj.noglob = True
     self.assertEqual(list(obj.get_files(('tar',))),
                      ['tar'])
     obj.noglob = False
     # test simple file tuple, with glob
     self.assertEqual(sorted(obj.get_files(('bar', 'tar'))),
                      ['bar',
                       'tar'])
     # test glob file tuple, with glob
     self.assertEqual(sorted(obj.get_files(('bar', 't*'))),
                      ['bar',
                       'tar'])
Example #3
0
 def test__len_(self):
     f = Path(self.tpath, 'len.f')
     d = Path(self.tpath, 'len.d')
     f.open('w').write('=' * 256)
     self.assertEqual(len(f), 256)
     d.mkdir()
     for i in range(2):
         Path(d, str(i)).open('w')
     self.assertEqual(len(d), 2)
Example #4
0
 def test__iter_(self):
     d = Path(self.tpath, 'iter.d')
     d.mkdir()
     for i in range(2):
         Path(d, str(i)).open('w')
     i = 0
     for f in d:
         self.assertEqual(f.value, Path(d, str(i)).value)
         i += 1
     self.assertRaises(TypeError, iter(f))
Example #5
0
 def test_remove(self):
     f = Path(self.tpath, 'remove.f')
     d = Path(self.tpath, 'remove.d')
     n = Path(self.tpath, 'remove.n')
     f.open()
     d.mkdir()
     self.assertIsNone(f.remove())
     self.assertFalse(f.exists)
     self.assertIsNone(d.remove())
     self.assertFalse(d.exists)
     self.assertIsNone(n.remove())
     self.assertFalse(n.exists)
Example #6
0
 def test_mkdir(self):
     n = Path(self.tpath, 'mkdir.n')  # does not exist
     f = Path(self.tpath, 'mkdir.f')  # existing file
     d = Path(self.tpath, 'mkdir.d')  # existing directory
     d1 = d + 'subdir'
     d2 = d1 + 'subsubdir'
     f.open()
     os.mkdir(d.value)  # do it the old fashioned way for now
     self.assertTrue(f.isfile)
     self.assertRaises(TypeError, f.mkdir)
     self.assertIsNone(n.mkdir())
     self.assertTrue(n.isdir)
     self.assertTrue(d.isdir)
     self.assertIsNone(d.mkdir())
     self.assertFalse(d2.exists)
     self.assertIsNone(d2.mkdir())
     self.assertTrue(d2.isdir)
     self.assertTrue(d1.isdir)
Example #7
0
 def test_makelink(self):
     n = Path(self.tpath, 'makelink.n')  # does not exist
     l = Path(self.tpath, 'makelink.l')  # existing link
     f = Path(self.tpath, 'makelink.f')  # existing file
     d = Path(self.tpath, 'makelink.d')  # existing directory
     ptr = 'foobar'
     pptr = Path(ptr)
     self.assertIsNone(n.makelink(ptr))  # passing str value
     self.assertTrue(n.islink)
     self.assertEqual(os.readlink(n.value), ptr)
     n.remove()
     self.assertIsNone(n.makelink(pptr))  # passing Path instance
     self.assertTrue(n.islink)
     self.assertEqual(os.readlink(n.value), ptr)
     f.open()
     d.mkdir()
     os.symlink('xyzzy', l.value)
     self.assertRaises(TypeError, f.makelink, ptr)
     self.assertRaises(TypeError, d.makelink, ptr)
     self.assertIsNone(l.makelink(ptr))
     self.assertTrue(l.islink)
     self.assertEqual(os.readlink(l.value), ptr)