File: test_flags.py

package info (click to toggle)
wtforms 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,064 kB
  • sloc: python: 5,264; makefile: 27; sh: 17
file content (41 lines) | stat: -rw-r--r-- 934 bytes parent folder | download
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
38
39
40
41
import pytest

from wtforms import validators
from wtforms.fields import StringField
from wtforms.form import Form


@pytest.fixture()
def flags():
    return StringField(validators=[validators.DataRequired()]).bind(Form(), "a").flags


def test_existing_values(flags):
    assert flags.required is True
    assert "required" in flags
    assert flags.optional is None
    assert "optional" not in flags


def test_assignment(flags):
    assert "optional" not in flags
    flags.optional = True
    assert flags.optional is True
    assert "optional" in flags


def test_unset(flags):
    flags.required = False
    assert flags.required is False
    assert "required" not in flags


def test_repr(flags):
    assert repr(flags) == "<wtforms.fields.Flags: {required=True}>"


def test_underscore_property(flags):
    with pytest.raises(AttributeError):
        flags._foo  # noqa: B018
    flags._foo = 42
    assert flags._foo == 42