Skip to content

Commit

Permalink
Merge pull request #5 from andrewtavis/add-testing
Browse files Browse the repository at this point in the history
Tests for data_utils and lctn_utils with version up
  • Loading branch information
andrewtavis authored Feb 23, 2021
2 parents 7401ce8 + 336029a commit ab6dfea
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 8 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
### wikirepo 0.1.0 (Feb 23, 2021)

First stable release of wikirepo

Additions include:

- Full documentation of the package

- Virtual environment files

- Bug fixes

- Extensive testing of all modules with GH Actions and Codecov

- Code of conduct and contribution guidelines


### wikirepo 0.0.2 (Dec 8, 2020)

The minimum viable product of wikirepo:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
author = "wikirepo developers"

# The full version, including alpha/beta/rc tags
release = "0.0.2.8"
release = "0.1.0"


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

setup_args = dict(
name="wikirepo",
version="0.0.2.8",
version="0.1.0",
author="Andrew Tavis McAllister",
author_email="andrew.t.mcallister@gmail.com",
classifiers=[
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
Expand Down
50 changes: 49 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
timespan = (date(2009, 1, 1), date(2010, 1, 1))
interval = "yearly"

# Test of values for a given timespan
df = wikirepo.data.query(
ents_dict=entities_dict,
locations=countries,
Expand Down Expand Up @@ -94,6 +95,48 @@
verbose=True,
)

# Test of most recent values
df = wikirepo.data.query(
ents_dict=entities_dict,
locations=countries,
depth=depth,
timespan=None,
interval=None,
demographic_props=[
"ethnic_div",
"life_expectancy",
"literacy",
"out_of_school_children",
"population",
],
economic_props=[
"gdp_ppp",
"gini",
"inflation_rate",
"median_income",
"nom_gdp_per_cap",
"nom_gdp",
"ppp_gdp_per_cap",
"total_reserves",
"unemployment",
],
electoral_poll_props=False,
electoral_result_props=False,
geographic_props=["area", "continent", "country",],
institutional_props=[
"bti_gov_idx",
"bti_status_idx",
"capital",
"fh_category",
"human_dev_idx",
"org_membership",
],
political_props="executive",
misc_props="country_abbr",
verbose=True,
)
df = data_utils.split_col_val_dates(df, col="population")

entities_dict_bundeslands = wd_utils.EntitiesDict()
depth = 1
sub_lctns = True
Expand Down Expand Up @@ -129,7 +172,12 @@ def ents_dict(request):
return request.param


@pytest.fixture(params=[df])
@pytest.fixture(params=[bundeslands_dict])
def lctns_dict(request):
return request.param


@pytest.fixture(params=[df_bundeslands])
def df(request):
return request.param

Expand Down
67 changes: 67 additions & 0 deletions tests/test_data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,70 @@
Data Utilities Tests
--------------------
"""

import pandas as pd

from wikirepo.data import data_utils


def test_interp_by_subset(df):
df_interp = data_utils.interp_by_subset(
df=df, depth=1, col_name="sub_abbr", method="pad", limit_direction="both"
)
assert df_interp["sub_abbr"].isnull().values.any() == False


def test_sum_df_prop_vals(df):
df.loc[
df.loc[(df["sub_lctn"] == "Berlin") & (df["year"] == "2009")].index,
"population",
] = 100

df.loc[
df.loc[(df["sub_lctn"] == "Berlin") & (df["year"] == "2010")].index,
"population",
] = 100

df.loc[
df.loc[(df["sub_lctn"] == "Hamburg") & (df["year"] == "2009")].index,
"population",
] = 100

df.loc[
df.loc[(df["sub_lctn"] == "Hamburg") & (df["year"] == "2010")].index,
"population",
] = 100

df_test = data_utils.sum_df_prop_vals(
df=df,
target_lctn="Berlin",
vals_lctn="Hamburg",
lctn_col="sub_lctn",
time_col="year",
prop_col="population",
subtract=False,
drop_vals_lctn=True,
)

assert (
df_test.loc[df_test.loc[df_test["sub_lctn"] == "Berlin"].index[0], "population"]
> df.loc[df.loc[df["sub_lctn"] == "Berlin"].index[0], "population"]
)
assert "Hamburg" not in list(df_test["sub_lctn"])

df_test = data_utils.sum_df_prop_vals(
df=df,
target_lctn="Berlin",
vals_lctn="Hamburg",
lctn_col="sub_lctn",
time_col=None,
prop_col="population",
subtract=True,
drop_vals_lctn=True,
)

assert (
df_test.loc[df_test.loc[df_test["sub_lctn"] == "Berlin"].index[0], "population"]
< df.loc[df.loc[df["sub_lctn"] == "Berlin"].index[0], "population"]
)
assert "Hamburg" not in list(df_test["sub_lctn"])
39 changes: 39 additions & 0 deletions tests/test_lctn_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,42 @@
Location Utilities Tests
------------------------
"""

from wikirepo.data import lctn_utils


def test_lctn_to_qid_dict():
assert type(lctn_utils.lctn_to_qid_dict()) == dict


def test_qid_to_lctn_dict():
assert type(lctn_utils.qid_to_lctn_dict()) == dict


def test_incl_lctn_lbls():
assert len(lctn_utils.incl_lctn_lbls("world")) == 1
assert len(lctn_utils.incl_lctn_lbls("continent")) == 7
assert type(lctn_utils.incl_lctn_lbls("country")) == list
assert type(lctn_utils.incl_lctn_lbls("region")) == list


def test_incl_lctn_ids():
assert type(lctn_utils.incl_lctn_ids()) == list


def test_qid_to_lctn_lbl(qid):
assert type(lctn_utils.qid_to_lctn_lbl(qid)) == str


def test_merge_lctn_dicts(lctns_dict):
assert (
type(lctn_utils.merge_lctn_dicts(ld1=lctns_dict, ld2=lctns_dict))
== lctn_utils.LocationsDict
)


def test_LocationsDict(ents_dict, lctns_dict):
assert len(lctns_dict.key_lbls_list()) == 17 # Germany and all its states
assert lctns_dict.get_depth() == 1
assert lctns_dict.get_qids_at_depth(depth=0) == ["Q183"]
assert type(lctns_dict.key_lbls_at_depth(ents_dict=ents_dict, depth=0)) == list
4 changes: 0 additions & 4 deletions tests/test_query.py

This file was deleted.

0 comments on commit ab6dfea

Please sign in to comment.