mirror of
https://github.com/simon987/hexlib.git
synced 2025-12-14 07:09:05 +00:00
Fix JSON encoding for Enums
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
from unittest import TestCase
|
||||
|
||||
from pydantic import BaseModel
|
||||
@@ -8,6 +10,11 @@ from pydantic.types import List
|
||||
from hexlib.db import PersistentState
|
||||
|
||||
|
||||
class Status(Enum):
|
||||
yes = "yes"
|
||||
no = "no"
|
||||
|
||||
|
||||
class Point(BaseModel):
|
||||
x: int
|
||||
y: int
|
||||
@@ -16,6 +23,7 @@ class Point(BaseModel):
|
||||
class Polygon(BaseModel):
|
||||
points: List[Point] = []
|
||||
created_date: datetime
|
||||
status: Status = Status("yes")
|
||||
|
||||
|
||||
class TestPydanticTable(TestCase):
|
||||
@@ -35,12 +43,13 @@ class TestPydanticTable(TestCase):
|
||||
points=[
|
||||
Point(x=1, y=2),
|
||||
Point(x=3, y=4),
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
s["a"]["1"] = val
|
||||
|
||||
self.assertEqual(s["a"]["1"].points[0].x, 1)
|
||||
self.assertEqual(s["a"]["1"].status, Status("yes"))
|
||||
self.assertEqual(s["a"]["1"].points[1].x, 3)
|
||||
self.assertEqual(s["a"]["1"].created_date.year, 2000)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user