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)