@@ -10,11 +10,11 @@ def test_atomic_write(tmpdir):
1010 fname = tmpdir .join ('ha' )
1111 for i in range (2 ):
1212 with atomic_write (str (fname ), overwrite = True ) as f :
13- f .write (u 'hoho' )
13+ f .write ('hoho' )
1414
1515 with pytest .raises (OSError ) as excinfo :
1616 with atomic_write (str (fname ), overwrite = False ) as f :
17- f .write (u 'haha' )
17+ f .write ('haha' )
1818
1919 assert excinfo .value .errno == errno .EEXIST
2020
@@ -34,7 +34,7 @@ def test_teardown(tmpdir):
3434def test_replace_simultaneously_created_file (tmpdir ):
3535 fname = tmpdir .join ('ha' )
3636 with atomic_write (str (fname ), overwrite = True ) as f :
37- f .write (u 'hoho' )
37+ f .write ('hoho' )
3838 fname .write ('harhar' )
3939 assert fname .read () == 'harhar'
4040 assert fname .read () == 'hoho'
@@ -45,7 +45,7 @@ def test_dont_remove_simultaneously_created_file(tmpdir):
4545 fname = tmpdir .join ('ha' )
4646 with pytest .raises (OSError ) as excinfo :
4747 with atomic_write (str (fname ), overwrite = False ) as f :
48- f .write (u 'hoho' )
48+ f .write ('hoho' )
4949 fname .write ('harhar' )
5050 assert fname .read () == 'harhar'
5151
@@ -59,11 +59,13 @@ def test_dont_remove_simultaneously_created_file(tmpdir):
5959def test_open_reraise (tmpdir ):
6060 fname = tmpdir .join ('ha' )
6161 with pytest .raises (AssertionError ):
62- with atomic_write (str (fname ), overwrite = False ) as f :
63- # Mess with f, so commit will trigger a ValueError. We're testing
64- # that the initial AssertionError triggered below is propagated up
65- # the stack, not the second exception triggered during commit.
66- f .close ()
62+ aw = atomic_write (str (fname ), overwrite = False )
63+ with aw :
64+ # Mess with internals, so commit will trigger a ValueError. We're
65+ # testing that the initial AssertionError triggered below is
66+ # propagated up the stack, not the second exception triggered
67+ # during commit.
68+ aw .rollback = lambda : 1 / 0
6769 # Now trigger our own exception.
6870 assert False , "Intentional failure for testing purposes"
6971
@@ -75,11 +77,11 @@ def test_atomic_write_in_pwd(tmpdir):
7577 fname = 'ha'
7678 for i in range (2 ):
7779 with atomic_write (str (fname ), overwrite = True ) as f :
78- f .write (u 'hoho' )
80+ f .write ('hoho' )
7981
8082 with pytest .raises (OSError ) as excinfo :
8183 with atomic_write (str (fname ), overwrite = False ) as f :
82- f .write (u 'haha' )
84+ f .write ('haha' )
8385
8486 assert excinfo .value .errno == errno .EEXIST
8587
0 commit comments