mirror of
https://github.com/openbabel/openbabel.git
synced 2025-02-25 18:55:23 -06:00
@@ -101,7 +101,7 @@ class TestToolkit(myTestCase):
|
|||||||
def testRSformaterror(self):
|
def testRSformaterror(self):
|
||||||
"""Test that invalid formats raise an error"""
|
"""Test that invalid formats raise an error"""
|
||||||
self.assertRaises(ValueError, self.toolkit.readstring, "noel", "jkjk")
|
self.assertRaises(ValueError, self.toolkit.readstring, "noel", "jkjk")
|
||||||
self.assertRaises(IOError, self.toolkit.readstring, "smi", "&*)(%)($)")
|
self.assertRaises(OSError, self.toolkit.readstring, "smi", "&*)(%)($)")
|
||||||
|
|
||||||
def testselfconversion(self):
|
def testselfconversion(self):
|
||||||
"""Test that the toolkit can eat its own dog-food."""
|
"""Test that the toolkit can eat its own dog-food."""
|
||||||
@@ -189,7 +189,7 @@ M END
|
|||||||
|
|
||||||
def testRFmissingfile(self):
|
def testRFmissingfile(self):
|
||||||
"""Test that reading from a non-existent file raises an error."""
|
"""Test that reading from a non-existent file raises an error."""
|
||||||
self.assertRaises(IOError, self.RFreaderror)
|
self.assertRaises(OSError, self.RFreaderror)
|
||||||
|
|
||||||
def RFformaterror(self):
|
def RFformaterror(self):
|
||||||
mol = getattr(self.toolkit.readfile("noel", "head.sdf"), nextmethod)()
|
mol = getattr(self.toolkit.readfile("noel", "head.sdf"), nextmethod)()
|
||||||
@@ -225,7 +225,7 @@ M END
|
|||||||
filecontents = input.readlines()[0].split("\t")[0].strip()
|
filecontents = input.readlines()[0].split("\t")[0].strip()
|
||||||
input.close()
|
input.close()
|
||||||
self.assertEqual(filecontents, test)
|
self.assertEqual(filecontents, test)
|
||||||
self.assertRaises(IOError, mol.write, "smi", "testoutput.txt")
|
self.assertRaises(OSError, mol.write, "smi", "testoutput.txt")
|
||||||
os.remove("testoutput.txt")
|
os.remove("testoutput.txt")
|
||||||
self.assertRaises(ValueError, mol.write, "noel", "testoutput.txt")
|
self.assertRaises(ValueError, mol.write, "noel", "testoutput.txt")
|
||||||
|
|
||||||
@@ -235,8 +235,8 @@ M END
|
|||||||
with self.toolkit.Outputfile("sdf", "testoutput.txt") as outputfile:
|
with self.toolkit.Outputfile("sdf", "testoutput.txt") as outputfile:
|
||||||
for mol in self.head:
|
for mol in self.head:
|
||||||
outputfile.write(mol)
|
outputfile.write(mol)
|
||||||
self.assertRaises(IOError, outputfile.write, mol)
|
self.assertRaises(OSError, outputfile.write, mol)
|
||||||
self.assertRaises(IOError, self.toolkit.Outputfile, "sdf", "testoutput.txt")
|
self.assertRaises(OSError, self.toolkit.Outputfile, "sdf", "testoutput.txt")
|
||||||
input = open("testoutput.txt", "r")
|
input = open("testoutput.txt", "r")
|
||||||
numdollar = len([x for x in input.readlines()
|
numdollar = len([x for x in input.readlines()
|
||||||
if x.rstrip() == "$$$$"])
|
if x.rstrip() == "$$$$"])
|
||||||
@@ -314,7 +314,7 @@ M END
|
|||||||
self.assertEqual(str(self.atom), test)
|
self.assertEqual(str(self.atom), test)
|
||||||
|
|
||||||
def invalidSMARTStest(self):
|
def invalidSMARTStest(self):
|
||||||
# Should raise IOError
|
# Should raise OSError
|
||||||
return self.toolkit.Smarts("[#NOEL][#NOEL]")
|
return self.toolkit.Smarts("[#NOEL][#NOEL]")
|
||||||
|
|
||||||
def testSMARTS(self):
|
def testSMARTS(self):
|
||||||
@@ -324,7 +324,7 @@ M END
|
|||||||
ans = smarts.findall(mol)
|
ans = smarts.findall(mol)
|
||||||
self.assertEqual(len(ans), 3)
|
self.assertEqual(len(ans), 3)
|
||||||
self.toolkit.ob.obErrorLog.SetOutputLevel(self.toolkit.ob.obError)
|
self.toolkit.ob.obErrorLog.SetOutputLevel(self.toolkit.ob.obError)
|
||||||
self.assertRaises(IOError, self.invalidSMARTStest)
|
self.assertRaises(OSError, self.invalidSMARTStest)
|
||||||
self.toolkit.ob.obErrorLog.SetOutputLevel(self.toolkit.ob.obWarning)
|
self.toolkit.ob.obErrorLog.SetOutputLevel(self.toolkit.ob.obWarning)
|
||||||
|
|
||||||
def testAddh(self):
|
def testAddh(self):
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ def readfile(format, filename, opt=None):
|
|||||||
if not formatok:
|
if not formatok:
|
||||||
raise ValueError("%s is not a recognised Open Babel format" % format)
|
raise ValueError("%s is not a recognised Open Babel format" % format)
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
raise IOError("No such file: '%s'" % filename)
|
raise OSError("No such file: '%s'" % filename)
|
||||||
|
|
||||||
def filereader():
|
def filereader():
|
||||||
obmol = ob.OBMol()
|
obmol = ob.OBMol()
|
||||||
@@ -206,7 +206,7 @@ def readstring(format, string, opt=None):
|
|||||||
|
|
||||||
success = obconversion.ReadString(obmol, string)
|
success = obconversion.ReadString(obmol, string)
|
||||||
if not success:
|
if not success:
|
||||||
raise IOError("Failed to convert '%s' to format '%s'" % (
|
raise OSError("Failed to convert '%s' to format '%s'" % (
|
||||||
string, format))
|
string, format))
|
||||||
return Molecule(obmol)
|
return Molecule(obmol)
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ class Outputfile(object):
|
|||||||
self.format = format
|
self.format = format
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
if not overwrite and os.path.isfile(self.filename):
|
if not overwrite and os.path.isfile(self.filename):
|
||||||
raise IOError(
|
raise OSError(
|
||||||
"%s already exists. Use 'overwrite=True' to overwrite it." %
|
"%s already exists. Use 'overwrite=True' to overwrite it." %
|
||||||
self.filename)
|
self.filename)
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ class Outputfile(object):
|
|||||||
molecule
|
molecule
|
||||||
"""
|
"""
|
||||||
if not self.filename:
|
if not self.filename:
|
||||||
raise IOError("Outputfile instance is closed.")
|
raise OSError("Outputfile instance is closed.")
|
||||||
|
|
||||||
if self.total == 0:
|
if self.total == 0:
|
||||||
self.obConversion.WriteFile(molecule.OBMol, self.filename)
|
self.obConversion.WriteFile(molecule.OBMol, self.filename)
|
||||||
@@ -554,7 +554,7 @@ class Molecule(object):
|
|||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
if not overwrite and os.path.isfile(filename):
|
if not overwrite and os.path.isfile(filename):
|
||||||
raise IOError(("%s already exists. Use 'overwrite=True' to "
|
raise OSError(("%s already exists. Use 'overwrite=True' to "
|
||||||
"overwrite it.") % filename)
|
"overwrite it.") % filename)
|
||||||
obconversion.WriteFile(self.OBMol, filename)
|
obconversion.WriteFile(self.OBMol, filename)
|
||||||
obconversion.CloseOutFile()
|
obconversion.CloseOutFile()
|
||||||
@@ -952,7 +952,7 @@ class Smarts(object):
|
|||||||
self.obsmarts = ob.OBSmartsPattern()
|
self.obsmarts = ob.OBSmartsPattern()
|
||||||
success = self.obsmarts.Init(smartspattern)
|
success = self.obsmarts.Init(smartspattern)
|
||||||
if not success:
|
if not success:
|
||||||
raise IOError("Invalid SMARTS pattern")
|
raise OSError("Invalid SMARTS pattern")
|
||||||
|
|
||||||
def findall(self, molecule):
|
def findall(self, molecule):
|
||||||
"""Find all matches of the SMARTS pattern to a particular molecule.
|
"""Find all matches of the SMARTS pattern to a particular molecule.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def find_version():
|
|||||||
if version_match:
|
if version_match:
|
||||||
return version_match.group(1)
|
return version_match.group(1)
|
||||||
raise Exception('Could not find version string in openbabel/__init__.py.')
|
raise Exception('Could not find version string in openbabel/__init__.py.')
|
||||||
except IOError:
|
except OSError:
|
||||||
raise Exception('Could not find openbabel/__init__.py.')
|
raise Exception('Could not find openbabel/__init__.py.')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ $end"""
|
|||||||
mol = pybel.readstring("smi", smi)
|
mol = pybel.readstring("smi", smi)
|
||||||
self.assertTrue(mol.OBMol.GetData(ob.StereoData))
|
self.assertTrue(mol.OBMol.GetData(ob.StereoData))
|
||||||
for smi in bad:
|
for smi in bad:
|
||||||
self.assertRaises(IOError, pybel.readstring, "smi", smi)
|
self.assertRaises(OSError, pybel.readstring, "smi", smi)
|
||||||
for smi in alsobad:
|
for smi in alsobad:
|
||||||
mol = pybel.readstring("smi", smi)
|
mol = pybel.readstring("smi", smi)
|
||||||
self.assertTrue(mol.OBMol.GetData(ob.StereoData))
|
self.assertTrue(mol.OBMol.GetData(ob.StereoData))
|
||||||
@@ -356,7 +356,7 @@ H 0.74700 0.50628 -0.64089
|
|||||||
smis = [r"\0", "&0", "=&",
|
smis = [r"\0", "&0", "=&",
|
||||||
"[H][S][S][S@S00]0[S][S@S00H](0[S@S00][S])0n"]
|
"[H][S][S][S@S00]0[S][S@S00H](0[S@S00][S])0n"]
|
||||||
for smi in smis:
|
for smi in smis:
|
||||||
self.assertRaises(IOError, pybel.readstring, "smi", smi)
|
self.assertRaises(OSError, pybel.readstring, "smi", smi)
|
||||||
|
|
||||||
smis = ["c0C[C@H](B)00O0"] # warning and stereo ignored
|
smis = ["c0C[C@H](B)00O0"] # warning and stereo ignored
|
||||||
for smi in smis:
|
for smi in smis:
|
||||||
@@ -461,7 +461,7 @@ M END
|
|||||||
data += " [C@,](Br)(Cl)(I)F C1,CC1 C%1,1CC%11 C%(1,1)CC%11"
|
data += " [C@,](Br)(Cl)(I)F C1,CC1 C%1,1CC%11 C%(1,1)CC%11"
|
||||||
data += " C=,C"
|
data += " C=,C"
|
||||||
for smi in data.split(" "):
|
for smi in data.split(" "):
|
||||||
self.assertRaises(IOError, pybel.readstring, "smi", smi)
|
self.assertRaises(OSError, pybel.readstring, "smi", smi)
|
||||||
|
|
||||||
def testOBMolAssignTotalChargeToAtoms(self):
|
def testOBMolAssignTotalChargeToAtoms(self):
|
||||||
"""Run the test cases described in the source code"""
|
"""Run the test cases described in the source code"""
|
||||||
@@ -499,7 +499,7 @@ M END
|
|||||||
mol = pybel.readstring("smi", smi)
|
mol = pybel.readstring("smi", smi)
|
||||||
self.assertEqual(charge, mol.atoms[0].formalcharge)
|
self.assertEqual(charge, mol.atoms[0].formalcharge)
|
||||||
for smi in bad:
|
for smi in bad:
|
||||||
self.assertRaises(IOError, pybel.readstring, "smi", smi)
|
self.assertRaises(OSError, pybel.readstring, "smi", smi)
|
||||||
|
|
||||||
def testReadingBenzyne(self):
|
def testReadingBenzyne(self):
|
||||||
"""Check that benzyne is read correctly"""
|
"""Check that benzyne is read correctly"""
|
||||||
@@ -544,7 +544,7 @@ M END
|
|||||||
for smi in smis:
|
for smi in smis:
|
||||||
mol = pybel.readstring("smi", smi)
|
mol = pybel.readstring("smi", smi)
|
||||||
self.assertEqual(mol.write("smi").rstrip(), smi)
|
self.assertEqual(mol.write("smi").rstrip(), smi)
|
||||||
self.assertRaises(IOError, pybel.readstring, "smi", "[11111C]")
|
self.assertRaises(OSError, pybel.readstring, "smi", "[11111C]")
|
||||||
mol = pybel.readstring("smi", "[C]")
|
mol = pybel.readstring("smi", "[C]")
|
||||||
mol.atoms[0].OBAtom.SetIsotope(65535)
|
mol.atoms[0].OBAtom.SetIsotope(65535)
|
||||||
self.assertEqual(mol.write("smi").rstrip(), "[C]")
|
self.assertEqual(mol.write("smi").rstrip(), "[C]")
|
||||||
@@ -652,7 +652,7 @@ H -0.26065 0.64232 -2.62218
|
|||||||
|
|
||||||
for smi, rt in smis:
|
for smi, rt in smis:
|
||||||
if rt==-1:
|
if rt==-1:
|
||||||
self.assertRaises(IOError, pybel.readstring, "smi", smi)
|
self.assertRaises(OSError, pybel.readstring, "smi", smi)
|
||||||
continue
|
continue
|
||||||
if rt is None:
|
if rt is None:
|
||||||
rt = smi
|
rt = smi
|
||||||
@@ -731,7 +731,7 @@ class NewReactionHandling(PythonBindings):
|
|||||||
self.assertEqual(smi, nsmi)
|
self.assertEqual(smi, nsmi)
|
||||||
badsmis = ["C>>N>O", ">>>", "C>N>O>", ">", ">N", "N>"]
|
badsmis = ["C>>N>O", ">>>", "C>N>O>", ">", ">N", "N>"]
|
||||||
for smi in badsmis:
|
for smi in badsmis:
|
||||||
self.assertRaises(IOError, pybel.readstring, "smi", smi)
|
self.assertRaises(OSError, pybel.readstring, "smi", smi)
|
||||||
|
|
||||||
def testFacade(self):
|
def testFacade(self):
|
||||||
parts = "CNO"
|
parts = "CNO"
|
||||||
|
|||||||
Reference in New Issue
Block a user