Ejemplo n.º 1
0
def test_check_string_control_characters():
    for string in ['foo \b  bar', 'foo\u200bbar', 'foo\0bar', 'foo\bbar']:
        with raises(Exception) as got:
            check_string(string, 'var name')
        assert_exception_correct(
            got.value,
            IllegalParameterError('var name contains control characters'))
Ejemplo n.º 2
0
def test_check_string_long_fail():
    for string, length in {'123456789': 8, 'ab': 1, 'a' * 100: 99}.items():
        with raises(Exception) as got:
            check_string(string, 'var name', max_len=length)
        assert_exception_correct(
            got.value,
            IllegalParameterError(
                f'var name exceeds maximum length of {length}'))
Ejemplo n.º 3
0
def test_check_string_max_len():
    for string, length in {
            '123456789': 9,
            'a': 1,
            'a' * 100: 100,
            'a' * 10000: 10000,
            'a' * 10000: 1000000
    }.items():
        assert check_string(string, 'name', max_len=length) == string
Ejemplo n.º 4
0
def test_check_string():
    for string, expected in {
            '    foo': 'foo',
            '  \t   baɷr     ': 'baɷr',
            'baᚠz  \t  ': 'baᚠz',
            'bat': 'bat',
            'a' * 1000: 'a' * 1000
    }.items():
        assert check_string(string, 'name') == expected
Ejemplo n.º 5
0
def test_check_string_optional_false():
    for string in [None, '   \t   ']:
        with raises(Exception) as got:
            check_string(string, 'var name')
        assert_exception_correct(got.value, MissingParameterError('var name'))
Ejemplo n.º 6
0
def test_check_string_optional_true():
    for string in [None, '   \t   ']:
        assert check_string(string, 'name', optional=True) is None
Ejemplo n.º 7
0
def test_check_string_bad_max_len():
    for max_len in [0, -1, -100]:
        with raises(Exception) as got:
            check_string('str', 'var name', max_len=max_len)
        assert_exception_correct(got.value,
                                 ValueError('max_len must be > 0 if provided'))