Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 665e210c rédigé par Adrien Leger's avatar Adrien Leger
Parcourir les fichiers

Change test to pytest package

parent e5cbb72e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -71,12 +71,12 @@ class MakeBlastDB(object):
if proc.returncode == 1:
msg = "An error occured during execution of following command :\n"
msg += "COMMAND : {}\n".format(cmd)
msg += "STDERR : {}\n".format(stderr)
msg += "STDERR : {}\n".format(stderr.strip())
raise Exception (msg)
# Verify the output
if not stdout:
raise Exception ("Error, no data received from standard output\n"+stderr)
raise Exception ("Error, no data received from standard output\n{}\n".format(stderr.strip()))
return path.abspath(db_path)
......@@ -89,4 +89,4 @@ class MakeBlastDB(object):
if path.isfile (f):
remove (f)
raise Exception (E.message+"Impossible to generate a valid database from the reference sequence")
raise Exception (str(E)+"Impossible to generate a valid database from the reference sequence")
# pyBlast
Python 2.7 wrapper for ncbi blast+
Python 2.7/3.3 wrapper for ncbi blast+
## Test
* Install pytest
* Run test with py.test-2.7 -v
\ No newline at end of file
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import random
import string
if __name__ == '__main__':
msg = ""
###############################################################################################
print ("Testing MakeBlastDB")
try:
from MakeBlastDB import MakeBlastDB
db_maker = MakeBlastDB()
db_path = db_maker (ref_path="./test/Reference.fa" , db_path="./test/Reference")
msg += "PASS\t MakeBlastDB test\n"
except Exception as E:
msg += "FAIL\t MakeBlastDB test\t {}\n".format(E)
###############################################################################################
print ("Testing BlastHit")
try:
from BlastHit import BlastHit
hit_list = []
for i in range (100):
hit_list .append(BlastHit (
q_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)),
s_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)),
identity = random.uniform(0, 1),
length = random.randint(1, 100),
mis = random.randint(0, 100),
gap = random.randint(0, 100),
q_start = random.randint(0, 100),
q_end = random.randint(0, 100),
s_start = random.randint(0, 100),
s_end = random.randint(0, 100),
evalue = random.uniform(0, 1),
bscore = random.uniform(0, 1),
qseq = ''.join(random.choice(["A","T","C","G"]) for _ in range(20))))
assert len(hit_list) == 100, "Incorect number of hit generated"
msg += "PASS\t BlastHit test\n"
except Exception as E:
msg += "FAIL\t BlastHit test\t {}\n".format(E)
###############################################################################################
print ("Testing MakeBlastn")
try:
from MakeBlastn import MakeBlastn
for _ in range (50):
blast_maker = MakeBlastn (
task = random.choice(['blastn', 'blastn-short', 'dc-megablast', 'megablast', 'rmblastn']),
evalue = random.uniform(0, 1),
best_per_query_seq = random.choice([True, False]))
hits = blast_maker(query_path = "./test/query_sample.fa", db_path = db_path)
msg += "PASS\t MakeBlastn test\n"
except Exception as E:
msg += "FAIL\t MakeBlastn test\t {}\n".format(E)
print (msg)
###############################################################################################
Aucun aperçu pour ce type de fichier
# -*- coding: utf-8 -*-
"""
@package pyBlast
@brief Test function to be used with python package pytest
@copyright [GNU General Public License v2](http://www.gnu.org/licenses/gpl-2.0.html)
@author Adrien Leger - 2014
* <adrien.leger@gmail.com> <adrien.leger@inserm.fr> <adrien.leger@univ-nantes.fr>
* [Github](https://github.com/a-slide)
* [Atlantic Gene Therapies - INSERM 1089] (http://www.atlantic-gene-therapies.fr/)
"""
# Standard library packages import
import sys, os, random, string
# Third party packages import
import pytest
# Import the current working dir in the python path to allow local package imports
sys.path.append(os.getcwd())
# Start tests
def test_MakeBlastDB():
from MakeBlastDB import MakeBlastDB
db_maker = MakeBlastDB()
assert(db_maker (
ref_path="./test/Reference.fa" ,
db_path="./test/Reference"))
def test_BlastHit():
from BlastHit import BlastHit
for _ in range (100):
assert(BlastHit(
q_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)),
s_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)),
identity = random.uniform(0, 1),
length = random.randint(1, 100),
mis = random.randint(0, 100),
gap = random.randint(0, 100),
q_start = random.randint(0, 100),
q_end = random.randint(0, 100),
s_start = random.randint(0, 100),
s_end = random.randint(0, 100),
evalue = random.uniform(0, 1),
bscore = random.uniform(0, 100),
qseq = ''.join(random.choice(["A","T","C","G"]) for _ in range(20))))
def test_MakeBlastn():
from MakeBlastn import MakeBlastn
for _ in range (10):
blast_maker = MakeBlastn(
task = random.choice(['blastn', 'blastn-short', 'dc-megablast', 'megablast', 'rmblastn']),
evalue = random.uniform(0, 1),
best_per_query_seq = random.choice([True, False]))
assert(blast_maker(
query_path="./test/query_sample.fa",
db_path="./test/Reference" ))
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter