[xmlWriter_test] test custom 'newlinestr' values in XMLWriter constructor

This commit is contained in:
Cosimo Lupo 2016-10-20 16:56:41 +01:00
parent d235e124b4
commit 543be9cfbf

View File

@ -106,6 +106,22 @@ class TestXMLWriter(unittest.TestCase):
HEADER + b'two lines
\nseparated by Windows line endings',
writer.file.getvalue())
def test_newlinestr(self):
header = b'<?xml version="1.0" encoding="UTF-8"?>'
for nls in (None, '\n', '\r\n', '\r', ''):
writer = XMLWriter(BytesIO(), newlinestr=nls)
writer.write("hello")
writer.newline()
writer.write("world")
writer.newline()
linesep = tobytes(os.linesep) if nls is None else tobytes(nls)
self.assertEqual(
header + linesep + b"hello" + linesep + b"world" + linesep,
writer.file.getvalue())
if __name__ == '__main__':
unittest.main()