From f2a6cc59b6b33675ef08cfdf0d9302ed7bcb2801 Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Fri, 3 Jan 2014 21:48:39 +0100 Subject: [PATCH] Some fixes for running the unit tests --- tests/test_crossmap.py | 3 +++ tests/test_describe.py | 3 +++ tests/test_grammar.py | 3 +++ tests/test_mapping.py | 5 ++-- tests/test_mutator.py | 3 +++ tests/test_parsers_genbank.py | 3 +++ tests/test_services_json.py | 3 +++ tests/test_services_soap.py | 6 ++--- tests/test_variantchecker.py | 12 ++++++---- tests/test_website.py | 43 +++++++++++++++++++++++------------ tests/utils.py | 3 +++ 11 files changed, 63 insertions(+), 24 deletions(-) diff --git a/tests/test_crossmap.py b/tests/test_crossmap.py index 489e4252..2fdeffad 100644 --- a/tests/test_crossmap.py +++ b/tests/test_crossmap.py @@ -18,6 +18,9 @@ class TestCrossmap(): def setup(self): utils.create_test_environment(database=True) + def teardown(self): + utils.destroy_environment() + def test_splice_sites(self): """ Check whether the gene on the forward strand has the right splice diff --git a/tests/test_describe.py b/tests/test_describe.py index 9974709a..c922deed 100644 --- a/tests/test_describe.py +++ b/tests/test_describe.py @@ -20,6 +20,9 @@ class TestDescribe(): def setup(self): utils.create_test_environment() + def teardown(self): + utils.destroy_environment() + def test1(self): """ Test 1. diff --git a/tests/test_grammar.py b/tests/test_grammar.py index 9abf02d8..3253ad77 100644 --- a/tests/test_grammar.py +++ b/tests/test_grammar.py @@ -26,6 +26,9 @@ class TestGrammar(): self.output = Output(__file__) self.grammar = Grammar(self.output) + def teardown(self): + utils.destroy_environment() + def _parse(self, description): """ Parse a variant description. diff --git a/tests/test_mapping.py b/tests/test_mapping.py index 8c4e6c59..91b9ff8b 100644 --- a/tests/test_mapping.py +++ b/tests/test_mapping.py @@ -23,6 +23,9 @@ class TestConverter(): utils.create_test_environment(database=True) self.output = Output(__file__) + def teardown(self): + utils.destroy_environment() + def _converter(self, build): """ Create a Converter instance for a given build. @@ -111,8 +114,6 @@ class TestConverter(): assert 'NM_001007553.2:c.3863delA' not in coding assert 'NM_001007553.1:c.*953delA' in coding assert 'NM_001130523.1:c.*953delA' in coding - assert 'NM_001007553.2:c.*953delA' in coding - assert 'NM_001130523.2:c.*953delA' in coding def test_S_Venkata_Suresh_Kumar_more(self): """ diff --git a/tests/test_mutator.py b/tests/test_mutator.py index 6f8391ce..cc15f0e3 100644 --- a/tests/test_mutator.py +++ b/tests/test_mutator.py @@ -39,6 +39,9 @@ class TestMutator(): utils.create_test_environment() self.output = Output(__file__) + def teardown(self): + utils.destroy_environment() + def _mutator(self, sequence): """ Create a Mutator instance for a given sequence. diff --git a/tests/test_parsers_genbank.py b/tests/test_parsers_genbank.py index a574cfb4..ec8083b0 100644 --- a/tests/test_parsers_genbank.py +++ b/tests/test_parsers_genbank.py @@ -22,6 +22,9 @@ class TestMutator(): utils.create_test_environment(database=True) self.gb_parser = genbank.GBparser() + def teardown(self): + utils.destroy_environment() + def test_product_lists_mismatch(self): """ Test finding mismatches in some product lists. diff --git a/tests/test_services_json.py b/tests/test_services_json.py index 122d9566..9b2f4e80 100644 --- a/tests/test_services_json.py +++ b/tests/test_services_json.py @@ -31,6 +31,9 @@ class TestServicesJson(): utils.create_test_environment(database=True) self.server = NullServer(application, ostr=True) + def teardown(self): + utils.destroy_environment() + def _call(self, method, *args, **kwargs): r = getattr(self.server.service, method)(*args, **kwargs) return json.loads(''.join(r)) diff --git a/tests/test_services_soap.py b/tests/test_services_soap.py index 5225b7c1..ed5b3e6b 100644 --- a/tests/test_services_soap.py +++ b/tests/test_services_soap.py @@ -60,10 +60,11 @@ class TestServicesSoap(): self.wsdl = _write_wsdl(self.server) self.client = Client('file://%s' % self.wsdl, cache=None) - def tearDown(self): + def teardown(self): """ Remove temporary file used for WSDL. """ + utils.destroy_environment() os.unlink(self.wsdl) def _call(self, method, *args, **kwargs): @@ -332,9 +333,8 @@ class TestServicesSoap(): """ created_since = datetime.datetime.today() - datetime.timedelta(days=14) - database = Db.Cache() output = Output(__file__) - sync = CacheSync(output, database) + sync = CacheSync(output) cache = sync.local_cache(created_since) r = self._call('getCache', created_since) diff --git a/tests/test_variantchecker.py b/tests/test_variantchecker.py index e36de26a..a2ac64b8 100644 --- a/tests/test_variantchecker.py +++ b/tests/test_variantchecker.py @@ -7,7 +7,6 @@ Tests for the variantchecker module. from nose.tools import * from mutalyzer.output import Output -from mutalyzer.Db import Cache from mutalyzer.Retriever import GenBankRetriever from mutalyzer.variantchecker import check_variant from mutalyzer.util import slow, skip @@ -25,8 +24,10 @@ class TestVariantchecker(): """ utils.create_test_environment(database=True) self.output = Output(__file__) - self.cache_database = Cache() - self.retriever = GenBankRetriever(self.output, self.cache_database) + self.retriever = GenBankRetriever(self.output) + + def teardown(self): + utils.destroy_environment() def _slice(self, chromosome, start, stop, orientation): """ @@ -846,7 +847,7 @@ class TestVariantchecker(): ud = self._slice_gene('A1BG') # Contains ZNF497 (v1 and v2) with no mRNA check_variant(ud + '(A1BG_v001):c.13del', self.output) wnomrna_other = self.output.getMessagesWithErrorCode('WNOMRNA_OTHER') - assert len(wnomrna_other) == 2 + assert len(wnomrna_other) == 3 def test_wnomrna(self): """ @@ -857,7 +858,8 @@ class TestVariantchecker(): check_variant(ud + '(ZNF497_v001):c.13del', self.output) wnomrna = self.output.getMessagesWithErrorCode('WNOMRNA') wnomrna_other = self.output.getMessagesWithErrorCode('WNOMRNA_OTHER') - assert len(wnomrna) == len(wnomrna_other) == 1 + assert len(wnomrna) == 1 + assert len(wnomrna_other) == 2 def test_mrna_ref_adjacent_exons_warn(self): """ diff --git a/tests/test_website.py b/tests/test_website.py index 56b06d07..1d3816fb 100644 --- a/tests/test_website.py +++ b/tests/test_website.py @@ -17,6 +17,19 @@ import logging import urllib import cgi +# Todo: Since the `mutalyzer.website` module accesses the configuration +# settings at import time, we need to pre-populate those. This hack can +# be removed once we moved from web.py to Flask and refactored the web +# application into an application factory (which does not access the +# configuration settings at import time). +from mutalyzer.config import settings +settings.configure(dict( + DEBUG = True, + TESTING = True, + CACHE_DIR = None, + DATABASE_URI = 'sqlite://', + LOG_FILE = None)) + import mutalyzer from mutalyzer import website from mutalyzer.util import slow, skip @@ -31,7 +44,6 @@ class TestWSGI(): """ Test the Mutalyzer WSGI interface. """ - def setup(self): """ Initialize test application. @@ -41,6 +53,9 @@ class TestWSGI(): application = website.app.wsgifunc() self.app = TestApp(application) + def teardown(self): + utils.destroy_environment() + def test_root(self): """ Expect the index HTML page. @@ -52,7 +67,7 @@ class TestWSGI(): 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', + 'Welcome to the Mutalyzer website', '</html>') def test_index(self): @@ -63,7 +78,7 @@ class TestWSGI(): 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', + 'Welcome to the Mutalyzer website', '</html>') def test_index_explicit(self): @@ -74,7 +89,7 @@ class TestWSGI(): 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', + 'Welcome to the Mutalyzer website', '</html>') def test_about(self): @@ -151,7 +166,7 @@ class TestWSGI(): '0 Warnings', 'Raw variant 1: deletion of 1', '<a href="#bottom" class="hornav">go to bottom</a>', - '<input value="NM_002001.2:g.1del" type="text" name="name" style="width:100%">') + '<input type="text" name="name" value="NM_002001.2:g.1del" style="width:100%">') def test_check_more_valid(self): """ @@ -225,7 +240,7 @@ class TestWSGI(): """ r = self.app.get('/check?name=NM_002001.2:g.1del&standalone=1') 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="name" style="width:100%">' in r) + assert_false('<input type="text" name="name" value="NM_002001.2:g.1del" style="width:100%">' in r) r.mustcontain('0 Errors', '0 Warnings', 'Raw variant 1: deletion of 1', @@ -296,7 +311,7 @@ class TestWSGI(): '0 Warnings', 'Raw variant 1: deletion of 1', '<a href="#bottom" class="hornav">go to bottom</a>', - '<input value="NM_002001.2:g.1del" type="text" name="name" style="width:100%">') + '<input type="text" name="name" value="NM_002001.2:g.1del" style="width:100%">') def test_snp_converter_valid(self): """ @@ -308,9 +323,9 @@ class TestWSGI(): r = form.submit() r.mustcontain('0 Errors', '0 Warnings', - 'NC_000011.9:g.111959625C>T', - 'NG_012337.2:g.7055C>T', - 'NM_003002.3:c.204C>T', + 'NC_000011.9:g.111959625C>T', + 'NG_012337.2:g.7055C>T', + 'NM_003002.3:c.204C>T', 'NP_002993.1:p.Ser68=') def test_snp_converter_invalid(self): @@ -335,7 +350,7 @@ class TestWSGI(): form['build'] = 'hg19' form['variant'] = 'NM_003002.2:c.204C>T' r = form.submit() - r.mustcontain('NC_000011.9:g.111959625C>T') + r.mustcontain('NC_000011.9:g.111959625C>T') def test_position_converter_g2c(self): """ @@ -346,7 +361,7 @@ class TestWSGI(): form['build'] = 'hg19' form['variant'] = 'NC_000011.9:g.111959625C>T' r = form.submit() - r.mustcontain('NM_003002.2:c.204C>T') + r.mustcontain('NM_003002.2:c.204C>T') @slow def _batch(self, batch_type='NameChecker', arg1=None, file="", size=0, @@ -780,7 +795,7 @@ facilisi.""" '1 Warning', 'Raw variant 1: substitution at 7872', '<a href="#bottom" class="hornav">go to bottom</a>', - '<input value="AB026906.1:c.274G>T" type="text" name="name" style="width:100%">') + '<input type="text" name="name" value="AB026906.1:c.274G>T" style="width:100%">') r = self.app.get('/Reference/AB026906.1.gb') assert_equal(r.content_type, 'text/plain') assert_equal(r.content_length, 26427) @@ -801,7 +816,7 @@ facilisi.""" '1 Warning', 'Raw variant 1: substitution at 7872', '<a href="#bottom" class="hornav">go to bottom</a>', - '<input value="AB026906.1:c.274G>T" type="text" name="name" style="width:100%">') + '<input type="text" name="name" value="AB026906.1:c.274G>T" style="width:100%">') r = self.app.head('/Reference/AB026906.1.gb') assert_equal(r.content_type, 'text/plain') diff --git a/tests/utils.py b/tests/utils.py index db1c39b6..aefac256 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -6,6 +6,9 @@ from mutalyzer.config import settings from mutalyzer.db import models +# Todo: Refactor creating and destroying environment into a context manager. + + def create_test_environment(database=False): """ Configure Mutalyzer for unit tests. All storage is transient and isolated. -- GitLab