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])
|