Support for additional path separator
- removed additional argument, set additional separator automatically
instead
- adapted tests
diff --git a/.gitignore b/.gitignore
index 2c3816f..3262812 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,6 @@
.settings
.project
.pydevproject
+
+# PyCharm
+.idea/
diff --git a/fake_filesystem_test.py b/fake_filesystem_test.py
index b71553a..9787837 100755
--- a/fake_filesystem_test.py
+++ b/fake_filesystem_test.py
@@ -3006,7 +3006,18 @@
class AdditionalPathSeparatorTest(TestCase):
def setUp(self):
- self.filesystem = fake_filesystem.FakeFilesystem(path_separator='!', alt_path_separator='?')
+ self.filesystem = fake_filesystem.FakeFilesystem(path_separator='!')
+ self.filesystem.additional_path_separator = '?'
+
+ def testInitialValue(self):
+ filesystem = fake_filesystem.FakeFilesystem()
+ if self.is_windows:
+ self.assertEqual('/', filesystem.additional_path_separator)
+ else:
+ self.assertIsNone(filesystem.additional_path_separator)
+
+ filesystem = fake_filesystem.FakeFilesystem(path_separator='/')
+ self.assertIsNone(filesystem.additional_path_separator)
def testCollapsePathWithMixedSeparators(self):
self.assertEqual('!foo!bar', self.filesystem.CollapsePath('!foo??bar'))
@@ -3023,4 +3034,4 @@
if __name__ == '__main__':
- main()
+ unittest.main()
diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py
index 97e1835..600e426 100644
--- a/pyfakefs/fake_filesystem.py
+++ b/pyfakefs/fake_filesystem.py
@@ -357,18 +357,19 @@
class FakeFilesystem(object):
"""Provides the appearance of a real directory tree for unit testing."""
- def __init__(self, path_separator=os.path.sep, alt_path_separator=None):
+ def __init__(self, path_separator=os.path.sep):
"""init.
Args:
path_separator: optional substitute for os.path.sep
- alt_path_separator: optional alternative path separator (especially for '/' under Windows)
Example usage to emulate real file systems:
filesystem = FakeFilesystem(alt_path_separator='/' if _is_windows else None)
"""
self.path_separator = path_separator
- self.alt_path_separator = alt_path_separator
+ self.additional_path_separator = None
+ if _is_windows and path_separator == os.sep:
+ self.additional_path_separator = '/'
self.root = FakeDirectory(self.path_separator)
self.cwd = self.root.name
# We can't query the current value without changing it:
@@ -447,9 +448,9 @@
Returns:
The normalized path that will be used internally.
"""
- if self.alt_path_separator is None or not path:
+ if self.additional_path_separator is None or not path:
return path
- return path.replace(self.alt_path_separator, self.path_separator)
+ return path.replace(self.additional_path_separator, self.path_separator)
def CollapsePath(self, path):
"""Mimics os.path.normpath using the specified path_separator.