File: test_length.py

package info (click to toggle)
validators 0.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 332 kB
  • sloc: python: 1,556; makefile: 150
file content (37 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
import pytest

import validators


@pytest.mark.parametrize(('value', 'min', 'max'), [
    ('password', 2, 10),
    ('password', None, 10),
    ('password', 2, None),
    ('password', 8, 8)
])
def test_returns_true_on_valid_length(value, min, max):
    assert validators.length(value, min=min, max=max)


@pytest.mark.parametrize(('value', 'min', 'max'), [
    ('something', 13, 12),
    ('something', -1, None),
    ('something', -1, None),
    ('something', -3, -2)
])
def test_raises_assertion_error_for_invalid_args(value, min, max):
    with pytest.raises(AssertionError):
        assert validators.length(value, min=min, max=max)


@pytest.mark.parametrize(('value', 'min', 'max'), [
    ('something', 13, 14),
    ('something', None, 6),
    ('something', 13, None)
])
def test_returns_failed_validation_on_invalid_range(value, min, max):
    assert isinstance(
        validators.length(value, min=min, max=max),
        validators.ValidationFailure
    )