From 433f46b3a387ec5d4daf2c057923c6d4c1bc263a Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 30 Sep 2016 22:17:28 +0300 Subject: [PATCH] Test print_tokens() with encoding --- tests/test_print_tokens.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_print_tokens.py b/tests/test_print_tokens.py index af9c9ae..133bb92 100644 --- a/tests/test_print_tokens.py +++ b/tests/test_print_tokens.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- try: - from cStringIO import StringIO + from io import StringIO, BytesIO except ImportError: try: - from StringIO import StringIO + from cStringIO import StringIO except ImportError: - from io import StringIO + from StringIO import StringIO + BytesIO = StringIO from sqlparse import parse from sqlconvert.print_tokens import print_tokens @@ -17,3 +18,10 @@ def test_print_tokens(): parsed = parse("select * from T")[0] print_tokens(parsed, outfile=sio) assert sio.getvalue() == u"SELECT * FROM T" + + +def test_print_tokens_encoded(): + sio = BytesIO() + parsed = parse("select * from T")[0] + print_tokens(parsed, outfile=sio, encoding='ascii') + assert sio.getvalue() == b"SELECT * FROM T" -- 2.39.5