Skip to content

Commit

Permalink
pep8 unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamZekaiWang authored and WilliamZekaiWang committed May 15, 2024
1 parent 1a9fff2 commit ec04d1c
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 140 deletions.
74 changes: 37 additions & 37 deletions tests/test_batch_utils.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import unittest
from argparse import Namespace
from covizu.utils.batch_utils import beadplot_serial, import_labels, make_beadplots, get_mutations
from covizu.utils.batch_utils import beadplot_serial, get_mutations

# Build TimeTree - Tests in test_timetree.py


class TestBeadplotSerial(unittest.TestCase):
def setUp(self):
self.expected = {
'lineage': 'B.1.1.171',
'nodes': {
'EPI_ISL_465679': [['2020-03-27', 'EPI_ISL_465679', 'North America / Canada / London', 'hCoV-19/Canada/Qc-L00240569/2020']]
},
'edges': [],
'sampled_variants': 1
}
self.expected = {'lineage': 'B.1.1.171',
'nodes': {'EPI_ISL_465679': [['2020-03-27',
'EPI_ISL_465679',
'North America / Canada / London',
'hCoV-19/Canada/Qc-L00240569/2020']]},
'edges': [],
'sampled_variants': 1}

@unittest.skip("beadplot_serial has been deprecated")
def testBeadplotSerial(self):
def test_beadplot_serial(self):
# Lineage with only one variant

lineage = 'B.1.1.171'
features = {
'~|240|T,~|1436|T,~|3036|T,~|3713|T,~|5883|T,~|14407|T,~|20543|T,~|23402|G,~|28880|A,~|28881|A,~|28882|C': [
('~|240|T,~|1436|T,~|3036|T,~|3713|T,~|5883|T,~|14407|T,'
'~|20543|T,~|23402|G,~|28880|A,~|28881|A,~|28882|C'): [
{
'covv_virus_name': 'hCoV-19/Canada/Qc-L00240569/2020',
'covv_accession_id': 'EPI_ISL_465679',
'covv_collection_date': '2020-03-27',
'covv_lineage': 'B.1.1.171',
'covv_location': 'North America / Canada / London',
'diffs' : [
'diffs': [
tuple(['~', 240, 'T']),
tuple(['~', 1436, 'T']),
tuple(['~', 3036, 'T']),
Expand All @@ -42,7 +42,7 @@ def testBeadplotSerial(self):
tuple(['~', 28881, 'A']),
tuple(['~', 28882, 'C'])
],
'missing' : [
'missing': [
tuple([0, 6]),
tuple([5203, 5222]),
tuple([29844, 29903])
Expand All @@ -63,47 +63,47 @@ def setUp(self):
'B.1.265': {('~', 240, 'T'): 1.0, ('~', 1436, 'T'): 1.0}
}

def testGetMutations(self):
def test_get_mutations(self):
by_lineage = \
{'B.1.1.171':
{'~|240|T,~|1436|T':
[{'covv_virus_name' : '',
'covv_accession_id' : '',
{'B.1.1.171':
{'~|240|T,~|1436|T':
[{'covv_virus_name': '',
'covv_accession_id': '',
'covv_collection_date': '',
'covv_lineage' : 'B.1.1.171',
'diffs' : [
'covv_lineage': 'B.1.1.171',
'diffs': [
tuple(['~', 240, 'T']),
tuple(['~', 1436, 'T']),
],
'missing' : []
'missing': []
}]
},
'B.1.265':
{'~|240|T,~|1436|T':
[{'covv_virus_name' : '',
'covv_accession_id' : '',
},
'B.1.265':
{'~|240|T,~|1436|T':
[{'covv_virus_name': '',
'covv_accession_id': '',
'covv_collection_date': '',
'covv_lineage' : 'B.1.265',
'diffs' : [
'covv_lineage': 'B.1.265',
'diffs': [
tuple(['~', 240, 'T']),
tuple(['~', 240, 'T']),
tuple(['~', 240, 'T']),
tuple(['~', 1436, 'T']),
],
'missing' : []
},
{'covv_virus_name' : '',
'covv_accession_id' : '',
'missing': []
},
{'covv_virus_name': '',
'covv_accession_id': '',
'covv_collection_date': '',
'covv_lineage' : 'B.1.1.171',
'diffs' : [
'covv_lineage': 'B.1.1.171',
'diffs': [
tuple(['~', 240, 'T']),
tuple(['~', 1436, 'T']),
],
'missing' : []
'missing': []
}]
}
}
}
}

results = get_mutations(by_lineage)
self.assertEqual(self.expected, results)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_beadplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from covizu import beadplot
from io import StringIO
from covizu import beadplot
from Bio import Phylo


Expand Down Expand Up @@ -43,7 +43,7 @@ def setUp(self):
]
}

def testParse(self):
def test_parse(self):
handle = StringIO()
handle.write(
"name,index\n"
Expand All @@ -56,7 +56,7 @@ def testParse(self):
result = beadplot.parse_labels(handle)
self.assertEqual(self.expected, result)

def testBadParse(self):
def test_bad_parse(self):
handle = StringIO()
handle.write(
"label,index\n"
Expand All @@ -67,7 +67,7 @@ def testBadParse(self):
with self.assertRaises(KeyError):
beadplot.parse_labels(handle)

def testReverse(self):
def test_reverse(self):
handle = StringIO()
handle.write(
"index,name\n"
Expand All @@ -82,7 +82,7 @@ def testReverse(self):


class TestGetParents(unittest.TestCase):
def testGetParents(self):
def test_get_parents(self):
tree = phylo_from_str("((A,B)D,C)E;\n")
result = beadplot.get_parents(tree)

Expand All @@ -96,7 +96,7 @@ def testGetParents(self):


class TestCollapsePolytomies(unittest.TestCase):
def testSimple(self):
def test_simple(self):
tree = phylo_from_str("((A:1,B:1):0,C:1):0;")
result = beadplot.collapse_polytomies(tree)
expected = phylo_from_str("(A:1,B:1,C:1):0;")
Expand All @@ -107,7 +107,7 @@ def testSimple(self):
expected = phylo_from_str("(A:1,B:1,(C:1,D:1):1):0;")
self.assertTrue(compare_phylo(expected, result))

def testLabeling(self):
def test_labeling(self):
tree3 = phylo_from_str("((A:1,B:1):1,C:0):0;")
result = beadplot.collapse_polytomies(tree3)
expected = phylo_from_str("(((A:1,B:1):1)C:0);")
Expand All @@ -120,7 +120,7 @@ def testLabeling(self):


class TestIssues(unittest.TestCase):
def testIssue150(self):
def test_issue150(self):
# consensus of B.13 bootstrap trees
tree = phylo_from_str(
"(0:0.00000,(((1:0.00000,8:1.86735)0.71:1.54286,3:0.00000)"
Expand Down
Loading

0 comments on commit ec04d1c

Please sign in to comment.