|
3 | 3 | import msgpack |
4 | 4 | import numpy |
5 | 5 |
|
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 |
8 | 8 | from mmtf.codecs import encoders |
9 | 9 | from mmtf.utils.codec_utils import parse_header |
| 10 | +from mmtf.utils.constants import BASE_URL |
10 | 11 | from mmtf.codecs.default_codec import codec_dict |
11 | 12 | from mmtf.codecs.decoders import numpy_decoders as decoders |
12 | 13 |
|
| 14 | + |
13 | 15 | def run_all(unit_test, encoded_data, decoded_data, param, codec_id): |
14 | 16 | """Test that a given codec can work in the forward backward and round trip both ways.""" |
15 | 17 | try: |
@@ -191,7 +193,10 @@ def test_gzip_open(self): |
191 | 193 | ungzip_data(open("mmtf/tests/testdatastore/4CUP.mmtf.gz","rb").read()) |
192 | 194 |
|
193 | 195 | 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) |
195 | 200 |
|
196 | 201 |
|
197 | 202 | def array_eq(self,array_one, array_two): |
@@ -297,10 +302,13 @@ def test_round_trip(self): |
297 | 302 | self.check_equal(data_in, data_rt) |
298 | 303 |
|
299 | 304 | 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) |
304 | 312 |
|
305 | 313 | def test_round_trip_list(self): |
306 | 314 | id_list = [ |
|
0 commit comments