|
| 1 | +"""Unit tests for utils/models_dumper module.""" |
| 2 | + |
| 3 | +from json import load |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +from utils.models_dumper import dump_models |
| 7 | + |
| 8 | + |
| 9 | +def test_dump_models(tmpdir: Path) -> None: |
| 10 | + """Test that models can be dump into a JSON file. |
| 11 | +
|
| 12 | + An example of schema dump: |
| 13 | + { |
| 14 | + "openapi": "3.0.0", |
| 15 | + "info": { |
| 16 | + "title": "Lightspeed Core Stack", |
| 17 | + "version": "0.3.0" |
| 18 | + }, |
| 19 | + "components": { |
| 20 | + "schemas": { |
| 21 | + "ConversationSummary": { |
| 22 | + "description": "A single compaction-produced summary chunk.\n\nAttributes:\n", |
| 23 | + "properties": { |
| 24 | + "summary_text": { |
| 25 | + "description": "Natural-language summary produced by the ...", |
| 26 | + "title": "Summary text", |
| 27 | + "type": "string" |
| 28 | + }, |
| 29 | + "summarized_through_turn": { |
| 30 | + "description": "Running total of conversation items consumed by this ...", |
| 31 | + "minimum": 0, |
| 32 | + "title": "Summarized through turn", |
| 33 | + "type": "integer" |
| 34 | + }, |
| 35 | + "token_count": { |
| 36 | + "description": "Number of tokens in summary_text.", |
| 37 | + "minimum": 0, |
| 38 | + "title": "Token count", |
| 39 | + "type": "integer" |
| 40 | + }, |
| 41 | + "created_at": { |
| 42 | + "description": "ISO 8601 timestamp recording when this summary ...", |
| 43 | + "title": "Created at", |
| 44 | + "type": "string" |
| 45 | + }, |
| 46 | + "model_used": { |
| 47 | + "description": "Fully-qualified model identifier used for the ...", |
| 48 | + "title": "Model used", |
| 49 | + "type": "string" |
| 50 | + } |
| 51 | + }, |
| 52 | + "required": [ |
| 53 | + "summary_text", |
| 54 | + "summarized_through_turn", |
| 55 | + "token_count", |
| 56 | + "created_at", |
| 57 | + "model_used" |
| 58 | + ], |
| 59 | + "title": "ConversationSummary", |
| 60 | + "type": "object" |
| 61 | + } |
| 62 | + } |
| 63 | + }, |
| 64 | + "paths": {} |
| 65 | + } |
| 66 | + """ |
| 67 | + filename = tmpdir / "foo.json" |
| 68 | + dump_models(str(filename)) |
| 69 | + |
| 70 | + with open(filename, "r", encoding="utf-8") as fin: |
| 71 | + # schema should be stored in JSON format |
| 72 | + content = load(fin) |
| 73 | + assert content is not None |
| 74 | + |
| 75 | + # top-level keys test |
| 76 | + keys = ("openapi", "info", "components", "paths") |
| 77 | + for key in keys: |
| 78 | + assert key in content |
| 79 | + |
| 80 | + # components should be top-level node |
| 81 | + components = content["components"] |
| 82 | + assert components is not None |
| 83 | + |
| 84 | + # schemas should be a node stored inside components node |
| 85 | + assert "schemas" in components |
| 86 | + schemas = components["schemas"] |
| 87 | + assert schemas is not None |
| 88 | + |
| 89 | + # list of schemas expected in a dump |
| 90 | + expected_schemas = ("ConversationSummary",) |
| 91 | + for expected_schema in expected_schemas: |
| 92 | + assert expected_schema in schemas |
0 commit comments