|
2 | 2 | import pytest |
3 | 3 | from bcb.sgs.regional_economy import get_non_performing_loans, get_non_performing_loans_codes |
4 | 4 | from bcb.utils import BRAZILIAN_REGIONS |
| 5 | +from bcb.sgs import regional_economy |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class TestGetNonPerformingLoansCodes: |
@@ -34,3 +35,33 @@ def test_get_series_by_region_pj(self): |
34 | 35 | assert isinstance(series, pd.DataFrame) |
35 | 36 | assert (series.columns == south_states).all() |
36 | 37 | assert len(series) == 5 |
| 38 | + |
| 39 | + |
| 40 | +class TestNonPerformingLoansCodes: |
| 41 | + @pytest.fixture |
| 42 | + def non_performing_constants(self): |
| 43 | + constants = [ |
| 44 | + item |
| 45 | + for item in dir(regional_economy) |
| 46 | + if item.startswith("NON_PERFORMING_LOANS_BY") |
| 47 | + ] |
| 48 | + return constants |
| 49 | + |
| 50 | + def test_if_all_regions_and_states_are_there(self, non_performing_constants): |
| 51 | + states = [] |
| 52 | + for state in BRAZILIAN_REGIONS.values(): |
| 53 | + states.extend(state) |
| 54 | + for item_str in non_performing_constants: |
| 55 | + item = getattr(regional_economy, item_str) |
| 56 | + if "REGION" in str(item): |
| 57 | + assert (list(item.values()) == list(BRAZILIAN_REGIONS.keys())), item_str |
| 58 | + elif "STATE" in str(item): |
| 59 | + assert (list(item.values()) == states), item_str |
| 60 | + |
| 61 | + def test_check_if_codes_are_unique(self, non_performing_constants): |
| 62 | + for item_str in non_performing_constants: |
| 63 | + item = getattr(regional_economy, item_str) |
| 64 | + |
| 65 | + unique_values = set(item.values()) |
| 66 | + assert all(unique_values), item_str |
| 67 | + assert (len(item.values()) == len(unique_values)), item_str |
0 commit comments