File: test_invalid.py

package info (click to toggle)
python-tomli-w 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,476 kB
  • sloc: python: 614; makefile: 5
file content (40 lines) | stat: -rw-r--r-- 1,098 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
from datetime import time, timezone

import pytest

import tomli_w


def test_invalid_type_nested():
    with pytest.raises(TypeError) as exc_info:
        tomli_w.dumps({"bytearr": bytearray()})
    assert str(exc_info.value) == "Object of type 'bytearray' is not TOML serializable"


def test_invalid_time():
    offset_time = time(23, 59, 59, tzinfo=timezone.utc)
    with pytest.raises(ValueError):
        tomli_w.dumps({"offset time": offset_time})


def test_negative_indent():
    with pytest.raises(ValueError):
        tomli_w.dumps({"k": "v"}, indent=-1)


def test_invalid_key__falsy():
    with pytest.raises(TypeError) as exc_info:
        tomli_w.dumps({None: "v"})  # type: ignore[dict-item]
    assert (
        str(exc_info.value)
        == "Invalid mapping key 'None' of type 'NoneType'. A string is required."
    )


def test_invalid_key__truthy():
    with pytest.raises(TypeError) as exc_info:
        tomli_w.dumps({2: "v"})  # type: ignore[dict-item]
    assert (
        str(exc_info.value)
        == "Invalid mapping key '2' of type 'int'. A string is required."
    )