Skip to content

Commit

Permalink
Propagate exception for non-existing path in os.scandir()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Nov 1, 2019
1 parent 947e83f commit 46c9e24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ the proposed changes so you can be ready.

## Version 3.7 (as yet unreleased)

### Fixes
* raise for `os.scandir` with non-existing directory
(see [#498](../../issues/498))

## [Version 3.6.1](https://pypi.python.org/pypi/pyfakefs/3.6.1)

### Fixes
Expand Down
6 changes: 1 addition & 5 deletions pyfakefs/fake_scandir.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ def __init__(self, filesystem, path):
else:
self.abspath = self.filesystem.absnormpath(path)
self.path = path
contents = {}
try:
contents = self.filesystem.confirmdir(self.abspath).contents
except OSError:
pass
contents = self.filesystem.confirmdir(self.abspath).contents
self.contents_iter = iter(contents)

def __iter__(self):
Expand Down
6 changes: 6 additions & 0 deletions pyfakefs/tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def test_get_cwd(self):
self.assertEqual(self.os.getcwd(), dirname)

def test_listdir(self):
self.assert_raises_os_error(
errno.ENOENT, self.os.listdir, 'non_existing/fake_dir')
directory = self.make_path('xyzzy', 'plugh')
files = ['foo', 'bar', 'baz']
for f in files:
Expand Down Expand Up @@ -4941,6 +4943,10 @@ def test_path_like(self):
self.assertEqual(self.os.path.join(self.scandir_path(), 'file'),
os.fspath(self.dir_entries[1]))

def test_non_existing_dir(self):
self.assert_raises_os_error(
errno.ENOENT, self.scandir, 'non_existing/fake_dir')


class RealScandirTest(FakeScandirTest):
def use_real_fs(self):
Expand Down

0 comments on commit 46c9e24

Please sign in to comment.