* 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:
Noel O'Boyle
2006-11-25 09:49:50 +00:00
parent 265b48866c
commit 7caab0c0f7
4 changed files with 20 additions and 1 deletions
+7
View File
@@ -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.
+4 -1
View File
@@ -160,11 +160,14 @@ Optional&nbsp;parameters:<br>
&nbsp;&nbsp;&nbsp;overwrite&nbsp;(default&nbsp;is&nbsp;False)&nbsp;--&nbsp;if&nbsp;the&nbsp;output&nbsp;file&nbsp;already&nbsp;exists,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;should&nbsp;it&nbsp;be&nbsp;overwritten?<br>
Methods:<br>
&nbsp;&nbsp;&nbsp;<a href="#Outputfile-write">write</a>(molecule)<br>&nbsp;</tt></td></tr>
&nbsp;&nbsp;&nbsp;<a href="#Outputfile-write">write</a>(molecule)<br>
&nbsp;&nbsp;&nbsp;<a href="#Outputfile-close">close</a>()<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</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&nbsp;the&nbsp;<a href="#Outputfile">Outputfile</a>&nbsp;to&nbsp;further&nbsp;writing.</tt></dd></dl>
<dl><dt><a name="Outputfile-write"><strong>write</strong></a>(self, molecule)</dt><dd><tt>Write&nbsp;a&nbsp;molecule&nbsp;to&nbsp;the&nbsp;output&nbsp;file.<br>
&nbsp;<br>
Required&nbsp;parameters:<br>
+2
View File
@@ -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")