|
49 | 49 | from pyfakefs import fake_filesystem |
50 | 50 | from pyfakefs import fake_filesystem_shutil |
51 | 51 | from pyfakefs import fake_tempfile |
| 52 | + |
52 | 53 | if sys.version_info >= (3, 4): |
53 | 54 | from pyfakefs import fake_pathlib |
54 | 55 |
|
@@ -119,41 +120,40 @@ def fs(self): |
119 | 120 | def patches(self): |
120 | 121 | return self._stubber.patches |
121 | 122 |
|
122 | | - if sys.version_info >= (2, 7): |
123 | | - def copyRealFile(self, real_file_path, fake_file_path=None, |
124 | | - create_missing_dirs=True): |
125 | | - """Copy the file `real_file_path` from the real file system to the fake |
126 | | - file system file `fake_file_path`. The permissions, gid, uid, ctime, |
127 | | - mtime and atime of the real file are copied to the fake file. |
128 | | -
|
129 | | - This is a helper method you can use to set up your test more easily. |
130 | | -
|
131 | | - This method is available in Python 2.7 and above. |
132 | | -
|
133 | | - Args: |
134 | | - real_file_path: Path to the source file in the real file system. |
135 | | - fake_file_path: path to the destination file in the fake file system. |
136 | | - create_missing_dirs: if True, auto create missing directories. |
137 | | -
|
138 | | - Returns: |
139 | | - the newly created FakeFile object. |
140 | | -
|
141 | | - Raises: |
142 | | - IOError: if the file already exists. |
143 | | - IOError: if the containing directory is required and missing. |
144 | | - """ |
145 | | - real_stat = REAL_OS.stat(real_file_path) |
146 | | - with REAL_OPEN(real_file_path, 'rb') as real_file: |
147 | | - real_contents = real_file.read() |
148 | | - fake_file = self.fs.CreateFile(fake_file_path, st_mode=real_stat.st_mode, |
149 | | - contents=real_contents, |
150 | | - create_missing_dirs=create_missing_dirs) |
151 | | - fake_file.st_ctime = real_stat.st_ctime |
152 | | - fake_file.st_atime = real_stat.st_atime |
153 | | - fake_file.st_mtime = real_stat.st_mtime |
154 | | - fake_file.st_gid = real_stat.st_gid |
155 | | - fake_file.st_uid = real_stat.st_uid |
156 | | - return fake_file |
| 123 | + def copyRealFile(self, real_file_path, fake_file_path=None, |
| 124 | + create_missing_dirs=True): |
| 125 | + """Copy the file `real_file_path` from the real file system to the fake |
| 126 | + file system file `fake_file_path`. The permissions, gid, uid, ctime, |
| 127 | + mtime and atime of the real file are copied to the fake file. |
| 128 | +
|
| 129 | + This is a helper method you can use to set up your test more easily. |
| 130 | +
|
| 131 | + This method is available in Python 2.7 and above. |
| 132 | +
|
| 133 | + Args: |
| 134 | + real_file_path: Path to the source file in the real file system. |
| 135 | + fake_file_path: path to the destination file in the fake file system. |
| 136 | + create_missing_dirs: if True, auto create missing directories. |
| 137 | +
|
| 138 | + Returns: |
| 139 | + the newly created FakeFile object. |
| 140 | +
|
| 141 | + Raises: |
| 142 | + IOError: if the file already exists. |
| 143 | + IOError: if the containing directory is required and missing. |
| 144 | + """ |
| 145 | + real_stat = REAL_OS.stat(real_file_path) |
| 146 | + with REAL_OPEN(real_file_path, 'rb') as real_file: |
| 147 | + real_contents = real_file.read() |
| 148 | + fake_file = self.fs.CreateFile(fake_file_path, st_mode=real_stat.st_mode, |
| 149 | + contents=real_contents, |
| 150 | + create_missing_dirs=create_missing_dirs) |
| 151 | + fake_file.st_ctime = real_stat.st_ctime |
| 152 | + fake_file.st_atime = real_stat.st_atime |
| 153 | + fake_file.st_mtime = real_stat.st_mtime |
| 154 | + fake_file.st_gid = real_stat.st_gid |
| 155 | + fake_file.st_uid = real_stat.st_uid |
| 156 | + return fake_file |
157 | 157 |
|
158 | 158 | def setUpPyfakefs(self): |
159 | 159 | """Bind the file-related modules to the :py:class:`pyfakefs` fake file |
@@ -262,7 +262,7 @@ def _findModules(self): |
262 | 262 | for name, module in set(sys.modules.items()): |
263 | 263 | if (module in self.SKIPMODULES or |
264 | 264 | (not inspect.ismodule(module)) or |
265 | | - name.split('.')[0] in self._skipNames): |
| 265 | + name.split('.')[0] in self._skipNames): |
266 | 266 | continue |
267 | 267 | if 'os' in module.__dict__: |
268 | 268 | self._os_modules.add(module) |
|
0 commit comments