Skip to content

Commit

Permalink
Update test fixture structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsnow committed Nov 27, 2024
1 parent 7806ac1 commit 0d84a32
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
13 changes: 9 additions & 4 deletions assesspy/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ def quintos_data() -> tuple:
return sample.estimate, sample.sale_price


@pt.fixture(scope="module", params=["1_1", "1_4", "d_1", "d_2"])
def iaao_data(request) -> tuple:
sample = pd.read_csv(FIXTURE_DIR / f"iaao_table_{request.param}.csv")
return request.param, sample.estimate, sample.sale_price
@pt.fixture(scope="session", params=["1_1", "1_4", "d_1", "d_2"])
def iaao_data_name(request):
return request.param


@pt.fixture(scope="session")
def iaao_data(iaao_data_name) -> tuple:
sample = pd.read_csv(FIXTURE_DIR / f"iaao_table_{iaao_data_name}.csv")
return sample.estimate, sample.sale_price


@pt.fixture(
Expand Down
11 changes: 7 additions & 4 deletions assesspy/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ def test_metric_value_is_correct_ccao(self, metric, metric_val):
}
assert pt.approx(metric_val, rel=0.01) == expected[metric]

def test_metric_value_is_correct_iaao(self, metric, iaao_data):
def test_metric_value_is_correct_iaao(
self, metric, iaao_data_name, iaao_data
):
if metric in ["mki", "ki"]:
return None
else:
table_name, estimate, sale_price = iaao_data
result = getattr(ap, metric)(estimate, sale_price)
result = getattr(ap, metric)(*iaao_data)
expected = {
"1_1": {
"cod": 29.8,
Expand All @@ -52,7 +53,9 @@ def test_metric_value_is_correct_iaao(self, metric, iaao_data):
"prb": -0.011,
},
}
assert pt.approx(result, rel=0.02) == expected[table_name][metric]
assert (
pt.approx(result, rel=0.02) == expected[iaao_data_name][metric]
)

def test_metric_has_numeric_output(self, metric_val):
assert type(metric_val) is float
Expand Down
28 changes: 15 additions & 13 deletions assesspy/tests/test_sales_chasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,37 @@ def sample_dist(self, ccao_data):
return ratio

@pt.fixture(params=["normal", "chased", "sample"])
def distribution(self, request, ccao_data, sample_dist):
return request.param, {
def distribution_name(self, request):
return request.param

@pt.fixture
def distribution(self, distribution_name, ccao_data, sample_dist):
return {
"normal": np.random.normal(1, size=1000).tolist(),
"chased": np.append(
np.random.normal(1, 0.15, 900), [1] * 100
).tolist(),
"sample": sample_dist,
}[request.param]
}[distribution_name]

@pt.fixture(params=["cdf", "dist", "both"])
def method(self, request):
return request.param

def test_is_sales_chased_output_is_boolean(self, distribution, method):
dist_name, dist_data = distribution
assert isinstance(ap.is_sales_chased(dist_data, method), bool)
assert isinstance(ap.is_sales_chased(distribution, method), bool)

def test_is_sales_chased_has_expected_output(self, distribution, method):
dist_name, dist_data = distribution
def test_is_sales_chased_has_expected_output(
self, distribution_name, distribution, method
):
expected = {
"normal": {"cdf": False, "dist": False, "both": False},
"chased": {"cdf": True, "dist": True, "both": True},
"sample": {"cdf": False, "dist": True, "both": False},
}
assert (
ap.is_sales_chased(dist_data, method)
== expected[dist_name][method]
ap.is_sales_chased(distribution, method)
== expected[distribution_name][method]
)

@pt.mark.parametrize(
Expand All @@ -61,13 +65,11 @@ def test_is_sales_chased_raises_on_invalid_values(
self, input_data, distribution, method
):
with pt.raises(Exception):
dist_name, dist_data = distribution
ap.is_outlier(input_data(dist_data), method)
ap.is_outlier(input_data(distribution), method)

def test_is_sales_chased_raises_on_invalid_method(self, distribution):
with pt.raises(Exception):
dist_name, dist_data = distribution
ap.is_sales_chased(dist_data, method="hug")
ap.is_sales_chased(distribution, method="hug")

def test_is_sales_chased_warns_on_small_sample(self):
with pt.warns(UserWarning):
Expand Down

0 comments on commit 0d84a32

Please sign in to comment.