Created
August 27, 2009 13:18
-
-
Save EnigmaCurry/176280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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