+
+
+@wvtest
+def test_atomically_replaced_file():
+ target_file = os.path.join(tempfile.gettempdir(),
+ 'test_atomic_write')
+ try:
+ with atomically_replaced_file(target_file, mode='w') as f:
+ f.write('asdf')
+ WVPASSEQ(f.mode, 'w')
+ f = open(target_file, 'r')
+ WVPASSEQ(f.read(), 'asdf')
+
+ with atomically_replaced_file(target_file, mode='wb') as f:
+ f.write(os.urandom(20))
+ WVPASSEQ(f.mode, 'wb')
+ finally:
+ unlink(target_file)