Skip to content

Commit

Permalink
Added FakeDirectory.ordered_dirs
Browse files Browse the repository at this point in the history
- see #151
  • Loading branch information
mrbean-bremen committed Jan 17, 2017
1 parent 85d37b6 commit 75209e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fake_filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ def testDirectoryInode(self):
dir_obj.SetIno(43)
self.assertEqual(43, fake_os.stat(dirpath)[stat.ST_INO])

def testOrderedDirs(self):
filesystem = fake_filesystem.FakeFilesystem(path_separator='/')
filesystem.CreateDirectory('/foo')
filesystem.CreateFile('/foo/2')
filesystem.CreateFile('/foo/4')
filesystem.CreateFile('/foo/1')
filesystem.CreateFile('/foo/3')
fake_dir = filesystem.GetObject('/foo')
self.assertEqual(['2', '4', '1', '3'], fake_dir.ordered_dirs)


class SetLargeFileSizeTest(FakeDirectoryUnitTest):
def testShouldThrowIfSizeIsNotInteger(self):
Expand Down
5 changes: 5 additions & 0 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ def contents(self):
"""Return the list of contained directory entries."""
return self.byte_contents

@property
def ordered_dirs(self):
"""Return the list of contained directory entry names ordered by creation order."""
return [item[0] for item in sorted(self.byte_contents.items(), key=lambda entry: entry[1].st_ino)]

def AddEntry(self, path_object):
"""Adds a child FakeFile to this directory.
Expand Down

0 comments on commit 75209e3

Please sign in to comment.