Automatically download the Gck test files.

Let the Gck test module automatically download the archive from
the Drosophila Gateway Vector Collection before the tests are run.
This commit is contained in:
Damien Goutte-Gattat
2019-08-07 17:52:30 +01:00
committed by Peter Cock
parent d34cafb8f1
commit 8da81f889d
3 changed files with 47 additions and 22 deletions

3
.gitignore vendored
View File

@ -50,6 +50,9 @@ Tests/Graphics/*.eps
Tests/Graphics/*.svg
Tests/Graphics/*.png
# This file is downloaded when testing the Bio.SeqIO.GckIO module.
Tests/Gck/DGVC_GCK.zip
#Ignore the local BioSQL test settings:
Tests/biosql.ini

View File

@ -48,6 +48,10 @@ recursive-include Bio/phenotype *.py
exclude Tests/Graphics/* # Exclude test files generated by reportlab.
include Tests/Graphics/README # But include README file to make directory!
# Exclude archive of sample Gck files (automatically downloaded during
# tests but that we cannot redistribute).
exclude Tests/Gck/DGVC_GCK.zip
# e.g. from running the unit tests, or PyPy, etc
global-exclude *.pyc *.pyo *.py{} *.py-e

View File

@ -8,24 +8,20 @@
from io import BytesIO
import os.path
import shutil
import unittest
from zipfile import ZipFile
from Bio import SeqIO
from Bio import SeqIO, MissingExternalDependencyError
from Bio._py3k import urlopen, HTTPError
import requires_internet
# The Gck parser has been developed using the files of the
# Drosophila Gateway Vector Collection from Carnegie Science
# (<https://emb.carnegiescience.edu/drosophila-gateway-vector-collection>)
# as sample Gck files. We cannot redistribute those files along with
# Biopython, therefore we skip the test case by default.
#
# To test the Gck parser, download the GCK.zip archive from the URL
# above and place the files it contains under a 'Tests/Gck' directory.
@unittest.skipUnless(os.path.exists('Gck'), 'Gck sample files not available')
class TestGck(unittest.TestCase):
class TestGckWithDGVC(unittest.TestCase):
sample_data = {
'pACW': {
'file': 'Gck/pACW',
'file': 'Drosophila Gateway Vectors GCK/pACW',
'name': 'Construct:',
'id': 'Construct:',
'description': 'Construct: pACTIN-RW-SV',
@ -119,7 +115,7 @@ class TestGck(unittest.TestCase):
]
},
'pPWF': {
'file': 'Gck/pPWG',
'file': 'Drosophila Gateway Vectors GCK/pPWG',
'name': 'Construct:',
'id': 'Construct:',
'description': 'Construct: pPWF',
@ -270,10 +266,39 @@ class TestGck(unittest.TestCase):
}
}
def setUp(self):
# We are using the files of the Drosophila Gateway Vector Collection
# (<https://emb.carnegiescience.edu/drosophila-gateway-vector-collection>)
# as sample Gck files. We cannot redistribute those files along with
# Biopython, so we need to download them now for the tests to run.
if not os.path.exists('Gck/DGVC_GCK.zip'):
try:
requires_internet.check()
except MissingExternalDependencyError:
self.skipTest("Sample files missing and no Internet access")
return
try:
with urlopen('https://emb.carnegiescience.edu/sites/default/files/DGVC_GCK.zip') as response:
with open('Gck/DGVC_GCK.zip', 'wb') as f:
shutil.copyfileobj(response, f)
except HTTPError:
self.skipTest("Cannot download the sample files")
return
self.zipdata = ZipFile('Gck/DGVC_GCK.zip')
with self.zipdata.open('Drosophila Gateway Vectors GCK/pACW') as f:
# Keep one of the file in memory for the corruption tests below
self.buffer = f.read()
def tearDown(self):
self.zipdata.close()
def test_read(self):
"""Read sample files."""
for sample in self.sample_data.values():
record = SeqIO.read(sample['file'], 'gck')
f = self.zipdata.open(sample['file'])
record = SeqIO.read(f, 'gck')
self.assertEqual(sample['name'], record.name)
self.assertEqual(sample['id'], record.id)
self.assertEqual(sample['description'], record.description)
@ -290,14 +315,7 @@ class TestGck(unittest.TestCase):
self.assertEqual(exp_feat['strand'], read_feat.location.strand)
self.assertEqual(exp_feat['label'], read_feat.qualifiers['label'][0])
@unittest.skipUnless(os.path.exists('Gck'), 'Gck sample files not available')
class TestInvalidGck(unittest.TestCase):
def setUp(self):
f = open('Gck/pACW', 'rb')
self.buffer = f.read()
f.close()
f.close()
def munge_buffer(self, position, value):
mod_buffer = bytearray(self.buffer)