Skip to content

Commit

Permalink
Use six to manage unicode strings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwri committed Sep 28, 2016
1 parent 5a9e2ee commit 4d58148
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
],
install_requires=[
'setuptools >= 0.6b1',
'six >= 1.10'
]
)
24 changes: 7 additions & 17 deletions voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,8 @@ def fn(arg):

def test_unicode_key_is_converted_to_utf8_when_in_marker():
"""Verify that when using unicode key the 'u' prefix is not thrown in the exception"""
import sys
if sys.version_info >= (3,):
schema = Schema({Required('q'): 1})
else:
schema = Schema({Required(u'q'): 1})
import six
schema = Schema({Required(six.u('q')): 1})
# Can't use nose's raises (because we need to access the raised
# exception, nor assert_raises which fails with Python 2.6.9.
try:
Expand All @@ -574,13 +571,9 @@ def test_unicode_key_is_converted_to_utf8_when_in_marker():


def test_unicode_key_is_converted_to_utf8_when_plain_text():
import sys
if sys.version_info >= (3,):
schema = Schema({'q': int})
key = 'q'
else:
schema = Schema({u'q': int})
key = u'q'
import six
key = six.u('q')
schema = Schema({key: int})
# Can't use nose's raises (because we need to access the raised
# exception, nor assert_raises which fails with Python 2.6.9.
try:
Expand All @@ -590,10 +583,7 @@ def test_unicode_key_is_converted_to_utf8_when_plain_text():


def test_to_utf8_py2():
import sys
import six
from voluptuous.encoding import to_utf8_py2
if sys.version_info >= (3,):
s = 'hello'
else:
s = u'hello'
s = six.u('hello')
assert_true(isinstance(to_utf8_py2(s), str))

0 comments on commit 4d58148

Please sign in to comment.