Skip to content
Snippets Groups Projects
Commit d94f20cf authored by Vermaat's avatar Vermaat
Browse files

Refactor unit tests using common py.test layout and fixtures

parent cd9e05ee
No related branches found
No related tags found
No related merge requests found
Showing
with 7083 additions and 6661 deletions
*.pyc
.cache
/build
/dist
/mutalyzer.egg-info
......
# Validate this file using http://lint.travis-ci.org/
language: python
python: "2.7"
addons:
postgresql: "9.4"
services:
- redis-server
python:
- "2.7"
env:
global:
- MUTALYZER_TEST_REDIS_URI=redis://localhost
matrix:
- MUTALYZER_TEST_DATABASE_URI=sqlite://
- MUTALYZER_TEST_DATABASE_URI=postgres://postgres@127.0.0.1/mutalyzer_test
- MUTALYZER_TEST_DATABASE_URI=mysql://travis@127.0.0.1/mutalyzer_test?charset=utf8
services: redis-server
before_install:
- sudo apt-get update -qq
- sudo apt-get install -y swig
- pip install -r requirements.txt
- bash -c "if [[ '$MUTALYZER_TEST_DATABASE_URI' =~ 'postgres' ]]; then pip install psycopg2; fi"
install:
- pip install .
- pip install psycopg2
install: pip install .
before_script:
- bash -c "if [[ '$MUTALYZER_TEST_DATABASE_URI' =~ 'postgres' ]]; then psql -c 'DROP DATABASE IF EXISTS mutalyzer_test;' -U postgres; fi"
- bash -c "if [[ '$MUTALYZER_TEST_DATABASE_URI' =~ 'postgres' ]]; then psql -c 'CREATE DATABASE mutalyzer_test;' -U postgres; fi"
- bash -c "if [[ '$MUTALYZER_TEST_DATABASE_URI' =~ 'mysql' ]]; then mysql -e 'CREATE DATABASE IF NOT EXISTS mutalyzer_test;'; fi"
script:
- py.test
- psql -c 'DROP DATABASE IF EXISTS mutalyzer_test;' -U postgres
- psql -c 'CREATE DATABASE mutalyzer_test;' -U postgres
- mysql -e 'CREATE DATABASE IF NOT EXISTS mutalyzer_test;'
script: py.test --redis-uri redis://localhost --database-uri sqlite:// --database-uri postgres://postgres@127.0.0.1/mutalyzer_test --database-uri mysql://travis@127.0.0.1/mutalyzer_test?charset=utf8
......@@ -16,23 +16,26 @@ the Mutalyzer source directory.
tests.
By default, the tests use an in-memory SQLite database. This can be customized
by setting the `MUTALYZER_TEST_DATABASE_URI` to a valid `SQLAlchemy connection
URI
with the ``--database-uri` command line argument and a valid `SQLAlchemy
connection URI
<http://docs.sqlalchemy.org/en/rel_1_0/core/engines.html#database-urls>`_
(obviously, the contents of this database will be lost). For example, to use
an SQLite database on the filesystem::
$ MUTALYZER_TEST_DATABASE_URI=sqlite:////tmp/mutalyzer.sql py.test
$ py.test --database-uri sqlite:////tmp/mutalyzer.sql
Or, using `pg_virtualenv
<https://alioth.debian.org/scm/loggerhead/pkg-postgresql/postgresql-common/trunk/view/head:/pg_virtualenv>`_
(included with the Debian PostgreSQL packages), to run the tests with
PostgreSQL::
$ pg_virtualenv bash -c 'MUTALYZER_TEST_DATABASE_URI=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE} py.test'
$ pg_virtualenv bash -c 'py.test --database-uri postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}'
Similarly, the `MUTALYZER_TEST_REDIS_URI` specifies a Redis server to use for
testing. If unspecified, a mock Redis server is used.
Multiple ``--database-uri`` arguments are allowed. Tests using the database
will be run once for every database specified.
Similarly, ``--redis-uri`` (only one allowed) specifies a Redis server to use
for testing. If unspecified, a mock Redis server is used.
Tests are `run automatically on Travis CI
<https://travis-ci.org/mutalyzer/mutalyzer>`_ with SQLite, PostgreSQL, and
......
......@@ -30,6 +30,20 @@ def create_engine():
"""
Create an SQLAlchemy connection engine from the current configuration.
"""
if not settings.DATABASE_URI:
# Just return silently when no database is configured (this function
# may still be called via the configuration settings hook). Of course
# actually using the database will fail.
return
# TODO: Remove when refactoring tests is complete. We should check that
# this is never reached with 'sqlite://' from the default_settings or with
# a value from MUTALYZER_SETTINGS during tests. The uri(s) configured in
# the tests should be used instead.
# This also makes sure that tests can never accidentally use the database
# without having it declared as a needed fixture.
print '!!!!!!!!!!!!! Creating session for', settings.DATABASE_URI
url = make_url(settings.DATABASE_URI)
options = {}
......
......@@ -3,6 +3,7 @@ description-extractor==2.2.1
Flask==0.10.1
Jinja2==2.7.3
MySQL-python==1.2.5
PyYAML==3.11
SQLAlchemy==0.9.8
Sphinx==1.2.3
Werkzeug==0.9.6
......@@ -14,7 +15,7 @@ lxml==3.4.0
mock==1.0.1
mockredispy==2.9.0.9
pyparsing==2.0.3
pytest==2.6.3
pytest==2.8.2
pytz==2014.7
redis==2.10.3
requests==2.4.3
......
"""
Test configuration.
"""
from __future__ import unicode_literals
from fixtures import * # noqa
DEFAULT_DATABASE_URIS = ['sqlite://']
DEFAULT_REDIS_URI = None
def pytest_addoption(parser):
parser.addoption(
'--database-uri', metavar='URI', dest='database_uris', default=[],
action='append',
help='Database connection, multiple allowed (default: in-memory '
'SQLite database)')
parser.addoption(
'--redis-uri', metavar='URI', dest='redis_uri',
default=DEFAULT_REDIS_URI,
help='Redis connection (default: mock Redis server)')
def pytest_generate_tests(metafunc):
if 'database_uri' in metafunc.fixturenames:
metafunc.parametrize(
'database_uri',
metafunc.config.option.database_uris or DEFAULT_DATABASE_URIS)
A1BG:
accession: UD_139015218717
checksum: e179de8b248806815394c4f7496ba872
filename: UD_139015218717.gb.bz2
links:
- - NM_001207009
- NP_001193938
- - NM_198458
- NP_940860
- - XM_005258578
- XP_005258635
- - XM_005258577
- XP_005258634
- - NR_015380
- null
- - NM_130786
- NP_570602
- - XM_005258393
- XP_005258450
AA010203.1:
checksum: 57cee03becb77ce68a225b9c844afb24
filename: AA010203.1.gb.bz2
geninfo_id: '1471230'
AB026906.1:
checksum: 29b003d5a71af74dc61a92d2ef5cd5d9
filename: AB026906.1.gb.bz2
geninfo_id: '5295993'
AF230870.1:
checksum: 9fefa34f40d94910edb5de34a3f98910
filename: AF230870.1.gb.bz2
geninfo_id: '7739657'
AL449423.14:
checksum: 00a014242818a3b003b4c077af9e10e0
filename: AL449423.14.gb.bz2
geninfo_id: '16944057'
COL1A1:
accession: UD_139022298843
checksum: 815517e36fb380b52842ace6a6e78637
filename: UD_139022298843.gb.bz2
links:
- - XM_005257059
- XP_005257116
- - XM_005257058
- XP_005257115
- - NM_000088
- NP_000079
DMD:
accession: UD_139262478721
checksum: d41d8cd98f00b204e9800998ecf8427e
filename: UD_139262478721.gb.bz2
links:
- - XM_006724469
- XP_006724532
- - XM_006724472
- XP_006724535
- - XM_006724473
- XP_006724536
- - XM_006724474
- XP_006724537
- - XM_006724475
- XP_006724538
- - XM_006724471
- XP_006724534
- - XM_006724470
- XP_006724533
- - XR_430491
- null
- - XM_006724468
- XP_006724531
- - XM_006724476
- XP_006724539
- - NM_000109
- NP_000100
- - NM_004006
- NP_003997
- - NM_004009
- NP_004000
- - NM_004010
- NP_004001
- - NM_004011
- NP_004002
- - NM_004012
- NP_004003
- - NM_004023
- NP_004014
- - NM_004020
- NP_004011
- - NM_004022
- NP_004013
- - NM_004021
- NP_004012
- - NM_004013
- NP_004004
- - NM_004014
- NP_004005
- - NM_004018
- NP_004009
- - NM_004017
- NP_004008
- - NM_004016
- NP_004007
- - NM_004015
- NP_004006
- - NM_004019
- NP_004010
DPYD:
accession: UD_139015208095
checksum: b2b9d402a6e43f80ce1e9bbb72a3c0c6
filename: UD_139015208095.gb.bz2
links:
- - NR_046590
- null
- - XM_005270562
- XP_005270619
- - NM_000110
- NP_000101
- - XM_005270561
- XP_005270618
- - XM_005270563
- XP_005270620
- - XM_005270564
- XP_005270621
- - NM_001160301
- NP_001153773
L41870.1:
checksum: 91b1e539a053f731f95d230a06710897
filename: L41870.1.gb.bz2
geninfo_id: '793994'
LRG_1:
checksum: 5b8f5a39fcd9e3005688eddffd482746
filename: LRG_1.xml.bz2
MARK1:
accession: UD_139015213982
checksum: 0d63a8fe5beddeb793940f6ae194b985
filename: UD_139015213982.gb.bz2
links:
- - NM_018650
- NP_061120
- - XM_005273133
- null
- - XM_005273134
- XP_005273191
- - XM_005273135
- null
- - XM_005273136
- null
NG_008939.1:
checksum: 114a03e16ad2f63531d796c2fb0d7039
filename: NG_008939.1.gb.bz2
geninfo_id: '211938431'
links:
- - NM_000532
- NP_000523
NG_009105.1:
checksum: f2579e6c4a8ead4566e485aad493ef7e
filename: NG_009105.1.gb.bz2
geninfo_id: '216548283'
links:
- - NM_020061
- NP_064445
NG_012337.1:
checksum: ad712f4f225398d2b11b4f08110c70e6
filename: NG_012337.1.gb.bz2
geninfo_id: '254039638'
links:
- - NM_018195
- NP_060665
- - NM_001082969
- NP_001076438
- - NM_001082970
- NP_001076439
- - NM_003002
- NP_002993
- - NM_012459
- NP_036591
NG_012772.1:
checksum: 163881f00c9c26516d52a4ddb34f941f
filename: NG_012772.1.gb.bz2
geninfo_id: '256574794'
links:
- - NM_052818
- NP_438169
- - NM_001079691
- NP_001073159
- - NM_000059
- NP_000050
- - NM_001136571
- NP_001130043
NM_000059.3:
checksum: f93216b3a596adab279ebd7903258548
filename: NM_000059.3.gb.bz2
geninfo_id: '119395733'
NM_000088.3:
checksum: 5d1f23e3c1799bdb5586c6786b5d5744
filename: NM_000088.3.gb.bz2
geninfo_id: '110349771'
NM_000132.3:
checksum: 94569bee76d7c8b1168e17df4fe1dcb4
filename: NM_000132.3.gb.bz2
geninfo_id: '192448441'
NM_000143.3:
checksum: c91799f40fdc0466bf7702af14cf070a
filename: NM_000143.3.gb.bz2
geninfo_id: '299758401'
NM_000193.2:
checksum: 86d03e1cf38c1387d90116539ea0678f
filename: NM_000193.2.gb.bz2
geninfo_id: '21071042'
NM_001199.3:
checksum: e750b6dcead66b8bb953ce445bcd3093
filename: NM_001199.3.gb.bz2
NM_002001.2:
checksum: 7fd5aa4fe864fd5193f224fca8cea70d
filename: NM_002001.2.gb.bz2
geninfo_id: '31317229'
NM_003002.2:
checksum: 990aa672364937335365609617df3050
filename: NM_003002.2.gb.bz2
geninfo_id: '222352156'
NM_004006.1:
checksum: be8fea2905e146bfe096e25fbfda2eef
filename: NM_004006.1.gb.bz2
geninfo_id: '5032282'
NM_004006.2:
checksum: ee2090536af19a13ac1d6faa46d0b12e
filename: NM_004006.2.gb.bz2
geninfo_id: '238018044'
NM_024426.4:
checksum: 830a3beb9b7af3c6ba3e8a15b1bd0f54
filename: NM_024426.4.gb.bz2
geninfo_id: '309951095'
NM_203473.1:
checksum: ec8fbdeda11ef8ec953e4ed39e9a84e5
filename: NM_203473.1
geninfo_id: '45439330'
NP_064445.1:
checksum: 33ea9315882b4a9d8c33018a201be2fa
filename: NP_064445.1.gb.bz2
geninfo_id: '9910526'
chr9_reverse:
accession: UD_139015349377
checksum: d21f92d09116c4831ce8d3ef832aa281
filename: UD_139015349377.gb.bz2
links:
- - NM_001195250
- NP_001182179
- - NR_036576
- null
- - NR_036577
- null
- - NM_001195252
- NP_001182181
- - NM_001195248
- NP_001182177
- - NM_175069
- NP_778239
- - NM_175073
- NP_778243
- - NM_001195251
- NP_001182180
- - NM_001195254
- NP_001182183
- - NR_036578
- null
- - NR_036579
- null
- - NM_001195249
- NP_001182178
This diff is collapsed.
This diff is collapsed.
......@@ -5,63 +5,55 @@ Tests for the mutalyzer.db.queries module.
from __future__ import unicode_literals
#import logging; logging.basicConfig()
import pytest
from mutalyzer.db import queries
from fixtures import database, cache
from utils import MutalyzerTest
from utils import fix
pytestmark = [
pytest.mark.usefixtures('references'),
pytest.mark.parametrize('references', [['MARK1']], indirect=True)
]
class TestMutator(MutalyzerTest):
def test_get_transcript_protein_link():
"""
Query a transcript-protein link by transcript.
"""
link = queries.get_transcript_protein_link('NM_018650')
assert link.transcript_accession == 'NM_018650'
assert link.protein_accession == 'NP_061120'
def test_get_transcript_protein_link_negative():
"""
Query a negative transcript-protein link by transcript.
"""
link = queries.get_transcript_protein_link('XM_005273133')
assert link.transcript_accession == 'XM_005273133'
assert link.protein_accession is None
def test_get_transcript_protein_link_missing():
"""
Query a missing transcript-protein link by transcript.
"""
link = queries.get_transcript_protein_link('NM_123456')
assert link is None
def test_get_transcript_protein_link_reverse():
"""
Query a transcript-protein link by protein.
"""
link = queries.get_transcript_protein_link('NP_061120', reverse=True)
assert link.transcript_accession == 'NM_018650'
assert link.protein_accession == 'NP_061120'
def test_get_transcript_protein_link_reverse_missing():
"""
Test the queries module.
Query a missing transcript-protein link by protein.
"""
fixtures = (database, )
def setup(self):
super(TestMutator, self).setup()
@fix(cache('MARK1'))
def test_get_transcript_protein_link(self):
"""
Query a transcript-protein link by transcript.
"""
link = queries.get_transcript_protein_link('NM_018650')
assert link.transcript_accession == 'NM_018650'
assert link.protein_accession == 'NP_061120'
@fix(cache('MARK1'))
def test_get_transcript_protein_link_negative(self):
"""
Query a negative transcript-protein link by transcript.
"""
link = queries.get_transcript_protein_link('XM_005273133')
assert link.transcript_accession == 'XM_005273133'
assert link.protein_accession is None
@fix(cache('MARK1'))
def test_get_transcript_protein_link_missing(self):
"""
Query a missing transcript-protein link by transcript.
"""
link = queries.get_transcript_protein_link('NM_123456')
assert link is None
@fix(cache('MARK1'))
def test_get_transcript_protein_link_reverse(self):
"""
Query a transcript-protein link by protein.
"""
link = queries.get_transcript_protein_link('NP_061120', reverse=True)
assert link.transcript_accession == 'NM_018650'
assert link.protein_accession == 'NP_061120'
@fix(cache('MARK1'))
def test_get_transcript_protein_link_reverse_missing(self):
"""
Query a missing transcript-protein link by protein.
"""
link = queries.get_transcript_protein_link('NP_123456')
assert link is None
link = queries.get_transcript_protein_link('NP_123456')
assert link is None
......@@ -5,148 +5,160 @@ Tests for the mutalyzer.grammar module.
from __future__ import unicode_literals
#import logging; logging.basicConfig()
import os
import pytest
import mutalyzer
from mutalyzer.grammar import Grammar
from mutalyzer.output import Output
from utils import MutalyzerTest
@pytest.fixture
def grammar(output):
return Grammar(output)
class TestGrammar(MutalyzerTest):
@pytest.fixture
def parser(output, grammar):
def parse(description):
__tracebackhide__ = True
grammar.parse(description)
errors = output.getMessagesWithErrorCode('EPARSE')
if len(errors) > 0:
pytest.fail('failed to parse `%s`: %s' % (
description, errors[0].description))
return parse
@pytest.mark.parametrize('description', [
'NM_002001.2:c.[12del]',
'NM_002001.2:c.[(12del)]',
'NM_002001.2:c.[(12del)?]',
'NM_002001.2:c.[(12del);(12del)]',
'NM_002001.2:c.[(12del;12del)]',
'NM_002001.2:c.[((12del)?;12del)?]'
])
def test_parse_variants(parser, description):
"""
Parse some example variants.
"""
parser(description)
@pytest.mark.parametrize('description', [
'NM_002001.2:c.15_16insA',
'NM_002001.2:c.15_16insATC',
'NM_002001.2:c.15_16ins[A]',
'NM_002001.2:c.15_16ins[ATC]',
'NM_002001.2:c.15_16ins28_39',
'NM_002001.2:c.15_16ins[28_39]',
'NM_002001.2:c.15_16ins[28_39;A]',
'NM_002001.2:c.15_16ins[28_39;ATC]',
'NM_002001.2:c.15_16ins[28_39;A;ATC]',
'NM_002001.2:c.15_16ins28_39inv',
'NM_002001.2:c.15_16ins[28_39inv]',
'NM_002001.2:c.15_16ins[28_39inv;A]',
'NM_002001.2:c.15_16ins[28_39inv;ATC]',
'NM_002001.2:c.15_16ins[28_39inv;A;ATC]'
])
def test_parse_compound_insertion(parser, description):
"""
Parse compound insertions.
"""
parser(description)
@pytest.mark.parametrize('description', [
'NM_002001.2:c.12_17delinsA',
'NM_002001.2:c.12_17delinsATC',
'NM_002001.2:c.12_17delins[A]',
'NM_002001.2:c.12_17delins[ATC]',
'NM_002001.2:c.12_17delins28_39',
'NM_002001.2:c.12_17delins[28_39]',
'NM_002001.2:c.12_17delins[28_39;A]',
'NM_002001.2:c.12_17delins[28_39;ATC]',
'NM_002001.2:c.12_17delins[28_39;A;ATC]',
'NM_002001.2:c.12_17delins28_39inv',
'NM_002001.2:c.12_17delins[28_39inv]',
'NM_002001.2:c.12_17delins[28_39inv;A]',
'NM_002001.2:c.12_17delins[28_39inv;ATC]',
'NM_002001.2:c.12_17delins[28_39inv;A;ATC]'
])
def test_parse_compound_delins(parser, description):
"""
Parse compound deletion-insertions.
"""
parser(description)
@pytest.mark.parametrize('description', [
'NG_009105.1(OPN1LW):p.=',
'NG_009105.1(OPN1LW):p.?',
'NM_000076.2(CDKN1C):p.0',
'NM_000076.2(CDKN1C):p.0?',
'NG_009105.1(OPN1LW):p.(=)',
'NM_000076.2(CDKN1C):p.(Ala123del)',
'NM_000076.2(CDKN1C):p.(Ala123_Leu126del)',
'NM_000076.2(CDKN1C):p.(Ala123_Leu126delinsVal)',
'NM_000076.2(CDKN1C):p.Ala123del',
'NM_000076.2(CDKN1C):p.Ala123_Leu126del',
'NM_000076.2(CDKN1C):p.Ala123_Leu126delinsVal',
'NM_000076.2(CDKN1C):p.Ala123_*317delinsVal',
'NM_000076.2(CDKN1C):p.Ala123_X317delinsVal',
'NM_000076.2(CDKN1C):p.Ala123delinsVal',
'NM_000076.2(CDKN1C):p.Ala123delinsValPro',
'NM_000076.2(CDKN1C):p.Ala123delinsVP',
'NM_000076.2(CDKN1C):p.Ala123fs',
'NM_000076.2(CDKN1C_i001):p.(Glu124Serfs*148)',
'NM_000076.2(CDKN1C_i001):p.(Glu124SerfsX148)',
'NM_000076.2(CDKN1C_i001):p.(E124Sfs*148)',
'NM_000076.2(CDKN1C_i001):p.(E124SfsX148)',
'NG_009105.1(OPN1LW):p.Met1Leu',
'NP_064445.1(OPN1LW):p.Met1?',
'NP_064445.1(OPN1LW):p.M1?',
'NP_064445.1:p.Gln16del',
'NP_064445.1:p.Gln16dup',
'NP_064445.1:p.Gln3del',
'NP_064445.1:p.Q16del',
'NP_064445.1:p.Q16dup',
'NP_064445.1:p.Q16*',
'NP_064445.1:p.Q16X',
'NG_009105.1:p.Gln3Leu',
'NG_009105.1(OPN1LW):p.Gln3Leu',
'NG_009105.1(OPN1LW_i1):p.Gln3Leu',
'NG_009105.1(OPN1LW_v1):p.Gln3Leu',
'NG_009105.1(OPN1LW):p.Gln3_Gln4insLeu',
'NG_009105.1(OPN1LW):p.Gln3_Gln4insGln',
'NG_009105.1(OPN1LW):p.Gln3_Gln4dup',
'NG_009105.1(OPN1LW):p.Q3_Q4insQ',
'NG_009105.1(OPN1LW):p.Q3_Q4insQQ',
'NG_009105.1(OPN1LW):p.Q3_Q4dup',
'NG_009105.1(OPN1LW):p.Gln3_Leu7del',
'NG_009105.1(OPN1LW):p.Gln3_Leu7delinsValLeu',
'NG_009105.1(OPN1LW):p.Gln3_Leu7delinsValPro',
'NG_009105.1(OPN1LW):p.Gln3_Leu7delinsGlnGlnTrpSerLeu',
'NG_009105.1(OPN1LW):p.Q3_L7delinsGlnGlnTrpSerLeu',
'NG_009105.1(OPN1LW):p.Gln3_Leu7delinsQQWSL',
# 'NG_009105.1(OPN1LW):p.Met1AlaextMet-1',
# 'NG_009105.1(OPN1LW):p.M1AextM-1',
# 'NG_009105.1(OPN1LW):p.Gln3_Leu7[3]',
'NG_009105.1(OPN1LW):p.Gln3_Leu7(1_6)',
'NG_009105.1(OPN1LW):p.Gln3Leu',
'NG_009105.1(OPN1LW):p.Gln3Leu',
# 'NM_000076.2(CDKN1C_i001):p.(*317Trpext*3)',
'NM_000076.2(CDKN1C_i001):p.(*317TrpextX3)',
# 'NM_000076.2(CDKN1C_i001):p.(*317Cysext*1)',
'NM_000076.2(CDKN1C_i001):p.(*317CysextX1)',
# 'NM_000076.2(CDKN1C_i001):p.(*317Cext*1)',
'NM_000076.2(CDKN1C_i001):p.(*317CextX1)',
# 't(X;17)(DMD:p.Met1_Val1506; SGCA:p.Val250_*387)'
])
def test_parse_protein_variants(parser, description):
"""
Parse protein variants.
"""
parser(description)
def test_parse_minus_in_gene_symbol(parser):
"""
Test the mytalyzer.grammar module.
Gene symbol is allowed to contain a minus character.
"""
def setup(self):
super(TestGrammar, self).setup()
self.output = Output(__file__)
self.grammar = Grammar(self.output)
def _parse(self, description):
"""
Parse a variant description.
"""
self.grammar.parse(description)
assert self.output.getOutput('parseError') == []
def test_some_variants(self):
"""
Some example variants.
"""
self._parse('NM_002001.2:c.[12del]')
self._parse('NM_002001.2:c.[(12del)]')
self._parse('NM_002001.2:c.[(12del)?]')
self._parse('NM_002001.2:c.[(12del);(12del)]')
self._parse('NM_002001.2:c.[(12del;12del)]')
self._parse('NM_002001.2:c.[((12del)?;12del)?]')
def test_compound_insertion(self):
"""
Some some compound insertions.
"""
self._parse('NM_002001.2:c.15_16insA')
self._parse('NM_002001.2:c.15_16insATC')
self._parse('NM_002001.2:c.15_16ins[A]')
self._parse('NM_002001.2:c.15_16ins[ATC]')
self._parse('NM_002001.2:c.15_16ins28_39')
self._parse('NM_002001.2:c.15_16ins[28_39]')
self._parse('NM_002001.2:c.15_16ins[28_39;A]')
self._parse('NM_002001.2:c.15_16ins[28_39;ATC]')
self._parse('NM_002001.2:c.15_16ins[28_39;A;ATC]')
self._parse('NM_002001.2:c.15_16ins28_39inv')
self._parse('NM_002001.2:c.15_16ins[28_39inv]')
self._parse('NM_002001.2:c.15_16ins[28_39inv;A]')
self._parse('NM_002001.2:c.15_16ins[28_39inv;ATC]')
self._parse('NM_002001.2:c.15_16ins[28_39inv;A;ATC]')
def test_compound_delins(self):
"""
Some some compound deletion-insertions.
"""
self._parse('NM_002001.2:c.12_17delinsA')
self._parse('NM_002001.2:c.12_17delinsATC')
self._parse('NM_002001.2:c.12_17delins[A]')
self._parse('NM_002001.2:c.12_17delins[ATC]')
self._parse('NM_002001.2:c.12_17delins28_39')
self._parse('NM_002001.2:c.12_17delins[28_39]')
self._parse('NM_002001.2:c.12_17delins[28_39;A]')
self._parse('NM_002001.2:c.12_17delins[28_39;ATC]')
self._parse('NM_002001.2:c.12_17delins[28_39;A;ATC]')
self._parse('NM_002001.2:c.12_17delins28_39inv')
self._parse('NM_002001.2:c.12_17delins[28_39inv]')
self._parse('NM_002001.2:c.12_17delins[28_39inv;A]')
self._parse('NM_002001.2:c.12_17delins[28_39inv;ATC]')
self._parse('NM_002001.2:c.12_17delins[28_39inv;A;ATC]')
def test_protein_variants(self):
"""
Some protein variants.
"""
self._parse('NG_009105.1(OPN1LW):p.=')
self._parse('NG_009105.1(OPN1LW):p.?')
self._parse('NM_000076.2(CDKN1C):p.0')
self._parse('NM_000076.2(CDKN1C):p.0?')
self._parse('NG_009105.1(OPN1LW):p.(=)')
self._parse('NM_000076.2(CDKN1C):p.(Ala123del)')
self._parse('NM_000076.2(CDKN1C):p.(Ala123_Leu126del)')
self._parse('NM_000076.2(CDKN1C):p.(Ala123_Leu126delinsVal)')
self._parse('NM_000076.2(CDKN1C):p.Ala123del')
self._parse('NM_000076.2(CDKN1C):p.Ala123_Leu126del')
self._parse('NM_000076.2(CDKN1C):p.Ala123_Leu126delinsVal')
self._parse('NM_000076.2(CDKN1C):p.Ala123_*317delinsVal')
self._parse('NM_000076.2(CDKN1C):p.Ala123_X317delinsVal')
self._parse('NM_000076.2(CDKN1C):p.Ala123delinsVal')
self._parse('NM_000076.2(CDKN1C):p.Ala123delinsValPro')
self._parse('NM_000076.2(CDKN1C):p.Ala123delinsVP')
self._parse('NM_000076.2(CDKN1C):p.Ala123fs')
self._parse('NM_000076.2(CDKN1C_i001):p.(Glu124Serfs*148)')
self._parse('NM_000076.2(CDKN1C_i001):p.(Glu124SerfsX148)')
self._parse('NM_000076.2(CDKN1C_i001):p.(E124Sfs*148)')
self._parse('NM_000076.2(CDKN1C_i001):p.(E124SfsX148)')
self._parse('NG_009105.1(OPN1LW):p.Met1Leu')
self._parse('NP_064445.1(OPN1LW):p.Met1?')
self._parse('NP_064445.1(OPN1LW):p.M1?')
self._parse('NP_064445.1:p.Gln16del')
self._parse('NP_064445.1:p.Gln16dup')
self._parse('NP_064445.1:p.Gln3del')
self._parse('NP_064445.1:p.Q16del')
self._parse('NP_064445.1:p.Q16dup')
self._parse('NP_064445.1:p.Q16*')
self._parse('NP_064445.1:p.Q16X')
self._parse('NG_009105.1:p.Gln3Leu')
self._parse('NG_009105.1(OPN1LW):p.Gln3Leu')
self._parse('NG_009105.1(OPN1LW_i1):p.Gln3Leu')
self._parse('NG_009105.1(OPN1LW_v1):p.Gln3Leu')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Gln4insLeu')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Gln4insGln')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Gln4dup')
self._parse('NG_009105.1(OPN1LW):p.Q3_Q4insQ')
self._parse('NG_009105.1(OPN1LW):p.Q3_Q4insQQ')
self._parse('NG_009105.1(OPN1LW):p.Q3_Q4dup')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Leu7del')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Leu7delinsValLeu')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Leu7delinsValPro')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Leu7delinsGlnGlnTrpSerLeu')
self._parse('NG_009105.1(OPN1LW):p.Q3_L7delinsGlnGlnTrpSerLeu')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Leu7delinsQQWSL')
#self._parse('NG_009105.1(OPN1LW):p.Met1AlaextMet-1')
#self._parse('NG_009105.1(OPN1LW):p.M1AextM-1')
#self._parse('NG_009105.1(OPN1LW):p.Gln3_Leu7[3]')
self._parse('NG_009105.1(OPN1LW):p.Gln3_Leu7(1_6)')
self._parse('NG_009105.1(OPN1LW):p.Gln3Leu')
self._parse('NG_009105.1(OPN1LW):p.Gln3Leu')
#self._parse('NM_000076.2(CDKN1C_i001):p.(*317Trpext*3)')
self._parse('NM_000076.2(CDKN1C_i001):p.(*317TrpextX3)')
#self._parse('NM_000076.2(CDKN1C_i001):p.(*317Cysext*1)')
self._parse('NM_000076.2(CDKN1C_i001):p.(*317CysextX1)')
#self._parse('NM_000076.2(CDKN1C_i001):p.(*317Cext*1)')
self._parse('NM_000076.2(CDKN1C_i001):p.(*317CextX1)')
#self._parse('t(X;17)(DMD:p.Met1_Val1506; SGCA:p.Val250_*387)')
def test_minus_in_gene_symbol(self):
"""
Gene symbol is allowed to contain a minus character.
"""
self._parse('UD_132464528477(KRTAP2-4_v001):c.100del')
parser('UD_132464528477(KRTAP2-4_v001):c.100del')
This diff is collapsed.
......@@ -5,8 +5,6 @@ Test database migrations.
from __future__ import unicode_literals
import os
import alembic.autogenerate
import alembic.command
import alembic.config
......@@ -17,16 +15,11 @@ from sqlalchemy import create_engine, sql
from mutalyzer import db
def test_migrations():
def test_migrations(database_uri):
"""
Run all migrations and assert the result is up to date with the model
definitions.
We don't use `utils.MutalyzerTest` here, or `mutalyzer.db.session` in any
way for that matter, since it will bootstrap the database schema.
"""
database_uri = os.getenv('MUTALYZER_TEST_DATABASE_URI', 'sqlite://')
alembic_config = alembic.config.Config('migrations/alembic.ini')
engine = create_engine(database_uri)
......
This diff is collapsed.
......@@ -5,52 +5,44 @@ Tests for the mutalyzer.parsers.genbank module.
from __future__ import unicode_literals
#import logging; logging.basicConfig()
import os
from mutalyzer.parsers import genbank
from mutalyzer.config import settings
import pytest
from fixtures import REFERENCES
from fixtures import database, cache
from utils import MutalyzerTest
from utils import fix
from mutalyzer.parsers.genbank import GBparser
class TestMutator(MutalyzerTest):
@pytest.fixture
def parser():
return GBparser()
@pytest.mark.parametrize('products,expected', [
(['a b c d e', 'a b C D e', 'a b c d e'], (2, 1)),
(['a b c d e', 'a b C d e', 'a B c d e'], (1, 2)),
(['a c d a', 'a b a', 'a a', 'a'], (1, 1)),
([''], (-1, -1)),
(['', ''], (-1, -1)),
(['a', 'a'], (-1, -1)),
(['a', 'b'], (0, 0)),
(['a b c', 'a b c'], (-1, -1)),
(['a b c d a b', 'a b'], (2, 2))
])
def test_product_lists_mismatch(parser, products, expected):
"""
Test finding mismatches in some product lists.
"""
assert parser._find_mismatch(products) == expected
@pytest.mark.parametrize('references', [['A1BG']], indirect=True)
def test_only_complete_genes_included(settings, references, parser):
"""
Test the mutator module.
Incomplete genes from the reference file should be ignored.
"""
fixtures = (database, )
def setup(self):
super(TestMutator, self).setup()
self.gb_parser = genbank.GBparser()
def test_product_lists_mismatch(self):
"""
Test finding mismatches in some product lists.
"""
tests = [(['a b c d e', 'a b C D e', 'a b c d e'], (2, 1)),
(['a b c d e', 'a b C d e', 'a B c d e'], (1, 2)),
(['a c d a', 'a b a', 'a a', 'a'], (1, 1)),
([''], (-1, -1)),
(['', ''], (-1, -1)),
(['a', 'a'], (-1, -1)),
(['a', 'b'], (0, 0)),
(['a b c', 'a b c'], (-1, -1)),
(['a b c d a b', 'a b'], (2, 2))]
for test in tests:
assert self.gb_parser._find_mismatch(test[0]) == test[1]
@fix(cache('A1BG'))
def test_only_complete_genes_included(self):
"""
Incomplete genes from the reference file should be ignored.
"""
# contains A1BG (complete) and A1BG-AS1, ZNF497, LOC100419840
# (incomplete).
genbank_filename = os.path.join(settings.CACHE_DIR,
REFERENCES['A1BG']['filename'])
record = self.gb_parser.create_record(genbank_filename)
assert [g.name for g in record.geneList] == ['A1BG']
# contains A1BG (complete) and A1BG-AS1, ZNF497, LOC100419840
# (incomplete).
accession = references[0].accession
filename = os.path.join(settings.CACHE_DIR, '%s.gb.bz2' % accession)
record = parser.create_record(filename)
assert [g.name for g in record.geneList] == ['A1BG']
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment