Skip to content

Commit

Permalink
Fix tests (#183)
Browse files Browse the repository at this point in the history
* Rename so pytest finds files; remove duplicate test file

* Remove classes/setup/teardown, use pytest.fixture; all tests discoverable by pytest

* Bug fix where alt probes could be in wrong order
  • Loading branch information
martinghunt authored May 10, 2024
1 parent c1745f0 commit e51db6a
Show file tree
Hide file tree
Showing 31 changed files with 2,499 additions and 2,811 deletions.
2 changes: 1 addition & 1 deletion src/mykrobe/cmds/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_non_singelton_variants(db_name):

def run(parser, args):
db_name = '%s-%s' % (DB_PREFIX, args.db_name)
DB = connect(db_name, host=args.db_uri)
DB = connect(db_name, host=args.db_uri, uuidRepresentation="pythonLegacy")
if args.verbose:
logger.setLevel(level=logging.DEBUG)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/mykrobe/cmds/makeprobes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run(parser, args):
logger.info("Not connecting to database, because --no-backgrounds option used")
DB = None
else:
DB = connect("%s-%s" % (DB_PREFIX, args.db_name), host=args.db_uri)
DB = connect("%s-%s" % (DB_PREFIX, args.db_name), host=args.db_uri, uuidRepresentation="pythonLegacy")

if DB is not None:
try:
Expand Down
4 changes: 2 additions & 2 deletions src/mykrobe/cmds/variants/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(parser, args):
else:
logger.setLevel(logging.INFO)
DBNAME = "%s-%s" % (DB_PREFIX, args.db_name)
connect(DBNAME, host=args.db_uri)
connect(DBNAME, host=args.db_uri, uuidRepresentation="pythonLegacy")
logger.debug("Using DB %s" % DBNAME)

with open(args.reference_set) as fp:
Expand All @@ -58,7 +58,7 @@ def run(parser, args):
reference_set = ReferenceSet.objects.get(name=reference_set_name)
except DoesNotExist:
reference_set = ReferenceSet.create_and_save(name=reference_set_name)

try:
reference = Reference.create_and_save(
name=reference_set_name, reference_sets=[reference_set], md5checksum="NA"
Expand Down
4 changes: 3 additions & 1 deletion src/mykrobe/probes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def _generate_alternates_on_all_backgrounds(self, v, context):
for alt in v.alternate_bases:
alternate[i: i + len(v.reference_bases)] = alt
alternates.append(alternate)

return alternates

def _get_all_context_combinations(self, context):
Expand Down Expand Up @@ -379,7 +380,8 @@ def __init__(self, variant, refs, start, alts):
self.refs = unique(["".join(ref) for ref in refs])
self.start = start
self.alts = unique(["".join(alt) for alt in alts])
self.alts=list(set(self.alts)-set(self.refs))
ref_set = set(self.refs)
self.alts = [x for x in self.alts if x not in ref_set]


class Mutation(object):
Expand Down
813 changes: 414 additions & 399 deletions tests/annotation_tests/test_annotations.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import copy
import pytest

from mykrobe import amr

Expand Down
1 change: 0 additions & 1 deletion tests/end_to_end_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import pytest
import subprocess

from mykrobe.parser import parser
Expand Down
104 changes: 0 additions & 104 deletions tests/metagenomics_tests/MTBC_tests.py

This file was deleted.

79 changes: 31 additions & 48 deletions tests/metagenomics_tests/basic_test.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
from unittest import TestCase
from mykrobe.metagenomics import AMRSpeciesPredictor


class MTBCSpeciesTests(TestCase):

def setUp(self):
pass

def teardown(self):
pass

def test_mixed_chimera(self):
species_predictor = AMRSpeciesPredictor(
phylo_group_covgs={},
sub_complex_covgs={},
species_covgs={},
lineage_covgs={}
)
species_predictor.out_json["phylogenetics"] = {
"sub_complex": {
"Mycobacterium_avium_complex": {
"percent_coverage": 98.346,
"median_depth": 54.0
}
},
"phylo_group": {
"Non_tuberculosis_mycobacterium_complex": {
"percent_coverage": 82.846,
"median_depth": 49
}
},
"species": {
"Mycobacterium_chimaera": {
"percent_coverage": 99.162,
"median_depth": 39
},
"Mycobacterium_intracellulare": {
"percent_coverage": 98.662,
"median_depth": 45
},
"Mycobacterium_bovis": {
"percent_coverage": 9.894,
"median_depth": 12.0
}
def test_mixed_chimera():
species_predictor = AMRSpeciesPredictor(
phylo_group_covgs={}, sub_complex_covgs={}, species_covgs={}, lineage_covgs={}
)
species_predictor.out_json["phylogenetics"] = {
"sub_complex": {
"Mycobacterium_avium_complex": {
"percent_coverage": 98.346,
"median_depth": 54.0,
}
},
"phylo_group": {
"Non_tuberculosis_mycobacterium_complex": {
"percent_coverage": 82.846,
"median_depth": 49,
}
}
},
"species": {
"Mycobacterium_chimaera": {"percent_coverage": 99.162, "median_depth": 39},
"Mycobacterium_intracellulare": {
"percent_coverage": 98.662,
"median_depth": 45,
},
"Mycobacterium_bovis": {"percent_coverage": 9.894, "median_depth": 12.0},
},
}

out_dict = species_predictor.choose_best(
species_predictor.out_json["phylogenetics"])
out_dict = species_predictor.choose_best(
species_predictor.out_json["phylogenetics"]
)

assert "Mycobacterium_chimaera" in out_dict["species"]
assert "Mycobacterium_intracellulare" in out_dict["species"]
assert "Mycobacterium_bovis" not in out_dict["species"]
assert "Mycobacterium_chimaera" in out_dict["species"]
assert "Mycobacterium_intracellulare" in out_dict["species"]
assert "Mycobacterium_bovis" not in out_dict["species"]
Loading

0 comments on commit e51db6a

Please sign in to comment.