Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add beginnings of unit test coverage of align #463

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ dist/
*.pyc
__pycache__/
.cache/
.coverage
augur.egg-info/
.mypy_cache/
nextstrain_augur.egg-info/
env/
.pytest_cache
Expand Down
14 changes: 13 additions & 1 deletion pytest.python3.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
[pytest]
addopts = --doctest-modules tests/python3/ augur/
addopts =
# do not capture any output---necessary for interactive breakpoints
-s

# run any doctests found in .py modules
--doctest-modules

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add --cov here, --no-cov can override it.

# calculate test coverage for the `augur` module
--cov=augur

testpaths =
augur/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/
16 changes: 16 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest removing this file and instead adding --no-cov when needed to pytest.


case "$@" in
*-k*) partial_test=1 ;;
huddlej marked this conversation as resolved.
Show resolved Hide resolved
esac

if [ "$partial_test" = 1 ]; then
# skip test coverage when running a subset of the test suite
coverage_arg='--no-cov'
else
coverage_arg=''
fi

python3 -m pytest -c pytest.python3.ini $coverage_arg "$@"

exit $?
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
],
'dev': [
"pylint >=1.7.6, ==1.7.*",
"pytest >=3.2.1, ==3.*",
"pytest >=5.4.1, ==5.4.*",
"pytest-cov >=2.8.1, ==2.8.*",
"recommonmark >=0.5.0, ==0.*",
"Sphinx >=2.0.1, ==2.*",
"sphinx-argparse >=0.2.5, ==0.*",
Expand Down
75 changes: 75 additions & 0 deletions tests/test_align.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from Bio.Align import MultipleSeqAlignment
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord

from augur import align

import pytest


class TestAlign:
def test_make_gaps_ambiguous(self):
alignment = MultipleSeqAlignment(
[SeqRecord(Seq("G-AC")), SeqRecord(Seq("----")), SeqRecord(Seq("TAGC"))]
)

align.make_gaps_ambiguous(alignment)

assert [seq_record.seq for seq_record in alignment] == [
Seq("GNAC"),
Seq("NNNN"),
Seq("TAGC"),
]

def test_check_duplicates_no_arguments(self):
assert align.check_duplicates() is None

def test_check_duplicates_strings_with_no_duplicates(self):
assert align.check_duplicates("GTAC", "CGTT") is None

def test_check_duplicates_MSA_with_no_duplicates(self):
alignment = MultipleSeqAlignment(
[
SeqRecord(Seq("GTAC"), name="seq1"),
SeqRecord(Seq("CGTT"), name="seq2"),
SeqRecord(Seq("TAGC"), name="seq3"),
]
)
assert align.check_duplicates(alignment) is None

def test_check_duplicates_MSA_and_string_with_no_duplicates(self):
alignment = MultipleSeqAlignment(
[
SeqRecord(Seq("GTAC"), name="seq1"),
SeqRecord(Seq("CGTT"), name="seq2"),
SeqRecord(Seq("TAGC"), name="seq3"),
]
)
assert align.check_duplicates(alignment, "TGTT") is None

def test_check_duplicates_string_with_duplicates(self):
with pytest.raises(align.AlignmentError):
assert align.check_duplicates("GTAC", "CGTT", "CGTT")

def test_check_duplicates_MSA_with_duplicates(self):
alignment = MultipleSeqAlignment(
[
SeqRecord(Seq("GTAC"), name="seq1"),
SeqRecord(Seq("CGTT"), name="seq2"),
SeqRecord(Seq("TAGC"), name="seq3"),
SeqRecord(Seq("TAGC"), name="seq3"),
]
)
with pytest.raises(align.AlignmentError):
assert align.check_duplicates(alignment)

def test_check_duplicates_MSA_and_string_with_duplicates(self):
alignment = MultipleSeqAlignment(
[
SeqRecord(Seq("GTAC"), name="seq1"),
SeqRecord(Seq("CGTT"), name="seq2"),
SeqRecord(Seq("TAGC"), name="seq3"),
]
)
with pytest.raises(align.AlignmentError):
assert align.check_duplicates(alignment, "seq3")