def test_unicode_as_key(): if sys.version_info >= (3, ): text_type = str else: text_type = unicode schema = Schema({text_type: int}) schema({u("foobar"): 1})
def test_unicode_as_key(): if sys.version_info >= (3,): text_type = str else: text_type = unicode schema = Schema({text_type: int}) schema({u("foobar"): 1})
def test_unicode_key_is_converted_to_utf8_when_plain_text(): key = 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: schema({key: 'will fail'}) except Invalid as e: assert_equal(str(e), "expected int for dictionary value @ data['q']")
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""" schema = Schema({Required(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: schema({}) except Invalid as e: assert_equal(str(e), "required key not provided @ data['q']")
def test_to_utf8(): s = u('hello') assert_true(isinstance(to_utf8_py2(s), str))