Make sure an exception inside the body leaves the original file
content.
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
f = open(target_file, 'r')
WVPASSEQ(f.read(), 'asdf')
+ try:
+ with atomically_replaced_file(target_file, mode='w') as f:
+ f.write('wxyz')
+ raise Exception()
+ except:
+ pass
+ with open(target_file) as f:
+ WVPASSEQ(f.read(), 'asdf')
+
with atomically_replaced_file(target_file, mode='wb') as f:
f.write(os.urandom(20))
WVPASSEQ(f.mode, 'wb')