Skip to content

Commit

Permalink
Removing unittest in favor of pytest (#465)
Browse files Browse the repository at this point in the history
* moving tests from files with unittest to test_interfaces written with pytest

* fixing comments and consolidating sample method tests

* consolidating non positive integer tests

* removing redundant tests
  • Loading branch information
sabinala authored Jan 23, 2024
1 parent 9ef3f85 commit 55d24aa
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 217 deletions.
6 changes: 6 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def __init__(
LOGGING_STEP_SIZES = [5.0]

NUM_SAMPLES = [2]
NON_POS_INTS = [
3.5,
-3,
0,
torch.tensor(3),
] # bad candidates for num_samples/num_iterations


def check_keys_match(obj1: Dict[str, T], obj2: Dict[str, T]):
Expand Down
70 changes: 0 additions & 70 deletions tests/test_calibrate_error_messages.py

This file was deleted.

78 changes: 0 additions & 78 deletions tests/test_ensemble_sample_error_messages.py

This file was deleted.

34 changes: 34 additions & 0 deletions tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
LOGGING_STEP_SIZES,
MODEL_URLS,
MODELS,
NON_POS_INTS,
NUM_SAMPLES,
START_TIMES,
check_result_sizes,
Expand Down Expand Up @@ -420,3 +421,36 @@ def test_output_format(

assert processed_result["timepoint_id"].dtype == np.int64
assert processed_result["sample_id"].dtype == np.int64


@pytest.mark.parametrize("model_fixture", MODELS)
@pytest.mark.parametrize("bad_num_iterations", NON_POS_INTS)
def test_non_pos_int_calibrate(model_fixture, bad_num_iterations):
# Assert that a ValueError is raised when num_iterations is not a positive integer
if model_fixture.data_path is None or model_fixture.data_mapping is None:
pytest.skip("Skip models with no data attached")
with pytest.raises(ValueError):
calibrate(
model_fixture.url,
model_fixture.data_path,
data_mapping=model_fixture.data_mapping,
num_iterations=bad_num_iterations,
)


@pytest.mark.parametrize("sample_method", SAMPLE_METHODS)
@pytest.mark.parametrize("model_url", MODEL_URLS)
@pytest.mark.parametrize("end_time", END_TIMES)
@pytest.mark.parametrize("logging_step_size", LOGGING_STEP_SIZES)
@pytest.mark.parametrize("bad_num_samples", NON_POS_INTS)
def test_non_pos_int_sample(
sample_method, model_url, end_time, logging_step_size, bad_num_samples
):
# Assert that a ValueError is raised when num_samples is not a positive integer
with pytest.raises(ValueError):
sample_method(
model_url,
end_time,
logging_step_size,
num_samples=bad_num_samples,
)
69 changes: 0 additions & 69 deletions tests/test_sample_error_message.py

This file was deleted.

0 comments on commit 55d24aa

Please sign in to comment.