Spaces:
Sleeping
Sleeping
File size: 1,346 Bytes
d8394f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | from backend.utils.csv_parser import parse_csv_questions
def test_parses_valid_csv():
text = "question_text,difficulty\nWhat is Python?,easy\nExplain GIL,hard"
result = parse_csv_questions(text)
assert len(result) == 2
assert result[0] == {"question_text": "What is Python?", "difficulty": "easy"}
assert result[1] == {"question_text": "Explain GIL", "difficulty": "hard"}
def test_defaults_invalid_difficulty_to_medium():
text = "question_text,difficulty\nWhat is Python?,bogus"
result = parse_csv_questions(text)
assert result[0]["difficulty"] == "medium"
def test_skips_empty_question_text():
text = "question_text,difficulty\n,easy\nWhat is Python?,easy"
result = parse_csv_questions(text)
assert len(result) == 1
def test_missing_difficulty_column_defaults_to_medium():
text = "question_text\nWhat is Python?"
result = parse_csv_questions(text)
assert result[0]["difficulty"] == "medium"
def test_empty_csv_returns_empty_list():
text = "question_text,difficulty\n"
result = parse_csv_questions(text)
assert result == []
def test_strips_whitespace():
text = "question_text,difficulty\n What is Python? , easy "
result = parse_csv_questions(text)
assert result[0]["question_text"] == "What is Python?"
assert result[0]["difficulty"] == "easy"
|