@@ -605,7 +605,7 @@ def test_empty_file_created_for_none_contents(self):
605605 fake_open = fake_filesystem .FakeFileOpen (self .filesystem )
606606 path = "foo/bar/baz"
607607 self .filesystem .create_file (path , contents = None )
608- with fake_open (path ) as f :
608+ with fake_open (path , encoding = "utf8" ) as f :
609609 self .assertEqual ("" , f .read ())
610610
611611 def test_create_file_with_incorrect_mode_type (self ):
@@ -1649,15 +1649,15 @@ def test_disk_usage_on_file_creation(self):
16491649 self .fs .add_mount_point ("!mount" , total_size )
16501650
16511651 def create_too_large_file ():
1652- with self .open ("!mount!file" , "w" ) as dest :
1652+ with self .open ("!mount!file" , "w" , encoding = "utf8" ) as dest :
16531653 dest .write ("a" * (total_size + 1 ))
16541654
16551655 with self .assertRaises (OSError ):
16561656 create_too_large_file ()
16571657
16581658 self .assertEqual (0 , self .fs .get_disk_usage ("!mount" ).used )
16591659
1660- with self .open ("!mount!file" , "w" ) as dest :
1660+ with self .open ("!mount!file" , "w" , encoding = "utf8" ) as dest :
16611661 dest .write ("a" * total_size )
16621662
16631663 self .assertEqual (total_size , self .fs .get_disk_usage ("!mount" ).used )
@@ -1882,50 +1882,50 @@ def test_copying_preserves_byte_contents(self):
18821882 self .assertEqual (dest_file .contents , source_file .contents )
18831883
18841884 def test_diskusage_after_open_write (self ):
1885- with self .open ("bar.txt" , "w" ) as f :
1885+ with self .open ("bar.txt" , "w" , encoding = "utf8" ) as f :
18861886 f .write ("a" * 60 )
18871887 f .flush ()
18881888 self .assertEqual (60 , self .fs .get_disk_usage ()[1 ])
18891889
18901890 def test_disk_full_after_reopened (self ):
1891- with self .open ("bar.txt" , "w" ) as f :
1891+ with self .open ("bar.txt" , "w" , encoding = "utf8" ) as f :
18921892 f .write ("a" * 60 )
1893- with self .open ("bar.txt" ) as f :
1893+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
18941894 self .assertEqual ("a" * 60 , f .read ())
18951895 with self .raises_os_error (errno .ENOSPC ):
1896- with self .open ("bar.txt" , "w" ) as f :
1896+ with self .open ("bar.txt" , "w" , encoding = "utf8" ) as f :
18971897 f .write ("b" * 110 )
18981898 with self .raises_os_error (errno .ENOSPC ):
18991899 f .flush ()
1900- with self .open ("bar.txt" ) as f :
1900+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
19011901 self .assertEqual ("" , f .read ())
19021902
19031903 def test_disk_full_append (self ):
19041904 file_path = "bar.txt"
1905- with self .open (file_path , "w" ) as f :
1905+ with self .open (file_path , "w" , encoding = "utf8" ) as f :
19061906 f .write ("a" * 60 )
1907- with self .open (file_path ) as f :
1907+ with self .open (file_path , encoding = "utf8" ) as f :
19081908 self .assertEqual ("a" * 60 , f .read ())
19091909 with self .raises_os_error (errno .ENOSPC ):
1910- with self .open (file_path , "a" ) as f :
1910+ with self .open (file_path , "a" , encoding = "utf8" ) as f :
19111911 f .write ("b" * 41 )
19121912 with self .raises_os_error (errno .ENOSPC ):
19131913 f .flush ()
1914- with self .open ("bar.txt" ) as f :
1914+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
19151915 self .assertEqual (f .read (), "a" * 60 )
19161916
19171917 def test_disk_full_after_reopened_rplus_seek (self ):
1918- with self .open ("bar.txt" , "w" ) as f :
1918+ with self .open ("bar.txt" , "w" , encoding = "utf8" ) as f :
19191919 f .write ("a" * 60 )
1920- with self .open ("bar.txt" ) as f :
1920+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
19211921 self .assertEqual (f .read (), "a" * 60 )
19221922 with self .raises_os_error (errno .ENOSPC ):
1923- with self .open ("bar.txt" , "r+" ) as f :
1923+ with self .open ("bar.txt" , "r+" , encoding = "utf8" ) as f :
19241924 f .seek (50 )
19251925 f .write ("b" * 60 )
19261926 with self .raises_os_error (errno .ENOSPC ):
19271927 f .flush ()
1928- with self .open ("bar.txt" ) as f :
1928+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
19291929 self .assertEqual (f .read (), "a" * 60 )
19301930
19311931
@@ -2055,11 +2055,13 @@ def create_real_paths(self):
20552055 for dir_name in ("foo" , "bar" ):
20562056 real_dir = os .path .join (real_dir_root , dir_name )
20572057 os .makedirs (real_dir , exist_ok = True )
2058- with open (os .path .join (real_dir , "test.txt" ), "w" ) as f :
2058+ with open (
2059+ os .path .join (real_dir , "test.txt" ), "w" , encoding = "utf8"
2060+ ) as f :
20592061 f .write ("test" )
20602062 sub_dir = os .path .join (real_dir , "sub" )
20612063 os .makedirs (sub_dir , exist_ok = True )
2062- with open (os .path .join (sub_dir , "sub.txt" ), "w" ) as f :
2064+ with open (os .path .join (sub_dir , "sub.txt" ), "w" , encoding = "utf8" ) as f :
20632065 f .write ("sub" )
20642066 yield real_dir_root
20652067 finally :
@@ -2203,7 +2205,7 @@ def test_write_to_real_file(self):
22032205 # regression test for #470
22042206 real_file_path = os .path .abspath (__file__ )
22052207 self .filesystem .add_real_file (real_file_path , read_only = False )
2206- with self .fake_open (real_file_path , "w" ) as f :
2208+ with self .fake_open (real_file_path , "w" , encoding = "utf8" ) as f :
22072209 f .write ("foo" )
22082210
22092211 with self .fake_open (real_file_path , "rb" ) as f :
@@ -2289,7 +2291,7 @@ def test_add_existing_real_directory_symlink(self):
22892291
22902292 self .filesystem .create_file ("/etc/something" )
22912293
2292- with fake_open ("/etc/something" , "w" ) as f :
2294+ with fake_open ("/etc/something" , "w" , encoding = "utf8" ) as f :
22932295 f .write ("good morning" )
22942296
22952297 try :
@@ -2385,7 +2387,8 @@ def test_add_existing_real_directory_symlink(self):
23852387 "pyfakefs" ,
23862388 "tests" ,
23872389 "fixtures/symlink_file_absolute_outside" ,
2388- )
2390+ ),
2391+ encoding = "utf8" ,
23892392 ).read (),
23902393 "good morning" ,
23912394 )
@@ -2585,14 +2588,14 @@ def setUp(self):
25852588 def test_side_effect_called (self ):
25862589 fake_open = fake_filesystem .FakeFileOpen (self .filesystem )
25872590 self .side_effect_called = False
2588- with fake_open ("/a/b/file_one" , "w" ) as handle :
2591+ with fake_open ("/a/b/file_one" , "w" , encoding = "utf8" ) as handle :
25892592 handle .write ("foo" )
25902593 self .assertTrue (self .side_effect_called )
25912594
25922595 def test_side_effect_file_object (self ):
25932596 fake_open = fake_filesystem .FakeFileOpen (self .filesystem )
25942597 self .side_effect_called = False
2595- with fake_open ("/a/b/file_one" , "w" ) as handle :
2598+ with fake_open ("/a/b/file_one" , "w" , encoding = "utf8" ) as handle :
25962599 handle .write ("foo" )
25972600 self .assertEqual (self .side_effect_file_object_content , "foo" )
25982601
0 commit comments