Beispiel #1
0
 def __init__(self, indexed, skipped=None):
     indexed = [abspath(path) for path in indexed]
     if skipped:
         skipped = [abspath(path) for path in skipped]
     else:
         skipped = []
     BaseFileIterator.__init__(self, indexed, skipped)
 def testRelativePathConversion(self):
     """FileIterator should automatically convert relative paths"""
     paths = [(['data/a'], ['data/b']), (['/data/a'], ['/data/b',
                                                       'data/c'])]
     for indexed, skipped in paths:
         onRelatives = list(FileIterator(indexed, skipped))
         absIndexed = [abspath(path) for path in indexed]
         absSkipped = [abspath(path) for path in skipped]
         onAbspaths = list(FileIterator(absIndexed, absSkipped))
         self.assertEquals(onRelatives, onAbspaths)
 def testRelativePathConversion(self):
     """FileIterator should automatically convert relative paths"""
     paths = [([join('data', 'a')], [join('data', 'b')]),
              ([join(os.sep, 'data', 'a')], [
                  join(os.sep, 'data', 'b'),
                  join(os.sep, 'data', 'c'),
              ])]
     for indexed, skipped in paths:
         onRelatives = list(FileIterator(indexed, skipped))
         absIndexed = [abspath(path) for path in indexed]
         absSkipped = [abspath(path) for path in skipped]
         onAbspaths = list(FileIterator(absIndexed, absSkipped))
         self.assertEquals(onRelatives, onAbspaths)
 def testNothingSkipped(self):
     it = FileIterator(['a', 'b', 'c'])
     self.assertEquals(list(it), [])
     it = FileIterator(
         [join(DATADIR, 'a'),
          join(DATADIR, 'b'),
          join(DATADIR, 'c')])
     expected = Set([
         abspath(join(DATADIR, 'a', 'b', 'c', 'bar')),
         abspath(join(DATADIR, 'a', 'b', 'c', 'foo')),
         abspath(join(DATADIR, 'b', 'c', 'd', 'baz')),
         abspath(join(DATADIR, 'b', 'c', 'd', 'spam')),
         abspath(join(DATADIR, 'b', 'c', 'e', 'bazbar')),
         abspath(join(DATADIR, 'b', 'c', 'e', 'foobar')),
     ])
     self.assertEquals(Set(it), expected)
 def testDontChokeOnWeirdFilename(self):
     """we should iter without pain on everything in DATADIR, including
        the file whose name begins with an â
     """
     try:
         l = list(FileIterator([DATADIR]))
     except:
         self.fail("Exception while iterating on %s" % DATADIR)
 def testSkippingSomething(self):
     everything = [
         join(DATADIR, 'a'),
         join(DATADIR, 'b'),
         join(DATADIR, 'c')
     ]
     skipped = [join(DATADIR, 'a'), join(DATADIR, 'b', 'c', 'e')]
     it = FileIterator(everything, skipped)
     expected = Set([
         abspath(join(DATADIR, 'b', 'c', 'd', 'baz')),
         abspath(join(DATADIR, 'b', 'c', 'd', 'spam')),
     ])
     self.assertEquals(expected, Set(it))
 def testSkippingSomething(self):
     everything = [
         join(DATADIR, 'a'),
         join(DATADIR, 'b'),
         join(DATADIR, 'c')
     ]
     skipped = [join(DATADIR, 'a'), join(DATADIR, 'b', 'c', 'e')]
     it = FileIterator(everything, skipped)
     expected = [
         abspath(join(DATADIR, 'b', 'c', 'd', 'baz')),
         abspath(join(DATADIR, 'b', 'c', 'd', 'spam')),
     ]
     self.assertSetOfPathsEqual(it, expected)
 def testSkipNonAllowed(self):
     """tests that files that don't have 'read' permission are skipped"""
     # these two files should be skipped
     os.chmod(join(DATADIR, 'a/b/c/foo'), 0)
     os.chmod(join(DATADIR, 'b/c/d/spam'), 0)
     it = FileIterator(
         [join(DATADIR, 'a'),
          join(DATADIR, 'b'),
          join(DATADIR, 'c')])
     expected = Set([
         abspath(join(DATADIR, 'a', 'b', 'c', 'bar')),
         abspath(join(DATADIR, 'b', 'c', 'd', 'baz')),
         abspath(join(DATADIR, 'b', 'c', 'e', 'bazbar')),
         abspath(join(DATADIR, 'b', 'c', 'e', 'foobar')),
     ])
     self.assertEquals(Set(it), expected)
 def testSkipNonAllowed(self):
     """tests that files that don't have 'read' permission are skipped"""
     if sys.platform == 'win32':
         print "os.chmod() is very limited on windows platforms, I skip this test"
     else:
         # these two files should be skipped
         os.chmod(join(DATADIR, 'a', 'b', 'c', 'foo'), 0)
         os.chmod(join(DATADIR, 'b', 'c', 'd', 'spam'), 0)
         it = FileIterator(
             [join(DATADIR, 'a'),
              join(DATADIR, 'b'),
              join(DATADIR, 'c')])
         expected = [
             abspath(join(DATADIR, 'a', 'b', 'c', 'bar')),
             abspath(join(DATADIR, 'b', 'c', 'd', 'baz')),
             abspath(join(DATADIR, 'b', 'c', 'e', 'bazbar')),
             abspath(join(DATADIR, 'b', 'c', 'e', 'foobar')),
         ]
         self.assertSetOfPathsEqual(it, expected)
 def testEverythingSkipped(self):
     everything = ['data/a', 'data/b', 'data/c']
     it = FileIterator(everything, everything)
     self.assertEquals(list(it), [])
 def testEverythingSkipped(self):
     everything = [join('data', 'a'), join('data', 'b'), join('data', 'c')]
     it = FileIterator(everything, everything)
     self.assertEquals(list(it), [])