fix and test issue 3524949

This commit is contained in:
Greg Landrum
2012-05-09 03:19:30 +00:00
parent 90fff474ae
commit bbde03e9d6
4 changed files with 32 additions and 7 deletions

View File

@@ -129,6 +129,10 @@ namespace RDKit {
ROMol *SDMolSupplier::next() {
PRECONDITION(dp_inStream,"no stream");
if(df_end && d_last>=d_len){
throw FileParseException("EOF hit.");
}
// set the stream to the current position
dp_inStream->seekg(d_molpos[d_last]);

View File

@@ -52,6 +52,26 @@ int testMolSup() {
}
TEST_ASSERT(i==16);
}
{
SDMolSupplier sdsup(fname);
for(unsigned int i=0;i<16;++i){
ROMol *nmol = sdsup.next();
if (nmol) {
TEST_ASSERT(nmol->hasProp("_Name"));
TEST_ASSERT(nmol->hasProp("NCI_AIDS_Antiviral_Screen_Conclusion"));
delete nmol;
}
}
// test issue 3524949:
TEST_ASSERT(sdsup.atEnd());
bool ok=false;
try{
ROMol *mol = sdsup.next();
} catch (FileParseException &) {
ok=true;
}
TEST_ASSERT(ok);
}
{
std::ifstream strm(fname.c_str());
SDMolSupplier sdsup(&strm,false);

View File

@@ -783,7 +783,7 @@ class TestCase(unittest.TestCase):
# test parsed charges on one of the molecules
for id in chgs192.keys() :
self.failUnless(mol.GetAtomWithIdx(id).GetFormalCharge() == chgs192[id])
self.failUnlessRaises(StopIteration,lambda:sdSup.next())
sdSup.reset()
ns = [mol.GetProp("_Name") for mol in sdSup]

View File

@@ -91,15 +91,16 @@ public class SuppliersTests extends GraphMolTest {
assertEquals("78",m.getProp("_Name"));
assertEquals("78",m.getProp("NSC"));
assertEquals("6290-84-2",m.getProp("CAS_RN"));
/* The C++ code does not throw an error when iterating
* past the end, just returns null.
* So test for that */
suppl.reset();
}
@Test(expected=org.RDKit.GenericRDKitException.class)
public void test1SDSupplierEOF() {
File fileN = new File(baseTestPath, "NCI_aids.10.sdf");
SDMolSupplier suppl = new SDMolSupplier(fileN.getPath());
ROMol m;
for (int i = 0; i < 10; i++)
m = suppl.next();
assertEquals( true,suppl.atEnd() );
m = suppl.next();
assertNull("Iterate past end of list returns null", m);
}
@Test