Skip to content

Commit

Permalink
Add better common unicode handling for Python 2 and 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
bravegnu committed Jul 6, 2015
1 parent 5a30a02 commit e397b2a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
"""Unit tests for english language checker"""
from libcipher import utils as utils
"""Unit tests for english language checker."""

from libcipher import utils
import io
import sys
import unittest

#
# Based on http://python3porting.com/noconv.html
#
if sys.version_info < (3,):
import codecs
def u(x):
return codecs.unicode_escape_decode(x)[0]
else:
def u(x):
return x


def get_marys_dictionary():
english_words = ["had", "a", "little", "lamb"]
if sys.version < '3':
dict_file = io.StringIO(unicode('\n').join(english_words))
else:
dict_file = io.StringIO("\n".join(english_words))
return dict_file
english_words = ["had", "a", "little", "lamb"]
dict_file = io.StringIO(u('\n').join(english_words))
return dict_file


class EnglishCheckTestCase(unittest.TestCase):
Expand Down

0 comments on commit e397b2a

Please sign in to comment.