コード例 #1
0
ファイル: test_slicing.py プロジェクト: kaiba-tech/kaiba
def test_invalid_type():
    """Test that we get validation error with correct message."""
    with pytest.raises(ValidationError) as ve:
        Slicing(**{'from': 'test'})

    errors = ve.value.errors()[0]  # noqa: WPS441
    assert errors['loc'] == ('from',)
    assert errors['msg'] == 'value is not a valid integer'
コード例 #2
0
ファイル: test_slicing.py プロジェクト: kaiba-tech/kaiba
def test_invalid():
    """Test that we get validation error with correct message."""
    with pytest.raises(ValidationError) as ve:
        Slicing(to=0)

    errors = ve.value.errors()[0]  # noqa: WPS441
    assert errors['loc'] == ('from',)
    assert errors['msg'] == 'field required'
コード例 #3
0
def test_slice_range_on_range_out_of_string():
    """Test that slice range out of the string."""
    assert apply_slicing(
        '0123',
        Slicing(**{
            'from': 5,
            'to': 10
        }),
    ) == ''
コード例 #4
0
def test_slice_range_longer_than_string():
    """Test that slice range longer than the string length returns string."""
    assert apply_slicing(
        '0123',
        Slicing(**{
            'from': 0,
            'to': 50
        }),
    ) == '0123'
コード例 #5
0
def test_list():
    """Test that we can slice a list and that its not cast to string."""
    assert apply_slicing(
        [0, 1, 2],
        Slicing(**{
            'from': 1,
            'to': None
        }),
    ) == [1, 2]
コード例 #6
0
def test_object_is_stringified():
    """Test that an object is stringified."""
    assert apply_slicing(
        {'test': 'bob'},
        Slicing(**{
            'from': -5,
            'to': -2
        }),
    ) == 'bob'
コード例 #7
0
def test_negative_to():
    """Test that a negative to value ends cut at end minus to."""
    assert apply_slicing(
        '01234',
        Slicing(**{
            'from': 0,
            'to': -2
        }),
    ) == '012'
コード例 #8
0
def test_boolean_is_stringified():
    """Test that a boolean value is stringfied."""
    assert apply_slicing(
        False,  # noqa: WPS425
        Slicing(**{
            'from': 0,
            'to': 1
        }),
    ) == 'F'
コード例 #9
0
def test_middle_of_value():
    """Test that we can get a value in middle of string."""
    assert apply_slicing('test', Slicing(**{'from': 1, 'to': 3})) == 'es'
コード例 #10
0
def test_start_to_middle():
    """Test that we can slice from start to middle."""
    assert apply_slicing('test', Slicing(**{'from': 0, 'to': 3})) == 'tes'
コード例 #11
0
def test_float_is_stringified():
    """Test that a float value is stringfied."""
    assert apply_slicing(123.123, Slicing(**{'from': -3})) == '123'
コード例 #12
0
def test_int_is_stringified():
    """Test that a non string value will be stringified before slice."""
    assert apply_slicing(123, Slicing(**{'from': 2})) == '3'
コード例 #13
0
def test_no_value_is_ok():
    """When value is None we get a Success(None)."""
    assert apply_slicing(None, Slicing(**{'from': 0})) is None
コード例 #14
0
def test_negative_from():
    """Test that a negative from value starts cutting at the end minus from."""
    assert apply_slicing('012345', Slicing(**{'from': -2})) == '45'
コード例 #15
0
def test_start_to_end():
    """Test that we can slice from start to end."""
    assert apply_slicing('test', Slicing(**{'from': 0, 'to': None})) == 'test'
コード例 #16
0
ファイル: test_slicing.py プロジェクト: kaiba-tech/kaiba
def test_validates():  # noqa: WPS218
    """Test that dict is marshalled to pydantic object."""
    test = Slicing(**{'from': 0})
    assert test.slice_from == 0
    assert test.slice_to is None
コード例 #17
0
def test_middle_to_end():
    """Test that we can slice from middle to end of value."""
    assert apply_slicing('test', Slicing(**{'from': 1})) == 'est'