File: test_yaml.py

package info (click to toggle)
python-mashumaro 3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,400 kB
  • sloc: python: 19,890; sh: 16; makefile: 5
file content (24 lines) | stat: -rw-r--r-- 524 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
from dataclasses import dataclass
from typing import List

import yaml

from mashumaro.mixins.yaml import DataClassYAMLMixin


def test_to_yaml():
    @dataclass
    class DataClass(DataClassYAMLMixin):
        x: List[int]

    dumped = yaml.dump({"x": [1, 2, 3]})
    assert DataClass([1, 2, 3]).to_yaml() == dumped


def test_from_yaml():
    @dataclass
    class DataClass(DataClassYAMLMixin):
        x: List[int]

    dumped = yaml.dump({"x": [1, 2, 3]})
    assert DataClass.from_yaml(dumped) == DataClass([1, 2, 3])