|
|
|
|
@ -175,4 +175,41 @@ def test_atomic_writing():
|
|
|
|
|
f.write(u'written from symlink')
|
|
|
|
|
|
|
|
|
|
with stdlib_io.open(f1, 'r') as f:
|
|
|
|
|
nt.assert_equal(f.read(), u'written from symlink')
|
|
|
|
|
nt.assert_equal(f.read(), u'written from symlink')
|
|
|
|
|
|
|
|
|
|
def test_atomic_writing_newlines():
|
|
|
|
|
with TemporaryDirectory() as td:
|
|
|
|
|
path = os.path.join(td, 'testfile')
|
|
|
|
|
|
|
|
|
|
lf = u'a\nb\nc\n'
|
|
|
|
|
plat = lf.replace(u'\n', os.linesep)
|
|
|
|
|
crlf = lf.replace(u'\n', u'\r\n')
|
|
|
|
|
|
|
|
|
|
# test default
|
|
|
|
|
with stdlib_io.open(path, 'w') as f:
|
|
|
|
|
f.write(lf)
|
|
|
|
|
with stdlib_io.open(path, 'r', newline='') as f:
|
|
|
|
|
read = f.read()
|
|
|
|
|
nt.assert_equal(read, plat)
|
|
|
|
|
|
|
|
|
|
# test newline=LF
|
|
|
|
|
with stdlib_io.open(path, 'w', newline='\n') as f:
|
|
|
|
|
f.write(lf)
|
|
|
|
|
with stdlib_io.open(path, 'r', newline='') as f:
|
|
|
|
|
read = f.read()
|
|
|
|
|
nt.assert_equal(read, lf)
|
|
|
|
|
|
|
|
|
|
# test newline=CRLF
|
|
|
|
|
with atomic_writing(path, newline='\r\n') as f:
|
|
|
|
|
f.write(lf)
|
|
|
|
|
with stdlib_io.open(path, 'r', newline='') as f:
|
|
|
|
|
read = f.read()
|
|
|
|
|
nt.assert_equal(read, crlf)
|
|
|
|
|
|
|
|
|
|
# test newline=no convert
|
|
|
|
|
text = u'crlf\r\ncr\rlf\n'
|
|
|
|
|
with atomic_writing(path, newline='') as f:
|
|
|
|
|
f.write(text)
|
|
|
|
|
with stdlib_io.open(path, 'r', newline='') as f:
|
|
|
|
|
read = f.read()
|
|
|
|
|
nt.assert_equal(read, text)
|
|
|
|
|
|