Skip to content

Commit

Permalink
Test enums can be serialized to TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Sep 2, 2021
1 parent e4752c3 commit 47faae7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_extended_converters.py
Expand Up @@ -3,6 +3,8 @@
# pylint: disable=unused-variable


from enum import Enum

import pytest

from datafiles import datafile
Expand Down Expand Up @@ -111,3 +113,23 @@ def with_extra_newlines(sample, expect):
sample.datafile.save()

expect(sample.text) == "abc\ndef\n"


def describe_enum():
def as_toml(expect):
class FileOutputType(Enum):
IN_MESSAGE = 1
FILESYSTEM = 2

@datafile('../tmp/sample.toml')
class Sample:
path_type: FileOutputType = FileOutputType.IN_MESSAGE

sample = Sample()
sample.path_type = FileOutputType.FILESYSTEM

expect(read('tmp/sample.toml')) == dedent(
"""
path_type = 2
"""
)

0 comments on commit 47faae7

Please sign in to comment.