Skip to content

Commit

Permalink
Update tests/test_Models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xin-huang committed Apr 15, 2024
1 parent b7dd261 commit 58a5d04
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/test_Models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,30 @@ def test_print_built_in_model_details(capfd, model_list):

assert str(e_info.value) == "Cannot find model: mixture."

def test_custome_model_import(capfd):

def test_custom_model_import(capfd):
# Test importing a non-existing file
model_file = 'tests/non_existing_model.py'
with pytest.raises(ImportError) as excinfo:
get_model('hallo', model_file)

assert f"Failed to import module: {model_file}" in str(excinfo.value)

import tests.example_data.example_models as custom
custome_model_list = ['three_epoch_bottleneck', 'split_mig_fix_T', 'split_mig_fix_T_sel']

# Test importing good custom models
for custome_model in custome_model_list:
get_model(custome_model, 'tests/example_data/example_models')
out, err = capfd.readouterr()
assert out == "" and err == ""
# Test importing a custom model without .__param_names__ attribute

with pytest.raises(ValueError) as e_info:
get_model('split_no_mig_missing_param_names', 'tests/example_data/example_models')
assert str(e_info.value) == "Demographic model needs a .__param_names__ attribute!\nAdd one by adding the line split_no_mig_missing_param_names.__param_name__ = [LIST_OF_PARAMS]\nReplacing LIST_OF_PARAMS with the names of the parameters as strings."
# Test importing a custom model not in example_models

with pytest.raises(AttributeError) as e_info:
get_model('haha', 'tests/example_data/example_models')
assert str(e_info.value) == "module 'example_models' has no attribute 'haha'"
Expand Down

0 comments on commit 58a5d04

Please sign in to comment.