Skip to content

Instantly share code, notes, and snippets.

@EnigmaCurry
Created August 27, 2009 13:18
Show Gist options
  • Save EnigmaCurry/176280 to your computer and use it in GitHub Desktop.
Save EnigmaCurry/176280 to your computer and use it in GitHub Desktop.
import codecs
import tempfile
import doctest
def test_open(fn):
r"""
Test codecs.open to see if it actually opens a file
with an implicit binary mode and does not mess up the
newlines on Win32.
>>> f_contents = "Line One\nLine Two\nLine Three\n"
>>> f_wrong_contents = "Line One\r\nLine Two\r\nLine Three\r\n"
>>> fn = tempfile.mktemp()
>>> f = open(fn,"w")
>>> f.write(f_contents)
>>> f.close()
>>> test_open(fn) == f_contents
True
>>> test_open(fn) != f_wrong_contents
True
"""
return codecs.open(fn,"r","utf-8").read()
if __name__ == '__main__':
doctest.testmod(verbose=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment