コード例 #1
0
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})
コード例 #2
0
ファイル: tests.py プロジェクト: tuukkamustonen/voluptuous
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})
コード例 #3
0
ファイル: tests.py プロジェクト: lican09/voluptuous
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']")
コード例 #4
0
ファイル: tests.py プロジェクト: lican09/voluptuous
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']")
コード例 #5
0
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']")
コード例 #6
0
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']")
コード例 #7
0
ファイル: tests.py プロジェクト: lican09/voluptuous
def test_to_utf8():
    s = u('hello')
    assert_true(isinstance(to_utf8_py2(s), str))
コード例 #8
0
def test_to_utf8():
    s = u('hello')
    assert_true(isinstance(to_utf8_py2(s), str))