@@ -190,7 +190,7 @@ def test_own_path_module(self):
190
190
191
191
192
192
@unittest .skipIf (sys .version_info < (2 , 7 ), "No byte strings in Python 2.6" )
193
- class TestCopyRealFile (TestPyfakefsUnittestBase ):
193
+ class TestCopyOrAddRealFile (TestPyfakefsUnittestBase ):
194
194
"""Tests the `fake_filesystem_unittest.TestCase.copyRealFile()` method."""
195
195
with open (__file__ ) as f :
196
196
real_string_contents = f .read ()
@@ -235,6 +235,28 @@ def testCopyRealFileNoDestination(self):
235
235
self .copyRealFile (real_file_path )
236
236
self .assertTrue (self .fs .Exists (real_file_path ))
237
237
238
+ def testAddRealFile (self ):
239
+ '''Add a real file to the fake file system to be read on demand'''
240
+
241
+ # this tests only the basic functionality inside a unit test, more thorough tests
242
+ # are done in fake_filesystem_test.RealFileSystemAccessTest
243
+ real_file_path = __file__
244
+ fake_file = self .fs .add_real_file (real_file_path )
245
+ self .assertTrue (self .fs .Exists (real_file_path ))
246
+ self .assertIsNone (fake_file ._byte_contents )
247
+ self .assertEqual (self .real_byte_contents , fake_file .byte_contents )
248
+
249
+ def testAddRealDirectory (self ):
250
+ '''Add a real directory and the contained files to the fake file system to be read on demand'''
251
+
252
+ # this tests only the basic functionality inside a unit test, more thorough tests
253
+ # are done in fake_filesystem_test.RealFileSystemAccessTest
254
+ # Note: this test fails (add_real_directory raises) if 'genericpath' is not added to SKIPNAMES
255
+ real_dir_path = os .path .join (os .path .dirname (__file__ ), 'pyfakefs' )
256
+ self .fs .add_real_directory (real_dir_path )
257
+ self .assertTrue (self .fs .Exists (real_dir_path ))
258
+ self .assertTrue (self .fs .Exists (os .path .join (real_dir_path , 'fake_filesystem.py' )))
259
+
238
260
239
261
if __name__ == "__main__" :
240
262
unittest .main ()
0 commit comments