Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip test requiring network access when it is not available. #42

Closed
charles-plessy opened this issue Sep 29, 2014 · 3 comments
Closed

Comments

@charles-plessy
Copy link

Dear Andreas,

for the Debian package of Pysam, we need to skip tests requiring network, since it is unavailable by design in some of our build farm. Would you like to provide such an offline facility in Pysam ?

Here is how I would do on one file (inspired by bits and pieces saw on StackOverflow).

--- a/tests/pysam_test.py
+++ b/tests/pysam_test.py
@@ -7,6 +7,7 @@ and data files located there.

 import pysam
 import unittest
+import urllib2
 import os
 import shutil
 import sys
@@ -21,6 +22,12 @@ SAMTOOLS = "samtools"
 WORKDIR = "pysam_test_work"
 DATADIR = "pysam_data"

+def internet_on():
+    try:
+        response=urllib2.urlopen('http://ftp.1000genomes.ebi.ac.uk',timeout=1)
+        return True
+    except urllib2.URLError as err: pass
+    return False

 class BasicTestBAMFetch(unittest.TestCase):

@@ -973,6 +980,8 @@ class TestHeaderFromRefs(unittest.TestCase):

 class TestHeader1000Genomes(unittest.TestCase):
     '''see issue 110'''
+    if internet_on() == False:
+        self.skipTest('Internet access required for this test')
     # bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase2b_alignment/data/NA07048/exome_alignment/NA07048.unmapped.ILLUMINA.bwa.CEU.exome.20120522_p2b.bam"
     bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase3_EX_or_LC_only_alignment/data/HG00104/alignment/HG00104.chrom11.ILLUMINA.bwa.GBR.low_coverage.20130415.bam"

However, multiple files have tests requiring the network. Is there a better solution than cut-and-paste?

Have a nice day,

Charles

@AndreasHeger
Copy link
Contributor

Hi Charles,

I have added this - will be part of the next release.

Best wishes,
Andreas

@AndreasHeger
Copy link
Contributor

Need to redo, lost changes in bricked laptop.

@AndreasHeger AndreasHeger reopened this Oct 9, 2014
@AndreasHeger
Copy link
Contributor

see SHA:ff2b0a96974847a5a16d24628941a1c69084e9a6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants