Skip to content

Commit

Permalink
Allow trailing separator in fake_filesystem.add_real_directory()
Browse files Browse the repository at this point in the history
- fixes #446
  • Loading branch information
mrbean-bremen committed Oct 29, 2018
1 parent 9a88cbb commit 0e43445
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The release versions are PyPi releases.
#### Fixes
* fixed recursion error on unpickling the fake file system
([#445](../../issues/445))
* allow trailing path in `add_real_directory` ([#446](../../issues/446))

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

Expand Down
1 change: 1 addition & 0 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,7 @@ def add_real_directory(self, source_path, read_only=True, lazy_read=True,
OSError: if the directory does not exist in the real file system.
IOError: if the directory already exists in the fake file system.
"""
source_path = self._path_without_trailing_separators(source_path)
if not os.path.exists(source_path):
self.raise_io_error(errno.ENOENT, source_path)
target_path = target_path or source_path
Expand Down
8 changes: 8 additions & 0 deletions pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ def test_add_real_directory(self):
self.assertTrue(self.fs.exists(
os.path.join(real_dir_path, 'fake_filesystem.py')))

def test_add_real_directory_with_backslash(self):
"""Add a real directory ending with a path separator."""
real_dir_path = os.path.split(os.path.dirname(self.filepath))[0]
self.fs.add_real_directory(real_dir_path + os.sep)
self.assertTrue(self.fs.exists(real_dir_path))
self.assertTrue(self.fs.exists(
os.path.join(real_dir_path, 'fake_filesystem.py')))


class TestPyfakefsTestCase(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 0e43445

Please sign in to comment.