|
| 1 | +"""Pytest tests for the datasets module.""" |
| 2 | + |
| 3 | +from lettucedetect.datasets.hallucination_dataset import HallucinationSample |
| 4 | + |
| 5 | + |
| 6 | +def test_from_json_with_minimal_keys(): |
| 7 | + """Test that from_json handles data missing optional dataset/language keys.""" |
| 8 | + sample = HallucinationSample.from_json( |
| 9 | + { |
| 10 | + "prompt": "User request: What is AI?\n\nAI is artificial intelligence.", |
| 11 | + "answer": "AI stands for Artificial Intelligence.", |
| 12 | + "labels": [], |
| 13 | + "split": "test", |
| 14 | + "task_type": "qa", |
| 15 | + } |
| 16 | + ) |
| 17 | + assert sample.prompt == "User request: What is AI?\n\nAI is artificial intelligence." |
| 18 | + assert sample.answer == "AI stands for Artificial Intelligence." |
| 19 | + assert sample.labels == [] |
| 20 | + assert sample.split == "test" |
| 21 | + assert sample.task_type == "qa" |
| 22 | + assert sample.dataset == "unknown" |
| 23 | + assert sample.language == "en" |
| 24 | + |
| 25 | + |
| 26 | +def test_from_json_explicit_dataset_language(): |
| 27 | + """Test that explicit dataset and language keys are preserved.""" |
| 28 | + sample = HallucinationSample.from_json( |
| 29 | + { |
| 30 | + "prompt": "Test prompt", |
| 31 | + "answer": "Test answer", |
| 32 | + "labels": [{"start": 0, "end": 4, "label": "intrinsic"}], |
| 33 | + "split": "train", |
| 34 | + "task_type": "summarization", |
| 35 | + "dataset": "cnn_dailymail", |
| 36 | + "language": "de", |
| 37 | + } |
| 38 | + ) |
| 39 | + assert sample.dataset == "cnn_dailymail" |
| 40 | + assert sample.language == "de" |
0 commit comments