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

Updated unit tests. Now using the nose Python testing framework.

parent 2d73e50f
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ This program depends on the following packages:
- python-webpy >= 0.33
- python-webtest >= 1.2.3
- python-suds >= 0.3.9-1
- python-nose >= 0.11
The web and SOAP interfaces depend on the following packages:
- apache2 >= 2.2.11
......
......@@ -28,6 +28,8 @@ Todo:
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
* Document integration, deployment, release management, etc.
* Use standard logging module, with rotating functionality.
* Use environment variable for testing situation. Something like:
http://webpy.org/cookbook/testing_with_paste_and_nose
Notes for server setup (Europium VM copy):
......
#!/usr/bin/env python
"""
Tests for the mutalyzer.grammar module.
"""
#import logging; logging.basicConfig()
import os
import unittest
import site
from nose.tools import *
# Todo: Can this be done in a more elegant way?
os.chdir('../..')
......@@ -18,7 +16,7 @@ from mutalyzer.grammar import Grammar
from mutalyzer.output import Output
class TestGrammar(unittest.TestCase):
class TestGrammar():
"""
Test the mytalyzer.grammar module.
"""
......@@ -33,7 +31,7 @@ class TestGrammar(unittest.TestCase):
def test_some_variants(self):
"""
No change, no shifts.
Some example variants.
"""
self.grammar.parse('NM_002001.2:c.[12del]')
self.grammar.parse('NM_002001.2:c.[(12del)]')
......@@ -41,11 +39,3 @@ class TestGrammar(unittest.TestCase):
self.grammar.parse('NM_002001.2:c.[(12del);(12del)]')
self.grammar.parse('NM_002001.2:c.[(12del;12del)]')
self.grammar.parse('NM_002001.2:c.[((12del)?;12del)?]')
if __name__ == '__main__':
# Usage:
# ./test_parser.py -v
# Or, selecting a specific test:
# ./test_parser.py -v TestParser.test_some_variants
unittest.main()
#!/usr/bin/env python
"""
Tests for the Mutalyzer module.
"""
......@@ -8,8 +6,8 @@ Tests for the Mutalyzer module.
import re
import os
import random
import unittest
import site
from nose.tools import *
from Bio.Seq import Seq
# Todo: Can this be done in a more elegant way?
......@@ -21,7 +19,7 @@ from mutalyzer.output import Output
from mutalyzer.variantchecker import check_variant
class TestMutalyzer(unittest.TestCase):
class TestMutalyzer():
"""
Test the Mutalyzer module.
"""
......@@ -39,7 +37,7 @@ class TestMutalyzer(unittest.TestCase):
"""
check_variant('NM_003002.2:c.273del', self.config, self.output)
wroll = self.output.getMessagesWithErrorCode('WROLL')
self.assertTrue(len(wroll) > 0)
assert len(wroll) > 0
def test_no_roll(self):
"""
......@@ -47,7 +45,7 @@ class TestMutalyzer(unittest.TestCase):
"""
check_variant('NM_003002.2:c.274del', self.config, self.output)
wroll = self.output.getMessagesWithErrorCode('WROLL')
self.assertTrue(len(wroll) == 0)
assert len(wroll) == 0
def test_no_roll_splice(self):
"""
......@@ -55,9 +53,9 @@ class TestMutalyzer(unittest.TestCase):
"""
check_variant('NM_000088.3:g.459del', self.config, self.output)
wrollback = self.output.getMessagesWithErrorCode('IROLLBACK')
self.assertTrue(len(wrollback) > 0)
assert len(wrollback) > 0
wroll = self.output.getMessagesWithErrorCode('WROLL')
self.assertTrue(len(wroll) == 0)
assert len(wroll) == 0
def test_partial_roll_splice(self):
"""
......@@ -66,9 +64,9 @@ class TestMutalyzer(unittest.TestCase):
"""
check_variant('NM_000088.3:g.494del', self.config, self.output)
wrollback = self.output.getMessagesWithErrorCode('IROLLBACK')
self.assertTrue(len(wrollback) > 0)
assert len(wrollback) > 0
wroll = self.output.getMessagesWithErrorCode('WROLL')
self.assertTrue(len(wroll) > 0)
assert len(wroll) > 0
def test_roll_after_splice(self):
"""
......@@ -76,26 +74,18 @@ class TestMutalyzer(unittest.TestCase):
"""
check_variant('NM_000088.3:g.460del', self.config, self.output)
wroll = self.output.getMessagesWithErrorCode('WROLL')
self.assertTrue(len(wroll) > 0)
assert len(wroll) > 0
def test_ins_cds_start(self):
"""
Insertion on CDS start boundary should not be included in CDS.
"""
check_variant('NM_000143.3:c.-1_1insCAT', self.config, self.output)
self.assertEqual(self.output.getIndexedOutput("newprotein", 0), None)
assert_equal(self.output.getIndexedOutput("newprotein", 0), None)
def test_ins_cds_start_after(self):
"""
Insertion after CDS start boundary should be included in CDS.
"""
check_variant('NM_000143.3:c.1_2insCAT', self.config, self.output)
self.assertEqual(self.output.getIndexedOutput("newprotein", 0), '?')
if __name__ == '__main__':
# Usage:
# ./test_mutalyzer.py -v
# Or, selecting a specific test:
# ./test_mutalyzer.py -v TestMutalyzer.test_ins_cds_start
unittest.main()
assert_equal(self.output.getIndexedOutput("newprotein", 0), '?')
This diff is collapsed.
#!/usr/bin/env python
"""
Tests for the SOAP interface to Mutalyzer.
"""
import logging; logging.raiseExceptions = 0
import urllib2
from suds.client import Client
from suds import WebFault
import unittest
from nose.tools import *
WSDL_URL = 'http://mutalyzer.martijn/services/?wsdl'
class TestWSDL(unittest.TestCase):
class TestWSDL():
"""
Test the Mutalyzer SOAP interface WSDL description.
"""
......@@ -21,10 +22,11 @@ class TestWSDL(unittest.TestCase):
Test if the WSDL is available and looks somewhat sensible.
"""
wsdl = urllib2.urlopen(WSDL_URL).read()
self.assertTrue(wsdl.startswith("<?xml version='1.0' encoding='UTF-8'?>"))
self.assertTrue('name="Mutalyzer"' in wsdl)
assert wsdl.startswith("<?xml version='1.0' encoding='UTF-8'?>")
assert 'name="Mutalyzer"' in wsdl
class TestWebservice(unittest.TestCase):
class TestWebservice():
"""
Test the Mutalyzer SOAP interface.
"""
......@@ -43,7 +45,7 @@ class TestWebservice(unittest.TestCase):
Running checkSyntax with a valid variant name should return True.
"""
r = self.client.service.checkSyntax('AB026906.1:c.274G>T')
self.assertEqual(r.valid, True)
assert_equal(r.valid, True)
def test_checksyntax_invalid(self):
"""
......@@ -51,19 +53,15 @@ class TestWebservice(unittest.TestCase):
and give at least one error message.
"""
r = self.client.service.checkSyntax('0:abcd')
self.assertEqual(r.valid, False)
self.assertTrue(len(r.messages.SoapMessage) >= 1)
assert_equal(r.valid, False)
assert len(r.messages.SoapMessage) >= 1
@raises(WebFault)
def test_checksyntax_empty(self):
"""
Running checkSyntax with no variant name should raise exception.
"""
try:
self.client.service.checkSyntax()
self.fail('Expected WebFault exception')
except WebFault, e:
self.assertEqual(e.fault.faultstring,
'The variant argument is not provided.')
self.client.service.checkSyntax()
def test_transcriptinfo_valid(self):
"""
......@@ -72,9 +70,9 @@ class TestWebservice(unittest.TestCase):
"""
r = self.client.service.transcriptInfo(LOVD_ver='123', build='hg19',
accNo='NM_002001.2')
self.assertEqual(r.trans_start, -99)
self.assertEqual(r.trans_stop, 1066)
self.assertEqual(r.CDS_stop, 774)
assert_equal(r.trans_start, -99)
assert_equal(r.trans_stop, 1066)
assert_equal(r.CDS_stop, 774)
def test_numberconversion_gtoc_valid(self):
"""
......@@ -83,8 +81,8 @@ class TestWebservice(unittest.TestCase):
"""
r = self.client.service.numberConversion(build='hg19',
variant='NC_000001.10:g.159272155del')
self.assertEqual(type(r.string), list)
self.assertTrue('NM_002001.2:c.1del' in r.string)
assert_equal(type(r.string), list)
assert 'NM_002001.2:c.1del' in r.string
def test_numberconversion_ctog_valid(self):
"""
......@@ -93,8 +91,8 @@ class TestWebservice(unittest.TestCase):
"""
r = self.client.service.numberConversion(build='hg19',
variant='NM_002001.2:c.1del')
self.assertEqual(type(r.string), list)
self.assertTrue('NC_000001.10:g.159272155del' in r.string)
assert_equal(type(r.string), list)
assert 'NC_000001.10:g.159272155del' in r.string
def test_gettranscriptsbygenename_valid(self):
"""
......@@ -103,7 +101,7 @@ class TestWebservice(unittest.TestCase):
"""
r = self.client.service.getTranscriptsByGeneName(build='hg19',
name='DMD')
self.assertEqual(type(r.string), list)
assert_equal(type(r.string), list)
for t in ['NM_004006.2',
'NM_000109.3',
'NM_004021.2',
......@@ -111,7 +109,7 @@ class TestWebservice(unittest.TestCase):
'NM_004007.2',
'NM_004018.2',
'NM_004022.2']:
self.assertTrue(t in r.string)
assert t in r.string
def test_gettranscriptsandinfo_valid(self):
"""
......@@ -119,7 +117,7 @@ class TestWebservice(unittest.TestCase):
give a list of TranscriptInfo objects.
"""
r = self.client.service.getTranscriptsAndInfo('AL449423.14')
self.assertEqual(type(r.TranscriptInfo), list)
assert_equal(type(r.TranscriptInfo), list)
names = [t.name for t in r.TranscriptInfo]
for t in ['CDKN2B_v002',
'CDKN2B_v001',
......@@ -128,7 +126,7 @@ class TestWebservice(unittest.TestCase):
'CDKN2A_v007',
'C9orf53_v001',
'CDKN2A_v001']:
self.assertTrue(t in names)
assert t in names
def test_gettranscriptsandinfo_restricted_valid(self):
"""
......@@ -137,20 +135,13 @@ class TestWebservice(unittest.TestCase):
to the gene.
"""
r = self.client.service.getTranscriptsAndInfo('AL449423.14', 'CDKN2A')
self.assertEqual(type(r.TranscriptInfo), list)
assert_equal(type(r.TranscriptInfo), list)
names = [t.name for t in r.TranscriptInfo]
for t in ['CDKN2A_v008',
'CDKN2A_v007']:
self.assertTrue(t in names)
assert t in names
for t in ['CDKN2B_v002',
'CDKN2B_v001',
'MTAP_v005',
'C9orf53_v001']:
self.assertFalse(t in names)
if __name__ == '__main__':
# Usage:
# ./test_webservice.py -v
# Or, selecting a specific test:
# ./test_webservice.py -v TestWebservice.test_checksyntax_empty
unittest.main()
assert_false(t in names)
#!/usr/bin/env python
"""
Tests for the WSGI interface to Mutalyzer.
......@@ -12,10 +10,11 @@ I just installed webtest by 'easy_install webtest'.
@todo: Tests for /upload.
"""
#import logging; logging.basicConfig()
import re
import time
import unittest
from nose.tools import *
from webtest import TestApp
# Todo: Can this be done in a more elegant way?
......@@ -23,7 +22,8 @@ import site
site.addsitedir('../..')
from mutalyzer.wsgi import application
class TestWSGI(unittest.TestCase):
class TestWSGI():
"""
Test the Mutalyzer WSGI interface.
"""
......@@ -39,7 +39,7 @@ class TestWSGI(unittest.TestCase):
Expect the index HTML page.
"""
r = self.app.get('/')
self.assertEqual(r.status, '200 OK')
assert_equal(r.status, '200 OK')
# We check for <html> to make sure the menu template is included
r.mustcontain('<html>',
'Welcome to the Mutalyzer web site',
......@@ -131,8 +131,8 @@ class TestWSGI(unittest.TestCase):
Should not include form and main layout HTML.
"""
r = self.app.get('/check?mutationName=NM_002001.2:g.1del')
self.assertFalse('<a href="#bottom" class="hornav">go to bottom</a>' in r)
self.assertFalse('<input value="NM_002001.2:g.1del" type="text" name="mutationName" style="width:100%">' in r)
assert_false('<a href="#bottom" class="hornav">go to bottom</a>' in r)
assert_false('<input value="NM_002001.2:g.1del" type="text" name="mutationName" style="width:100%">' in r)
r.mustcontain('0 Errors',
'0 Warnings',
'Raw variant 1: deletion of 1',
......@@ -145,8 +145,8 @@ class TestWSGI(unittest.TestCase):
redirect to the name checker.
"""
r = self.app.get('/checkForward?mutationName=NM_002001.2:g.1del')
self.assertEqual(r.status, '303 See Other')
self.assertTrue(r.location.endswith('/check'))
assert_equal(r.status, '303 See Other')
assert r.location.endswith('/check')
r = r.follow()
r.mustcontain('0 Errors',
'0 Warnings',
......@@ -229,16 +229,16 @@ class TestWSGI(unittest.TestCase):
max_tries = 60
for i in range(max_tries):
r = self.app.get('/progress?jobID=' + id + '&totalJobs=' + str(size) + '&ajax=1')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
#print '%s: %s' % (batch_type, r.body)
if r.body == 'OK': break
self.assertTrue(re.match('[0-9]+', r.body))
assert re.match('[0-9]+', r.body)
time.sleep(2)
self.assertEqual(r.body, 'OK')
assert_equal(r.body, 'OK')
r = self.app.get('/Results_' + id + '.txt')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
r.mustcontain(header)
self.assertTrue(len(r.body.strip().split('\n')) == size + 1)
assert len(r.body.strip().split('\n')) == size + 1
def test_batch_namechecker(self):
"""
......@@ -401,14 +401,14 @@ facilisi."""
form.set('batchFile', ('test_batch_toobig.txt',
file))
r = form.submit(status=413)
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
def test_download_py(self):
"""
Download a Python example client for the webservice.
"""
r = self.app.get('/download/client-suds.py')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
r.mustcontain('#!/usr/bin/env python')
def test_download_rb(self):
......@@ -416,7 +416,7 @@ facilisi."""
Download a Ruby example client for the webservice.
"""
r = self.app.get('/download/client-savon.rb')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
r.mustcontain('#!/usr/bin/env ruby')
def test_download_cs(self):
......@@ -424,7 +424,7 @@ facilisi."""
Download a C# example client for the webservice.
"""
r = self.app.get('/download/client-mono.cs')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
r.mustcontain('public static void Main(String [] args) {')
def test_download_php(self):
......@@ -432,7 +432,7 @@ facilisi."""
Download a PHP example client for the webservice.
"""
r = self.app.get('/download/client-php.php')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
r.mustcontain('<?php')
def test_downloads_batchtest(self):
......@@ -440,7 +440,7 @@ facilisi."""
Download the batch test example file.
"""
r = self.app.get('/downloads/batchtestnew.txt')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
r.mustcontain('NM_003002.1:c.3_4insG')
def test_reference(self):
......@@ -448,8 +448,8 @@ facilisi."""
Download a reference file.
"""
r = self.app.get('/Reference/AB026906.1.gb')
self.assertEqual(r.content_type, 'text/plain')
self.assertEqual(r.content_length, 26427)
assert_equal(r.content_type, 'text/plain')
assert_equal(r.content_length, 26427)
r.mustcontain('ggaaaaagtc tctcaaaaaa cctgctttat')
def test_soap_documentation(self):
......@@ -457,7 +457,7 @@ facilisi."""
Test the SOAP documentation generated from the WSDL.
"""
r = self.app.get('/documentation')
self.assertEqual(r.content_type, 'text/html')
assert_equal(r.content_type, 'text/html')
r.mustcontain('Web Service: Mutalyzer')
def test_getgs(self):
......@@ -468,26 +468,26 @@ facilisi."""
r.mustcontain('0 Errors',
'0 Warnings',
'Raw variant 1: substitution at 7055')
self.assertTrue(r.body.find('go to bottom') == -1)
self.assertTrue(r.body.find('<input') == -1)
assert r.body.find('go to bottom') == -1
assert r.body.find('<input') == -1
def test_variantinfo_g2c(self):
"""
Test the /Variant_info interface used by LOVD2 (g to c).
"""
r = self.app.get('/Variant_info?LOVD_ver=2.0-29&build=hg19&acc=NM_203473.1&var=g.48374289_48374389del')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
expected = '\n'.join(['1020', '0', '1072', '48', '48374289', '48374389', 'del'])
self.assertEqual(r.body, expected)
assert_equal(r.body, expected)
def test_variantinfo_c2g(self):
"""
Test the /Variant_info interface used by LOVD2 (c to g).
"""
r = self.app.get('/Variant_info?LOVD_ver=2.0-29&build=hg19&acc=NM_203473.1&var=c.1020_1072%2B48del')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
expected = '\n'.join(['1020', '0', '1072', '48', '48374289', '48374389', 'del'])
self.assertEqual(r.body, expected)
assert_equal(r.body, expected)
def test_variantinfo_c2g_downstream(self):
"""
......@@ -495,9 +495,9 @@ facilisi."""
notation to g).
"""
r = self.app.get('/Variant_info?LOVD_ver=2.0-29&build=hg19&acc=NM_203473.1&var=c.1709%2Bd187del')
self.assertEqual(r.content_type, 'text/plain')
assert_equal(r.content_type, 'text/plain')
expected = '\n'.join(['1709', '187', '1709', '187', '48379389', '48379389', 'del'])
self.assertEqual(r.body, expected)
assert_equal(r.body, expected)
def test_upload_local_file(self):
"""
......@@ -513,10 +513,3 @@ facilisi."""
open(test_genbank_file, 'r').read()))
r = form.submit()
r.mustcontain('Your reference sequence was uploaded successfully.')
if __name__ == '__main__':
# Usage:
# ./test_wsgi.py -v
# Or, selecting a specific test:
# ./test_wsgi.py -v TestWSGI.test_getgs
unittest.main()
......@@ -351,9 +351,9 @@ def trim_common(s1, s2):
"""
Given two strings, trim their longest common prefix and suffix.
>>> util.trim_common('abcdefg', 'abcabcdefg')
>>> trim_common('abcdefg', 'abcabcdefg')
('', 'abc', 3, 4)
>>> util.trim_common('abcxyzefg', 'abcabcg')
>>> trim_common('abcxyzefg', 'abcabcg')
('xyzef', 'abc', 3, 1)
@arg s1: A string.
......
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