File: test_boolean.py

package info (click to toggle)
python-ical 12.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,776 kB
  • sloc: python: 15,157; sh: 9; makefile: 5
file content (47 lines) | stat: -rw-r--r-- 1,235 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
42
43
44
45
46
47
"""Tests for BOOLEAN data types."""

import pytest

from ical.component import ComponentModel
from ical.exceptions import CalendarParseError
from ical.parsing.property import ParsedProperty


class FakeModel(ComponentModel):
    """Model under test."""

    example: bool


def test_bool() -> None:
    """Test for boolean fields."""

    model = FakeModel.model_validate(
        {"example": [ParsedProperty(name="example", value="TRUE")]}
    )
    assert model.example

    model = FakeModel.model_validate(
        {"example": [ParsedProperty(name="example", value="FALSE")]}
    )
    assert not model.example

    with pytest.raises(CalendarParseError):
        FakeModel.model_validate(
            {"example": [ParsedProperty(name="example", value="efd")]}
        )

    # Populate based on bool object
    model = FakeModel(example=True)
    assert model.example
    component = model.__encode_component_root__()
    assert component.properties == [
        ParsedProperty(name="example", value="TRUE"),
    ]

    model = FakeModel(example=False)
    assert not model.example
    component = model.__encode_component_root__()
    assert component.properties == [
        ParsedProperty(name="example", value="FALSE"),
    ]