ai-interview-mentor / tests /test_csv_parser.py
samar m
feat: add CSV question parser utility with unit tests
d8394f9
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"