def testFileIteratorNotRecursive(self): target_files = [('0.ext', b'hello world'), ('1.ext', b'hi')] extra_files = [('a/1.ext', b'123456'), ('a/2.ext', b'abcd'), ('b/c/3.ext', b'9999'), ('d/e/5.ext', b'zzzzzzzz'), ('d/e/f/g/6.ext', b'yyyyyyyyyyy'), ('stuff.txt', b'some stuff'), ('a/q/r/file', b'more stuff')] root_dir = tempfile.mkdtemp(dir=self.get_temp_dir()) for path, contents in target_files + extra_files: abs_path = os.path.join(root_dir, path) tf.gfile.MakeDirs(os.path.dirname(abs_path)) tf.gfile.FastGFile(abs_path, mode='w').write(contents) file_iterator = pipeline.file_iterator(root_dir, 'ext', recurse=False) self.assertEqual(set(contents for _, contents in target_files), set(file_iterator))
def testFileIteratorRecursive(self): target_files = [('0.ext', b'hello world'), ('a/1.ext', b'123456'), ('a/2.ext', b'abcd'), ('b/c/3.ext', b'9999'), ('b/z/3.ext', b'qwerty'), ('d/4.ext', b'mary had a little lamb'), ('d/e/5.ext', b'zzzzzzzz'), ('d/e/f/g/6.ext', b'yyyyyyyyyyy')] extra_files = [('stuff.txt', b'some stuff'), ('a/q/r/file', b'more stuff')] root_dir = self.create_tempdir().full_path for path, contents in target_files + extra_files: abs_path = os.path.join(root_dir, path) tf.gfile.MakeDirs(os.path.dirname(abs_path)) tf.gfile.GFile(abs_path, mode='w').write(contents) file_iterator = pipeline.file_iterator(root_dir, 'ext', recurse=True) self.assertEqual(set(contents for _, contents in target_files), set(file_iterator))
def testFileIteratorNotRecursive(self): target_files = [ ('0.ext', b'hello world'), ('1.ext', b'hi')] extra_files = [ ('a/1.ext', b'123456'), ('a/2.ext', b'abcd'), ('b/c/3.ext', b'9999'), ('d/e/5.ext', b'zzzzzzzz'), ('d/e/f/g/6.ext', b'yyyyyyyyyyy'), ('stuff.txt', b'some stuff'), ('a/q/r/file', b'more stuff')] root_dir = tempfile.mkdtemp(dir=self.get_temp_dir()) for path, contents in target_files + extra_files: abs_path = os.path.join(root_dir, path) tf.gfile.MakeDirs(os.path.dirname(abs_path)) tf.gfile.FastGFile(abs_path, mode='w').write(contents) file_iterator = pipeline.file_iterator(root_dir, 'ext', recurse=False) self.assertEqual(set([contents for _, contents in target_files]), set(file_iterator))