Skip to content

Commit

Permalink
Update tests so that they are faster
Browse files Browse the repository at this point in the history
  • Loading branch information
noscode committed Apr 22, 2024
1 parent db7437f commit e22c26d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
- name: Run tests and codecov.
run: |
pytest --timeout=400 --cov=gadma --cov-report=xml -v tests --disable-warnings
pytest --timeout=600 --cov=gadma --cov-report=xml -v tests --disable-warnings
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
47 changes: 33 additions & 14 deletions tests/test_dem_model_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,33 @@ def test_likelihood_after_increase(self):
if not create_migs:
sym_migs = False
def model_generator(structure):
return StructureDemographicModel(structure,
np.array(structure) + 1,
has_migs=create_migs,
has_sels=create_sels,
has_dom=False, # TODO
has_dyns=create_dyns,
sym_migs=sym_migs,
frac_split=fracs,
has_anc_size=has_anc,
has_inbr=inbr)
model = StructureDemographicModel(
structure,
np.array(structure) + 1,
has_migs=create_migs,
has_sels=create_sels,
has_dom=False, # TODO
has_dyns=create_dyns,
sym_migs=sym_migs,
frac_split=fracs,
has_anc_size=has_anc,
has_inbr=inbr
)
# we will narrow domains so that test will be faster
for i in range(len(model.variables)):
var = model.variables[i]
if isinstance(var, PopulationSizeVariable):
if var.name == "Nanc":
model.variables[i].domain = [1000, 2000]
else:
model.variables[i].domain = [1e-1, 5.]
elif isinstance(var, TimeVariable):
model.variables[i].domain = [0.1, 1.]
elif isinstance(var, MigrationVariable):
model.variables[i].domain = [0, 2.]
elif isinstance(var, SelectionVariable):
model.variables[i].domain = [0, 2.]
return model

dm = model_generator(structure)
dm.mutation_rate = 1e-8
Expand Down Expand Up @@ -222,7 +239,7 @@ def model_generator(structure):
sizes = [8 for _ in range(len(structure))]
if len(structure) == 1:
sizes = [20]
kwargs = {"pts": [4, 6, 8]} # pts
kwargs = {"pts": [8, 10, 12]} # pts
else:
sizes = [4 for _ in range(len(structure))]
kwargs = {}
Expand Down Expand Up @@ -292,15 +309,17 @@ def model_generator(structure):
self.assertTrue(is_equal,
msg=f"{ll_true} != {new_ll} : {msg}")
except AttributeError as e:
assert engine.id in ["dadi"], str(e)
print(e)
assert engine.id in ["dadi"]
failed += 1
except TypeError as e:
assert engine.id in ["dadi"], str(e)
print(e)
assert engine.id in ["dadi"]
failed += 1

dm.final_structure = dm.get_structure()
self.assertRaises(ValueError, dm.increase_structure)
self.assertTrue(failed <= 5, "Dadi failed more that 5 times")
self.assertTrue(failed <= 5, "Dadi and momi2 failed more that 5 times")

def _data_for_ll_ld_test(self, ii):
return VCFDataHolder(
Expand Down

0 comments on commit e22c26d

Please sign in to comment.