Skip to content

Commit

Permalink
test: update family test data
Browse files Browse the repository at this point in the history
  • Loading branch information
Osneil Drakes authored and Osneil Drakes committed Sep 5, 2024
1 parent 3914c69 commit 97da22c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
33 changes: 33 additions & 0 deletions gcf_data_mapper/enums/family.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from enum import Enum


class FamilyColumnsNames(Enum):
"""The fields the GCF data mapper needs to parse family data/ metadata."""

APPROVED_REF = "ApprovedRef"
COUNTRIES = "Countries"
ENTITIES = "Entities"
FUNDING = "Funding"
PROJECT_URL = "ProjectURL"
PROJECTS_ID = "ProjectsID"
RESULT_AREAS = "ResultAreas"
SECTOR = "Sector"
THEME = "Theme"


class FamilyNestedColumnNames(Enum):
"""The fields the GCF data mapper needs to parse nested family data/ metadata."""

AREA = "Area"
BUDGET = "BudgetUSDeq"
NAME = "Name"
REGION = "Region"
SOURCE = "Source"
TYPE = "Type"


class GCFProjectBudgetSource(Enum):
"""The source of financing for the project's budget funding"""

CO_FINANCING = "Co-Financing"
GCF = "GCF"
38 changes: 5 additions & 33 deletions gcf_data_mapper/parsers/family.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,20 @@
from enum import Enum
from typing import Any, Optional

import click
import pandas as pd

from gcf_data_mapper.enums.family import (
FamilyColumnsNames,
FamilyNestedColumnNames,
GCFProjectBudgetSource,
)
from gcf_data_mapper.parsers.helpers import (
check_row_for_columns_with_empty_values,
check_row_for_missing_columns,
get_value_in_nested_object,
)


class FamilyColumnsNames(Enum):
"""The fields the GCF data mapper needs to parse family data/ metadata."""

APPROVED_REF = "ApprovedRef"
COUNTRIES = "Countries"
ENTITIES = "Entities"
FUNDING = "Funding"
PROJECT_URL = "ProjectURL"
PROJECTS_ID = "ProjectsID"
RESULT_AREAS = "ResultAreas"
SECTOR = "Sector"
THEME = "Theme"


class FamilyNestedColumnNames(Enum):
"""The fields the GCF data mapper needs to parse nested family data/ metadata."""

AREA = "Area"
BUDGET = "BudgetUSDeq"
NAME = "Name"
REGION = "Region"
SOURCE = "Source"
TYPE = "Type"


class GCFProjectBudgetSource(Enum):
"""The source of financing for the project's budget funding"""

CO_FINANCING = "Co-Financing"
GCF = "GCF"


def get_budgets(row: pd.Series, source: str) -> list[int]:
"""
Get the budget amount from the row based on the funding source.
Expand Down
17 changes: 13 additions & 4 deletions tests/unit_tests/parsers/family/test_family.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Type

import pandas as pd
import pytest

Expand Down Expand Up @@ -25,9 +27,12 @@ def parsed_family_data():
]


def test_returns_expected_family_data_structure(test_family_doc_df, parsed_family_data):
def test_returns_expected_family_data_structure(
test_family_doc_df: pd.DataFrame, parsed_family_data: list[dict]
):
family_data = family(test_family_doc_df, debug=True)
assert family_data != []
assert len(family_data) == len(parsed_family_data)
assert family_data == parsed_family_data


Expand Down Expand Up @@ -71,7 +76,9 @@ def test_returns_expected_family_data_structure(test_family_doc_df, parsed_famil
),
],
)
def test_raises_error_on_validating_row(test_df, error, error_msg):
def test_raises_error_on_validating_row(
test_df: pd.DataFrame, error: Type[Exception], error_msg: str
):
with pytest.raises(error) as e:
family(test_df, debug=True)
assert error_msg in str(e.value)
Expand Down Expand Up @@ -148,7 +155,7 @@ def test_raises_error_on_validating_row(test_df, error, error_msg):
],
)
def test_returns_expected_value_when_parsing_budget_data(
test_data_series, source, expected_value
test_data_series: pd.Series, source: str, expected_value: list[int]
):
budgets = get_budgets(test_data_series, source)
assert budgets == expected_value
Expand Down Expand Up @@ -210,7 +217,9 @@ def test_returns_empty_array_when_parsing_empty_data_frame():
),
],
)
def test_raises_error_on_validating_nested_objects_for_data(test_df, error, error_msg):
def test_raises_error_on_validating_nested_objects_for_data(
test_df: pd.DataFrame, error: Type[Exception], error_msg: str
):
with pytest.raises(error) as e:
family(test_df, debug=True)
assert error_msg in str(e.value)
2 changes: 1 addition & 1 deletion tests/unit_tests/parsers/helpers/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_raises_error_for_columns_with_empty_values_in_a_given_row(
],
)
def test_raises_error_when_checking_for_value_in_nested_object(
object, key, error, error_msg
object: dict, key: str, error: Type[Exception], error_msg: str
):
with pytest.raises(error) as e:
get_value_in_nested_object(object, key)
Expand Down

0 comments on commit 97da22c

Please sign in to comment.