Skip to content

Commit

Permalink
Merge pull request #14 from SermetPekin/v1.1.20
Browse files Browse the repository at this point in the history
testing datagr
  • Loading branch information
SermetPekin authored Apr 17, 2024
2 parents 221a180 + 5d8fb63 commit ede0f18
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions evdspy/EVDSlocal/tests/test_user_requests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from pathlib import Path
import pandas as pd
from evdspy.EVDSlocal.index_requests.get_series_indexes import default_start_date_fnc, \
Expand All @@ -13,10 +12,14 @@
from evdspy.EVDSlocal.index_requests.get_series_indexes_utils import default_start_date_fnc, default_end_date_fnc
from evdspy.EVDSlocal.index_requests.user_requests import ProxyManager, UrlBuilder, UrlSeries, ApiRequester, \
DataProcessor, RequestConfig


def test_get_series_bridge(capsys):
with capsys.disabled():
df = get_series("bie_gsyhgycf", cache=False, api_key=get_env_api_key(check=True))
assert isinstance(df, pd.DataFrame)


def test_get_diff_series(capsys):
with capsys.disabled():
template = """TP_GSYIH01_GY_CF
Expand All @@ -36,6 +39,8 @@ def test_get_diff_series(capsys):
"""
df = get_series(template, debug=False, cache=False, api_key=get_env_api_key(check=True))
assert isinstance(df, pd.DataFrame)


def test_template_series(capsys):
with capsys.disabled():
balance_of_pay1 = "TP.ODEMGZS.BDTTOPLAM", "TP.ODEMGZS.ABD"
Expand All @@ -47,6 +52,8 @@ def test_template_series(capsys):
a2 = get_series(balance_of_pay2, debug=True)
print(a1.hash, a2.hash)
assert a1 == a2


def test_a(capsys):
with capsys.disabled():
balance_of_pay1 = "TP.ODEMGZS.BDTTOPLAM", "TP.ODEMGZS.ABD"
Expand All @@ -63,6 +70,8 @@ def test_a(capsys):
a1 = get_series(balance_of_pay1, debug=False)
print(a1)
assert isinstance(a1, pd.DataFrame)


def test_template_series2(capsys):
with capsys.disabled():
balance_of_pay1 = "TP.ODEMGZS.BDTTOPLAM", "TP.ODEMGZS.ABD"
Expand All @@ -74,6 +83,8 @@ def test_template_series2(capsys):
a2 = get_series(balance_of_pay2, aggregation=("avg", "avg"), debug=True)
print(a1.hash, a2.hash)
assert a1 == a2


def test_template_series3(capsys):
with capsys.disabled():
balance_of_pay1 = "TP.ODEMGZS.BDTTOPLAM", "TP.ODEMGZS.ABD"
Expand All @@ -85,6 +96,8 @@ def test_template_series3(capsys):
a2 = get_series(balance_of_pay2, formulas=(0, 0), debug=True)
print(a1.hash, a2.hash)
assert a1 == a2


def test_freq(capsys):
f = Frequency.annually
with capsys.disabled():
Expand All @@ -98,17 +111,27 @@ def test_freq(capsys):
assert freq_enum("annual") == "&frequency=8"
assert freq_enum(3) == "&frequency=3"
assert freq_enum(1) == "&frequency=1"


def test_pickles():
import os
os.makedirs("pickles", exist_ok=True)


def get_api_key():
import os
return os.getenv("EVDS_API_KEY")


# assert isinstance(get_api_key(), str) and len(get_api_key()) == 10
def key_valid():
return isinstance(get_api_key(), str) and len(get_api_key()) == 10


def is_testing():
return GithubActions().is_testing() and not key_valid()


def test_get_series2(capsys):
with capsys.disabled():
if is_testing():
Expand All @@ -118,25 +141,29 @@ def test_get_series2(capsys):
df = get_series("TP.ODEMGZS.BDTTOPLAM",
cache=False)
assert isinstance(df, pd.DataFrame)


def test_get_df_datagroup(capsys):
if is_testing():
if not GithubActions().is_testing():
return
from evdspy.main import get_df_datagroup
df = get_df_datagroup(
datagroup="bie_gsyhgycf",
start_date="01-01-1998",
end_date="01-01-2030",
datagroup="bie_gsyhgycf",
start_date="01-01-1998",
end_date="01-01-2030",
)
print(df)


def test_get_api_key_while_testing(capsys):
with capsys.disabled():
if is_testing():
return
if GithubActions().is_testing() :
if GithubActions().is_testing():
return

a = get_api_key_while_testing()
assert len(a) > 5 and 'lg' in a


def test_get_series(capsys):
if is_testing():
return
Expand All @@ -150,6 +177,8 @@ def test_get_series(capsys):
# user_req = UserRequest(index, start_date, end_date)
df = get_series(index, start_date, end_date, cache)
print(df)


# from evdspy.EVDSlocal.index_requests.get_series_indexes import Formulas, correct_types, AggregationType
def test_aggr_types(capsys):
balance_of_pay1 = "TP.ODEMGZS.BDTTOPLAM", "TP.ODEMGZS.ABD"
Expand Down Expand Up @@ -178,13 +207,17 @@ def test_aggr_types(capsys):
cache=cache,
)
assert u1 == u2


def test_correct(capsys):
with capsys.disabled():
assert hasattr(Formulas, "from_str")
assert Formulas.level.value == 0
assert Formulas.from_str("level").value == 0
assert correct_types("level", Formulas) == 0
assert correct_types(("level", "level",), enum_class=Formulas) == (0, 0,)


def test_correct2(capsys):
with capsys.disabled():
assert correct_types("avg", AggregationType) == "avg"
Expand Down Expand Up @@ -212,4 +245,4 @@ def test_correct2(capsys):
# aggregation=("avg",),
# formulas="level")
# print(ur.url)
# assert ur.url == "https://evds2.tcmb.gov.tr/service/evds/series=Aaa-Bbb&frequency=3&formulas=0-0&aggregationTypes=avg-avg&startDate=01-01-2000&endDate=01-01-2100&type=json"
# assert ur.url == "https://evds2.tcmb.gov.tr/service/evds/series=Aaa-Bbb&frequency=3&formulas=0-0&aggregationTypes=avg-avg&startDate=01-01-2000&endDate=01-01-2100&type=json"

0 comments on commit ede0f18

Please sign in to comment.