From 87c339eee31466c800ab92bb8a438067cd4c13eb Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Fri, 29 Nov 2019 11:24:54 +0100
Subject: [PATCH] test remote loading in LoadPDB/LoadMMCIF

---
 modules/io/tests/test_io_mmcif.py | 14 ++++++++++++++
 modules/io/tests/test_io_pdb.py   | 17 +++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/modules/io/tests/test_io_mmcif.py b/modules/io/tests/test_io_mmcif.py
index 8a3773b0a..cfa10798c 100644
--- a/modules/io/tests/test_io_mmcif.py
+++ b/modules/io/tests/test_io_mmcif.py
@@ -1,4 +1,5 @@
 import unittest
+import subprocess
 import ost
 from ost import *
 
@@ -249,6 +250,19 @@ class TestMMCifInfo(unittest.TestCase):
     self.assertEqual(i.GetObsoleteInfo().GetPDBID(), '1FOO')
     self.assertEqual(i.GetObsoleteInfo().GetReplacedPDBID(), '2BAR')
 
+  def test_remote_loading(self):
+
+    if subprocess.call(['ping google.com -c 1'], shell=True,
+                       stdout=subprocess.PIPE, stderr=subprocess.PIPE) != 0:
+      print("No internet connection (or wrong OS) to test remote loading in "
+            "io.LoadMMCIF: ignoring unit test")
+      return
+
+    # let's hope that crambin stays the same forever
+    crambin_pdb = io.LoadMMCIF('1crn', remote=True)
+    self.assertEqual(len(crambin_pdb.residues), 46)
+    self.assertEqual(len(crambin_pdb.atoms), 327)
+
 if __name__== '__main__':
   from ost import testutils
   testutils.RunTests()
diff --git a/modules/io/tests/test_io_pdb.py b/modules/io/tests/test_io_pdb.py
index 3ba3539dc..77a504fd8 100644
--- a/modules/io/tests/test_io_pdb.py
+++ b/modules/io/tests/test_io_pdb.py
@@ -1,5 +1,6 @@
 import unittest
 from ost import *
+import subprocess
 
 class TestPDB(unittest.TestCase):
   def setUp(self):
@@ -34,6 +35,22 @@ class TestPDB(unittest.TestCase):
     self.assertFalse(mol.BondExists(res1.FindAtom("CA"),res1.FindAtom("CB")))
     self.assertTrue(mol.BondExists(res2.FindAtom("CA"),res2.FindAtom("CB")))
     self.assertTrue(mol.BondExists(resd.FindAtom("CA"),resd.FindAtom("CB")))
+
+  def test_remote_loading(self):
+
+    if subprocess.call(['ping google.com -c 1'], shell=True,
+                       stdout=subprocess.PIPE, stderr=subprocess.PIPE) != 0:
+      print("No internet connection (or wrong OS) to test remote loading in "
+            "io.LoadPDB: ignoring unit test")
+      return
+
+    with self.assertRaises(IOError):
+      io.LoadPDB('1ake', remote=True, remote_repo="cheeseisgoodforyou")
+
+    # let's hope that crambin stays the same forever
+    crambin_pdb = io.LoadPDB('1crn', remote=True, remote_repo='pdb')
+    self.assertEqual(len(crambin_pdb.residues), 46)
+    self.assertEqual(len(crambin_pdb.atoms), 327)
     
 if __name__== '__main__':
   from ost import testutils
-- 
GitLab