@@ -605,7 +605,7 @@ def test_empty_file_created_for_none_contents(self):
605
605
fake_open = fake_filesystem .FakeFileOpen (self .filesystem )
606
606
path = "foo/bar/baz"
607
607
self .filesystem .create_file (path , contents = None )
608
- with fake_open (path ) as f :
608
+ with fake_open (path , encoding = "utf8" ) as f :
609
609
self .assertEqual ("" , f .read ())
610
610
611
611
def test_create_file_with_incorrect_mode_type (self ):
@@ -1649,15 +1649,15 @@ def test_disk_usage_on_file_creation(self):
1649
1649
self .fs .add_mount_point ("!mount" , total_size )
1650
1650
1651
1651
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 :
1653
1653
dest .write ("a" * (total_size + 1 ))
1654
1654
1655
1655
with self .assertRaises (OSError ):
1656
1656
create_too_large_file ()
1657
1657
1658
1658
self .assertEqual (0 , self .fs .get_disk_usage ("!mount" ).used )
1659
1659
1660
- with self .open ("!mount!file" , "w" ) as dest :
1660
+ with self .open ("!mount!file" , "w" , encoding = "utf8" ) as dest :
1661
1661
dest .write ("a" * total_size )
1662
1662
1663
1663
self .assertEqual (total_size , self .fs .get_disk_usage ("!mount" ).used )
@@ -1882,50 +1882,50 @@ def test_copying_preserves_byte_contents(self):
1882
1882
self .assertEqual (dest_file .contents , source_file .contents )
1883
1883
1884
1884
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 :
1886
1886
f .write ("a" * 60 )
1887
1887
f .flush ()
1888
1888
self .assertEqual (60 , self .fs .get_disk_usage ()[1 ])
1889
1889
1890
1890
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 :
1892
1892
f .write ("a" * 60 )
1893
- with self .open ("bar.txt" ) as f :
1893
+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
1894
1894
self .assertEqual ("a" * 60 , f .read ())
1895
1895
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 :
1897
1897
f .write ("b" * 110 )
1898
1898
with self .raises_os_error (errno .ENOSPC ):
1899
1899
f .flush ()
1900
- with self .open ("bar.txt" ) as f :
1900
+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
1901
1901
self .assertEqual ("" , f .read ())
1902
1902
1903
1903
def test_disk_full_append (self ):
1904
1904
file_path = "bar.txt"
1905
- with self .open (file_path , "w" ) as f :
1905
+ with self .open (file_path , "w" , encoding = "utf8" ) as f :
1906
1906
f .write ("a" * 60 )
1907
- with self .open (file_path ) as f :
1907
+ with self .open (file_path , encoding = "utf8" ) as f :
1908
1908
self .assertEqual ("a" * 60 , f .read ())
1909
1909
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 :
1911
1911
f .write ("b" * 41 )
1912
1912
with self .raises_os_error (errno .ENOSPC ):
1913
1913
f .flush ()
1914
- with self .open ("bar.txt" ) as f :
1914
+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
1915
1915
self .assertEqual (f .read (), "a" * 60 )
1916
1916
1917
1917
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 :
1919
1919
f .write ("a" * 60 )
1920
- with self .open ("bar.txt" ) as f :
1920
+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
1921
1921
self .assertEqual (f .read (), "a" * 60 )
1922
1922
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 :
1924
1924
f .seek (50 )
1925
1925
f .write ("b" * 60 )
1926
1926
with self .raises_os_error (errno .ENOSPC ):
1927
1927
f .flush ()
1928
- with self .open ("bar.txt" ) as f :
1928
+ with self .open ("bar.txt" , encoding = "utf8" ) as f :
1929
1929
self .assertEqual (f .read (), "a" * 60 )
1930
1930
1931
1931
@@ -2055,11 +2055,13 @@ def create_real_paths(self):
2055
2055
for dir_name in ("foo" , "bar" ):
2056
2056
real_dir = os .path .join (real_dir_root , dir_name )
2057
2057
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 :
2059
2061
f .write ("test" )
2060
2062
sub_dir = os .path .join (real_dir , "sub" )
2061
2063
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 :
2063
2065
f .write ("sub" )
2064
2066
yield real_dir_root
2065
2067
finally :
@@ -2203,7 +2205,7 @@ def test_write_to_real_file(self):
2203
2205
# regression test for #470
2204
2206
real_file_path = os .path .abspath (__file__ )
2205
2207
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 :
2207
2209
f .write ("foo" )
2208
2210
2209
2211
with self .fake_open (real_file_path , "rb" ) as f :
@@ -2289,7 +2291,7 @@ def test_add_existing_real_directory_symlink(self):
2289
2291
2290
2292
self .filesystem .create_file ("/etc/something" )
2291
2293
2292
- with fake_open ("/etc/something" , "w" ) as f :
2294
+ with fake_open ("/etc/something" , "w" , encoding = "utf8" ) as f :
2293
2295
f .write ("good morning" )
2294
2296
2295
2297
try :
@@ -2385,7 +2387,8 @@ def test_add_existing_real_directory_symlink(self):
2385
2387
"pyfakefs" ,
2386
2388
"tests" ,
2387
2389
"fixtures/symlink_file_absolute_outside" ,
2388
- )
2390
+ ),
2391
+ encoding = "utf8" ,
2389
2392
).read (),
2390
2393
"good morning" ,
2391
2394
)
@@ -2585,14 +2588,14 @@ def setUp(self):
2585
2588
def test_side_effect_called (self ):
2586
2589
fake_open = fake_filesystem .FakeFileOpen (self .filesystem )
2587
2590
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 :
2589
2592
handle .write ("foo" )
2590
2593
self .assertTrue (self .side_effect_called )
2591
2594
2592
2595
def test_side_effect_file_object (self ):
2593
2596
fake_open = fake_filesystem .FakeFileOpen (self .filesystem )
2594
2597
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 :
2596
2599
handle .write ("foo" )
2597
2600
self .assertEqual (self .side_effect_file_object_content , "foo" )
2598
2601
0 commit comments