Open files in binary mode to avoid newlines transformation.

This commit is contained in:
Serhiy Storchaka 2015-04-04 10:36:25 +03:00
parent 2e229e025c
commit c9ba38c21c
1 changed files with 4 additions and 4 deletions

View File

@ -2624,8 +2624,8 @@ Windows line endings first:
>>> import tempfile, os
>>> fn = tempfile.mktemp()
>>> with open(fn, 'w') as f:
... f.write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
>>> with open(fn, 'wb') as f:
... f.write(b'Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
35
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)
@ -2634,8 +2634,8 @@ Windows line endings first:
And now *nix line endings:
>>> fn = tempfile.mktemp()
>>> with open(fn, 'w') as f:
... f.write('Test:\n\n >>> x = 1 + 1\n\nDone.\n')
>>> with open(fn, 'wb') as f:
... f.write(b'Test:\n\n >>> x = 1 + 1\n\nDone.\n')
30
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)