This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
soft-analytics-01/tests/test_cleaner_dataframe.py
Claudio Maggioni 07232eddcc Final version of the bug-triaging project
Commit history has been discarded to remove large files from the repo.
2024-01-03 15:22:56 +01:00

25 lines
650 B
Python

import pandas as pd
import pytest
from src.cleaner.dataframe import build_df
@pytest.fixture
def sample_objs():
return [
{'id': 1, 'name': 'Alice', 'age': 25},
{'id': 2, 'name': 'Bob', 'age': 30},
{'id': 3, 'name': 'Charlie', 'age': 22}
]
def test_build_df(sample_objs):
result_df = build_df(sample_objs)
assert isinstance(result_df, pd.DataFrame)
assert set(result_df.columns) == {'name', 'age'}
def test_build_df_missing_id_column():
objs_missing_id = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}]
with pytest.raises(KeyError, match="'id'"):
build_df(objs_missing_id)