예제 #1
0
def get_related_tags_for_series_search_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "search_words": (
            "mortgage",
            "rate",
            "index",
        ),
        "tag_names": (
            "30-year",
            "frb",
        ),
        #            'tag_search_words': ('', '',),
        "limit": 3,
        "realtime_end": "2020-02-13",
        "order_by": "name",
        "sort_order": "desc",
        "offset": 2,
    }
    fred.get_related_tags_for_series_search(**params)
    returned_ok_params["observed"] = fred.series_stack[
        "get_related_tags_for_series_search"
    ]
    params.pop("search_words")
    params.pop("tag_names")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("tags",)
    return returned_ok(**returned_ok_params)
예제 #2
0
def get_series_matching_tags_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "tag_names": (
            "slovenia",
            "food",
            "oecd",
        ),
        "limit": 2,
        "offset": 1,
        "order_by": "seasonal_adjustment",
        "sort_order": "desc",
        #            'realtime_start': '2000-01-01',
        "realtime_end": "2003-01-01",
    }
    fred.get_series_matching_tags(**params)
    returned_ok_params["observed"] = fred.tag_stack["get_series_matching_tags"]
    params.pop("tag_names")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = (
        "series",
        "seriess",
    )
    return returned_ok(**returned_ok_params)
예제 #3
0
def search_for_series_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "search_words": (
            "monetary",
            "service",
            "index",
        ),
        "limit": 3,
        "realtime_end": "2019-06-03",
        #            'search_type': 'series_id',
        "order_by": "title",
        "sort_order": "desc",
        "offset": 2,
    }
    fred.search_for_series(**params)
    returned_ok_params["observed"] = fred.series_stack["search_for_series"]
    params.pop("search_words")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = (
        "seriess",
        "series",
    )
    return returned_ok(**returned_ok_params)
예제 #4
0
def get_a_category_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    fred.get_a_category()  # root category of 0
    returned_ok_params["observed"] = fred.category_stack["get_a_category"]
    returned_ok_params["check_union"] = ("categories",)
    return returned_ok(**returned_ok_params)
예제 #5
0
def test_get_series_updates_raises_type_error(
    fred: Fred,
):
    """
    Test TypeError raised when only one of start_time, end_time is
    passed
    """
    with pytest.raises(TypeError):
        fred.get_series_updates(start_time="202103210851")
예제 #6
0
def test_api_key_file_works_with_get_a_category_method(
    fred: Fred,
) -> bool:
    fred.get_a_category(0)
    returned_ok_params = {
        "observed": fred.category_stack["get_a_category"],
        "check_union": ("categories",),
    }
    return returned_ok(**returned_ok_params)
예제 #7
0
def get_related_categories_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "category_id": 32073,
    }
    fred.get_related_categories(**params)
    returned_ok_params["observed"] = fred.category_stack["get_related_categories"]
    returned_ok_params["check_union"] = ("categories",)
    return returned_ok(**returned_ok_params)
예제 #8
0
def get_a_source_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "source_id": 1,
        "realtime_end": "2009-04-09",
    }
    fred.get_a_source(**params)
    returned_ok_params["observed"] = fred.source_stack["get_a_source"]
    returned_ok_params["check_union"] = ("sources", )
    return returned_ok(**returned_ok_params)
예제 #9
0
def get_a_release_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "release_id": 53,
        "realtime_end": "2018-02-02",
    }
    fred.get_a_release(**params)
    returned_ok_params["observed"] = fred.release_stack["get_a_release"]
    params.pop("release_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("releases", )
    return returned_ok(**returned_ok_params)
예제 #10
0
def get_release_for_a_series_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "series_id": "IRA",
        "realtime_end": "2014-07-04",
    }
    fred.get_release_for_a_series(**params)
    returned_ok_params["observed"] = fred.series_stack["get_release_for_a_series"]
    params.pop("series_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("releases",)
    return returned_ok(**returned_ok_params)
예제 #11
0
def test_get_series_updates_raises_value_error(
    fred: Fred,
):
    """
    Test ValueError raised when current time - end_time > 2 weeks.
    FRED's servers send error code 500 for start dates earlier than
    last 2 weeks. if end_date is earlier than last 2 weeks, FRED will
    return 500 error code
    """
    params = {
        "start_time": "202103110851",
        "end_time": "202103210851",
    }
    with pytest.raises(ValueError):
        fred.get_series_updates(**params)
예제 #12
0
def get_sources_for_a_release_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "release_id": 51,
        "realtime_start": "2020-12-24",
    }
    fred.get_sources_for_a_release(**params)
    returned_ok_params["observed"] = fred.release_stack[
        "get_sources_for_a_release"]
    params.pop("release_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("sources", )
    return returned_ok(**returned_ok_params)
예제 #13
0
def get_categories_of_series_method_works(
    fred: Fred,
    returned_ok_params: dict,
):
    params = {
        "series_id": "EXJPUS",
        # EXJPUS doesn't exist in ALFRED, forego realtime param
        #            'realtime_end': '1995-12-01',
    }
    fred.get_categories_of_series(**params)
    returned_ok_params["observed"] = fred.series_stack["get_categories_of_series"]
    params.pop("series_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("categories",)
    return returned_ok(**returned_ok_params)
예제 #14
0
def get_all_sources_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "limit": 2,
        "realtime_start": "2000-01-01",
        "sort_order": "desc",
        "order_by": "name",
    }
    fred.get_all_sources(**params)
    returned_ok_params["observed"] = fred.source_stack["get_all_sources"]
    returned_ok_params["check_union"] = ("sources", )
    returned_ok_params["expected"] = params
    return returned_ok(**returned_ok_params)
예제 #15
0
def get_all_releases_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "limit": 2,
        "realtime_start": "2018-02-02",
        "offset": 1,
        "sort_order": "desc",
        "order_by": "press_release",
    }
    fred.get_all_releases(**params)
    returned_ok_params["observed"] = fred.release_stack["get_all_releases"]
    returned_ok_params["check_union"] = ("releases", )
    returned_ok_params["expected"] = params
    return returned_ok(**returned_ok_params)
예제 #16
0
def get_tags_for_a_series_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "series_id": "STLFSI",
        "realtime_end": "2019-02-13",
        "order_by": "name",
        "sort_order": "desc",
    }
    fred.get_tags_for_a_series(**params)
    returned_ok_params["observed"] = fred.series_stack["get_tags_for_a_series"]
    params.pop("series_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("tags",)
    return returned_ok(**returned_ok_params)
예제 #17
0
def get_a_series_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "series_id": "GNPCA",
        "realtime_start": "2007-11-01",
    }
    fred.get_a_series(**params)
    returned_ok_params["observed"] = fred.series_stack["get_a_series"]
    params.pop("series_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = (
        "series",
        "seriess",
    )
    return returned_ok(**returned_ok_params)
예제 #18
0
def get_release_tables_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "release_id": 53,
        "element_id": 12886,
        "include_observation_values": True,
    }
    fred.get_release_tables(**params)
    returned_ok_params["observed"] = fred.release_stack["get_release_tables"]
    params.pop("include_observation_values")
    returned_ok_params["expected"] = params
    str_release_id = str(returned_ok_params["expected"]["release_id"])
    returned_ok_params["expected"]["release_id"] = str_release_id
    returned_ok_params["check_union"] = ("elements", )
    return returned_ok(**returned_ok_params)
예제 #19
0
def get_releases_for_a_source_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "source_id": 1,
        "limit": 3,
        "realtime_start": "2019-08-22",
        "order_by": "press_release",
        "sort_order": "desc",
    }
    fred.get_releases_for_a_source(**params)
    returned_ok_params["observed"] = fred.source_stack[
        "get_releases_for_a_source"]
    params.pop("source_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("releases", )
    return returned_ok(**returned_ok_params)
예제 #20
0
def get_tags_for_a_category_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "category_id": 125,
        "limit": 3,
        "realtime_end": "2018-05-22",
        "order_by": "created",
        "sort_order": "desc",
        "offset": 1,
    }
    fred.get_tags_for_a_category(**params)
    returned_ok_params["observed"] = fred.category_stack["get_tags_for_a_category"]
    params.pop("category_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("tags",)
    return returned_ok(**returned_ok_params)
예제 #21
0
def get_release_dates_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "release_id": 82,
        "limit": 3,
        "realtime_end": "2015-02-02",
        "include_empty": True,
        "offset": 1,
        "sort_order": "desc",
    }
    fred.get_release_dates(**params)
    returned_ok_params["observed"] = fred.release_stack["get_release_dates"]
    params.pop("release_id")
    params.pop("include_empty")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("release_dates", )
    return returned_ok(**returned_ok_params)
예제 #22
0
def get_all_tags_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "limit": 2,
        "realtime_start": "1950-12-19",
        "sort_order": "desc",
        "tag_names": (
            "gdp",
            "oecd",
        ),
        "order_by": "name",
    }
    fred.get_all_tags(**params)
    returned_ok_params["observed"] = fred.tag_stack["get_all_tags"]
    params.pop("tag_names")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("tags", )
    return returned_ok(**returned_ok_params)
예제 #23
0
def get_series_updates_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "limit": 3,
        "filter_value": "regional",
        "offset": 2,
        "start_time": make_time_string(start=True),
        "end_time": make_time_string(start=False),
    }
    fred.get_series_updates(**params)
    returned_ok_params["observed"] = fred.series_stack["get_series_updates"]
    params.pop("start_time")
    params.pop("end_time")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = (
        "seriess",
        "series",
    )
    return returned_ok(**returned_ok_params)
예제 #24
0
def get_tags_for_a_release_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "release_id": 86,
        "limit": 3,
        "realtime_start": "2018-10-18",
        "tag_names": "gnp",
        "offset": 3,
        "sort_order": "desc",
        "order_by": "created",
    }
    fred.get_tags_for_a_release(**params)
    returned_ok_params["observed"] = fred.release_stack[
        "get_tags_for_a_release"]
    returned_ok_params["check_union"] = ("tags", )
    params.pop("release_id")
    params.pop("tag_names")
    returned_ok_params["expected"] = params
    return returned_ok(**returned_ok_params)
예제 #25
0
def get_series_df_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "series_id": "GNPCA",
        "limit": 10,
        "realtime_start": "2003-01-01",
        #            'units': 'log',
        "sort_order": "desc",
        "offset": 1,
        "observation_start": "1776-07-04",
        "observation_end": "9999-12-31",
    }
    fred.get_series_df(**params)
    returned_ok_params["observed"] = fred.series_stack["get_series_df"]
    if not "observation_start" in returned_ok_params["observed"].keys():
        return False

    # 1600-01-01 was returned for 1776-07-04
    expected_obs_start = (
        "1776-07-04",
        "1600-01-01",
    )
    if returned_ok_params["observed"]["observation_start"] not in expected_obs_start:
        return False
    params.pop("observation_start")

    # series_id is manually added to metadata of DataFrame,
    # so series_id in params is retained as an expected key
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = (
        "df",
        "observations",
    )
    if not returned_ok(**returned_ok_params):
        return False
    if isinstance(returned_ok_params["observed"]["df"], DataFrame):
        return True
    return False
예제 #26
0
def get_series_in_a_category_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "category_id": 125,
        "limit": 3,
        "realtime_start": "2020-01-01",
        "filter_variable": "units",
        "order_by": "units",
        "sort_order": "desc",
        "offset": 1,
    }
    fred.get_series_in_a_category(**params)
    returned_ok_params["observed"] = fred.category_stack["get_series_in_a_category"]
    params.pop("category_id")
    params.pop("filter_variable")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = (
        "series",
        "seriess",
    )
    return returned_ok(**returned_ok_params)
예제 #27
0
def get_tags_for_series_search_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "search_words": (
            "monetary",
            "service",
            "index",
        ),
        "limit": 3,
        "realtime_end": "2019-06-03",
        #            'tag_search_words': ('', '',),
        "order_by": "created",
        "sort_order": "desc",
        "offset": 2,
    }
    fred.get_tags_for_series_search(**params)
    returned_ok_params["observed"] = fred.series_stack["get_tags_for_series_search"]
    params.pop("search_words")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("tags",)
    return returned_ok(**returned_ok_params)
예제 #28
0
def get_related_tags_for_a_tag_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "tag_names": ("monetary aggregates", "weekly"),
        "limit": 2,
        "tag_group_id": "geo",
        "order_by": "name",
        "sort_order": "desc",
        "search_text": (
            "beans",
            "cabbage",
        ),
    }
    fred.get_related_tags_for_a_tag(**params)
    returned_ok_params["observed"] = fred.tag_stack[
        "get_related_tags_for_a_tag"]
    params.pop("tag_names")
    params.pop("tag_group_id")
    params.pop("search_text")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("tags", )
    return returned_ok(**returned_ok_params)
예제 #29
0
def get_series_on_a_release_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "release_id": 51,
        "limit": 3,
        "realtime_end": "2020-12-24",
        "order_by": "last_updated",
        "offset": 1,
        "sort_order": "desc",
        "tag_names": ("japan", ),
    }
    fred.get_series_on_a_release(**params)
    returned_ok_params["observed"] = fred.release_stack[
        "get_series_on_a_release"]
    returned_ok_params["check_union"] = (
        "seriess",
        "series",
    )
    params.pop("release_id")
    params.pop("tag_names")
    returned_ok_params["expected"] = params
    return returned_ok(**returned_ok_params)
예제 #30
0
def get_series_vintagedates_method_works(
    fred: Fred,
    returned_ok_params: dict,
) -> bool:
    params = {
        "series_id": "GNPCA",
        "limit": 3,
        "realtime_start": "1812-06-18",
        "sort_order": "desc",
        "offset": 2,
    }
    returned_ok_params["observed"] = fred.get_series_vintagedates(**params)
    params.pop("series_id")
    returned_ok_params["expected"] = params
    returned_ok_params["check_union"] = ("vintage_dates",)
    return returned_ok(**returned_ok_params)