def testWalk(self): temp_dir = self._CreateDeepS3Structure() self._CreateDeepS3Structure(temp_dir) expected = [ ["", ["a.tfevents.1", "model.ckpt",]], # Empty directory not returned # ['foo', []], ["bar", ["b.tfevents.1", "red_herring.txt",]], ["bar/baz", ["c.tfevents.1", "d.tfevents.1",]], [ "bar/quux", ["some_flume_output.txt", "some_more_flume_output.txt",], ], ["quuz", ["e.tfevents.1",]], ["quuz/garply", ["f.tfevents.1",]], ["quuz/garply/corge", ["g.tfevents.1",]], ["quuz/garply/grault", ["h.tfevents.1",]], ["waldo", []], ["waldo/fred", ["i.tfevents.1",]], ] for pair in expected: # If this is not the top-level directory, prepend the high-level # directory. pair[0] = self._PathJoin(temp_dir, pair[0]) if pair[0] else temp_dir gotten = gfile.walk(temp_dir) self._CompareFilesPerSubdirectory(expected, gotten)
def testWalkPostOrder(self): dir_path = os.path.join(self._base_dir, "test_dir") self._setupWalkDirectories(dir_path) # Now test the walk (topdown = False) all_dirs = [] all_subdirs = [] all_files = [] for (w_dir, w_subdirs, w_files) in gfile.walk(dir_path, topdown=False): all_dirs.append(w_dir) all_subdirs.append(w_subdirs) all_files.append(w_files) self.assertItemsEqual( all_dirs, [ os.path.join(dir_path, item) for item in [ "subdir1_1", "subdir1_2/subdir2", "subdir1_2", "subdir1_3", ] ] + [dir_path], ) self.assertEqual(dir_path, all_dirs[4]) self.assertLess( all_dirs.index(os.path.join(dir_path, "subdir1_2/subdir2")), all_dirs.index(os.path.join(dir_path, "subdir1_2")), ) self.assertItemsEqual(all_subdirs[0:4], [[], [], ["subdir2"], []]) self.assertItemsEqual(all_subdirs[4], ["subdir1_1", "subdir1_2", "subdir1_3"]) self.assertItemsEqual(all_files, [["file2.txt"], [], [], [], ["file1.txt"]]) self.assertLess(all_files.index(["file2.txt"]), all_files.index(["file1.txt"]))
def testWalk(self): temp_dir = self.get_temp_dir() self._CreateDeepDirectoryStructure(temp_dir) expected = [ ["", ["a.tfevents.1", "model.ckpt",]], ["foo", []], ["bar", ["b.tfevents.1", "red_herring.txt",]], ["bar/baz", ["c.tfevents.1", "d.tfevents.1",]], [ "bar/quux", ["some_flume_output.txt", "some_more_flume_output.txt",], ], ["quuz", ["e.tfevents.1",]], ["quuz/garply", ["f.tfevents.1",]], ["quuz/garply/corge", ["g.tfevents.1",]], ["quuz/garply/grault", ["h.tfevents.1",]], ["waldo", []], ["waldo/fred", ["i.tfevents.1",]], ] for pair in expected: # If this is not the top-level directory, prepend the high-level # directory. pair[0] = ( os.path.join(temp_dir, pair[0].replace("/", os.path.sep)) if pair[0] else temp_dir ) gotten = gfile.walk(temp_dir) self._CompareFilesPerSubdirectory(expected, gotten)
def testWalkFailure(self): dir_path = os.path.join(self._base_dir, "test_dir") # Try walking a directory that wasn't created. all_dirs = [] all_subdirs = [] all_files = [] for (w_dir, w_subdirs, w_files) in gfile.walk(dir_path, topdown=False): all_dirs.append(w_dir) all_subdirs.append(w_subdirs) all_files.append(w_files) self.assertItemsEqual(all_dirs, []) self.assertItemsEqual(all_subdirs, []) self.assertItemsEqual(all_files, [])
def testWalk(self): temp_dir = self._CreateDeepS3Structure() self._CreateDeepS3Structure(temp_dir) expected = [ ['', [ 'a.tfevents.1', 'model.ckpt', ]], # Empty directory not returned # ['foo', []], ['bar', [ 'b.tfevents.1', 'red_herring.txt', ]], ['bar/baz', [ 'c.tfevents.1', 'd.tfevents.1', ]], [ 'bar/quux', [ 'some_flume_output.txt', 'some_more_flume_output.txt', ] ], ['quuz', [ 'e.tfevents.1', ]], ['quuz/garply', [ 'f.tfevents.1', ]], ['quuz/garply/corge', [ 'g.tfevents.1', ]], ['quuz/garply/grault', [ 'h.tfevents.1', ]], ['waldo', []], ['waldo/fred', [ 'i.tfevents.1', ]], ] for pair in expected: # If this is not the top-level directory, prepend the high-level # directory. pair[0] = self._PathJoin(temp_dir, pair[0]) if pair[0] else temp_dir gotten = gfile.walk(temp_dir) self._CompareFilesPerSubdirectory(expected, gotten)
def testWalk(self): temp_dir = tempfile.mkdtemp(prefix=self.base_temp_dir) self._CreateDeepDirectoryStructure(temp_dir) expected = [ ['', [ 'a.tfevents.1', 'model.ckpt', ]], ['foo', []], ['bar', [ 'b.tfevents.1', 'red_herring.txt', ]], ['bar/baz', [ 'c.tfevents.1', 'd.tfevents.1', ]], [ 'bar/quux', [ 'some_flume_output.txt', 'some_more_flume_output.txt', ] ], ['quuz', [ 'e.tfevents.1', ]], ['quuz/garply', [ 'f.tfevents.1', ]], ['quuz/garply/corge', [ 'g.tfevents.1', ]], ['quuz/garply/grault', [ 'h.tfevents.1', ]], ['waldo', []], ['waldo/fred', [ 'i.tfevents.1', ]], ] for pair in expected: # If this is not the top-level directory, prepend the high-level # directory. pair[0] = os.path.join(temp_dir, pair[0].replace( '/', os.path.sep)) if pair[0] else temp_dir gotten = gfile.walk(temp_dir) self._CompareFilesPerSubdirectory(expected, gotten)