Coverage for tests / test_pydanticv2_dataclasses_uuid_stringified_annotations.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from __future__ import annotations 1abcd

2 

3import uuid 1abcd

4from dataclasses import dataclass, field 1abcd

5 

6from dirty_equals import IsUUID 1abcd

7from fastapi import FastAPI 1abcd

8from fastapi.testclient import TestClient 1abcd

9from inline_snapshot import snapshot 1abcd

10 

11 

12@dataclass 1abcd

13class Item: 1abcd

14 id: uuid.UUID 1abcd

15 name: str 1abcd

16 price: float 1abcd

17 tags: list[str] = field(default_factory=list) 1abcd

18 description: str | None = None 1abcd

19 tax: float | None = None 1abcd

20 

21 

22app = FastAPI() 1abcd

23 

24 

25@app.get("/item", response_model=Item) 1abcd

26async def read_item(): 1abcd

27 return { 1efgh

28 "id": uuid.uuid4(), 

29 "name": "Island In The Moon", 

30 "price": 12.99, 

31 "description": "A place to be be playin' and havin' fun", 

32 "tags": ["breater"], 

33 } 

34 

35 

36client = TestClient(app) 1abcd

37 

38 

39def test_annotations(): 1abcd

40 response = client.get("/item") 1efgh

41 assert response.status_code == 200, response.text 1efgh

42 assert response.json() == snapshot( 1efgh

43 { 

44 "id": IsUUID(), 

45 "name": "Island In The Moon", 

46 "price": 12.99, 

47 "tags": ["breater"], 

48 "description": "A place to be be playin' and havin' fun", 

49 "tax": None, 

50 } 

51 )