mirror of
https://github.com/openbabel/openbabel.git
synced 2026-08-10 04:58:04 -05:00
* scripts/python/pybel.py, testpybel.py, pybelapi.html: Added a
.close() method to the Outputfile class of Pybel. This uses the CloseOutFile() method added by Chris Morley in r1606. This is necessary to ensure that all tests pass on Windows.
This commit is contained in:
@@ -92,12 +92,19 @@ class Outputfile(object):
|
||||
Required parameters:
|
||||
molecule
|
||||
"""
|
||||
if not self.filename:
|
||||
raise IOError, "Outputfile instance is closed."
|
||||
|
||||
if self.total==0:
|
||||
self.obConversion.WriteFile(molecule.OBMol, self.filename)
|
||||
else:
|
||||
self.obConversion.Write(molecule.OBMol)
|
||||
self.total += 1
|
||||
|
||||
def close(self):
|
||||
"""Close the Outputfile to further writing."""
|
||||
self.obConversion.CloseOutFile()
|
||||
self.filename = None
|
||||
|
||||
class Molecule(object):
|
||||
"""Represent a Pybel molecule.
|
||||
|
||||
@@ -160,11 +160,14 @@ Optional parameters:<br>
|
||||
overwrite (default is False) -- if the output file already exists,<br>
|
||||
should it be overwritten?<br>
|
||||
Methods:<br>
|
||||
<a href="#Outputfile-write">write</a>(molecule)<br> </tt></td></tr>
|
||||
<a href="#Outputfile-write">write</a>(molecule)<br>
|
||||
<a href="#Outputfile-close">close</a>()<br> </tt></td></tr>
|
||||
<tr><td> </td>
|
||||
<td width="100%">Methods defined here:<br>
|
||||
<dl><dt><a name="Outputfile-__init__"><strong>__init__</strong></a>(self, format, filename, overwrite<font color="#909090">=False</font>)</dt></dl>
|
||||
|
||||
<dl><dt><a name="Outputfile-close"><strong>close</strong></a>(self)</dt><dd><tt>Close the <a href="#Outputfile">Outputfile</a> to further writing.</tt></dd></dl>
|
||||
|
||||
<dl><dt><a name="Outputfile-write"><strong>write</strong></a>(self, molecule)</dt><dd><tt>Write a molecule to the output file.<br>
|
||||
<br>
|
||||
Required parameters:<br>
|
||||
|
||||
@@ -96,6 +96,8 @@ class Test_readfile(unittest.TestCase):
|
||||
outputfile = pybel.Outputfile("smi", "testoutput.txt")
|
||||
for mol in self.mols:
|
||||
outputfile.write(mol)
|
||||
outputfile.close()
|
||||
self.assertRaises(IOError, outputfile.write, mol)
|
||||
self.assertRaises(IOError, pybel.Outputfile, "smi", "testoutput.txt")
|
||||
filecontents = open("testoutput.txt", "r").readlines()
|
||||
os.remove("testoutput.txt")
|
||||
|
||||
Reference in New Issue
Block a user