Skip to content

Commit 29e130b

Browse files
authored
Merge pull request #25 from abradle/master
Fixes for testing without network / locally.
2 parents e36d4e2 + dbc1e5f commit 29e130b

7 files changed

Lines changed: 31 additions & 10 deletions

File tree

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ language: python
44
python:
55
- "2.6"
66
- "2.7"
7-
- "3.2"
87
- "3.3"
98
- "3.4"
109
- "3.5"

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include README.md CHANGELOG.md LICENSE.txt
22
include setup.py
3+
include mmtf/tests/testdatastore/4CUP.mmtf.gz mmtf/tests/testdatastore/4CUP.mmtf

mmtf/api/default_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
from .mmtf_writer import MMTFEncoder,TemplateEncoder
1313

1414

15+
def _internet_on(address):
16+
"""
17+
Check to see if the internet is on by pinging a set address.
18+
:param address: the IP or address to hit
19+
:return: a boolean - true if can be reached, false if not.
20+
"""
21+
try:
22+
urllib2.urlopen(address, timeout=1)
23+
return True
24+
except urllib2.URLError as err:
25+
return False
26+
1527
def write_mmtf(file_path, input_data, input_function):
1628
"""API function to write data as MMTF to a file
1729

mmtf/tests/codec_tests.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import msgpack
44
import numpy
55

6-
from mmtf import codecs,fetch,parse,parse_gzip, converters
7-
from mmtf.api.default_api import ungzip_data,write_mmtf,MMTFEncoder,MMTFDecoder
6+
from mmtf import fetch,parse,parse_gzip, converters
7+
from mmtf.api.default_api import ungzip_data,write_mmtf,MMTFDecoder,_internet_on
88
from mmtf.codecs import encoders
99
from mmtf.utils.codec_utils import parse_header
10+
from mmtf.utils.constants import BASE_URL
1011
from mmtf.codecs.default_codec import codec_dict
1112
from mmtf.codecs.decoders import numpy_decoders as decoders
1213

14+
1315
def run_all(unit_test, encoded_data, decoded_data, param, codec_id):
1416
"""Test that a given codec can work in the forward backward and round trip both ways."""
1517
try:
@@ -191,7 +193,10 @@ def test_gzip_open(self):
191193
ungzip_data(open("mmtf/tests/testdatastore/4CUP.mmtf.gz","rb").read())
192194

193195
def test_fetch(self):
194-
decoded = fetch("4CUP")
196+
if _internet_on(BASE_URL):
197+
decoded = fetch("4CUP")
198+
else:
199+
print("Warning - cannot connect to "+BASE_URL)
195200

196201

197202
def array_eq(self,array_one, array_two):
@@ -297,10 +302,13 @@ def test_round_trip(self):
297302
self.check_equal(data_in, data_rt)
298303

299304
def round_trip(self,pdb_id):
300-
data_in = fetch(pdb_id)
301-
write_mmtf(pdb_id+".mmtf", data_in, MMTFDecoder.pass_data_on)
302-
data_rt = parse(pdb_id+".mmtf")
303-
self.check_equal(data_in, data_rt)
305+
if _internet_on(BASE_URL):
306+
data_in = fetch(pdb_id)
307+
write_mmtf(pdb_id+".mmtf", data_in, MMTFDecoder.pass_data_on)
308+
data_rt = parse(pdb_id+".mmtf")
309+
self.check_equal(data_in, data_rt)
310+
else:
311+
print("Warning - cannot connect to "+BASE_URL)
304312

305313
def test_round_trip_list(self):
306314
id_list = [

mmtf/utils/codec_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import mmtf
44
import mmtf.utils.constants
55

6+
67
def parse_header(input_array):
78
"""Parse the header and return it along with the input array minus the header.
89
:param input_array the array to parse

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ipython
1+
ipython==5.4.1
22
numpy
33
nose
44
msgpack-python

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Versions should comply with PEP440. For a discussion on single-sourcing
2020
# the version across setup.py and the project code, see
2121
# https://packaging.python.org/en/latest/single_source_version.html
22-
version='1.0.5',
22+
version='1.0.6',
2323

2424
description='A decoding libary for the PDB mmtf format',
2525
long_description=long_description,

0 commit comments

Comments
 (0)