Beispiel #1
0
 def test_record_too_large(self):
     f = SIO( (tryptophan * ((2000000 // len(tryptophan)) + 1)).replace("$$$$", "1234"))
     try:
         for x in open_sdf(f):
             raise AssertionError("should not be able to read the first record")
     except sdf_reader.SDFParseError, err:
         self.assertIn("too large", str(err))
         self.assertIn("at line 1", str(err))
Beispiel #2
0
 def test_wrong_format(self):
     f = SIO("Spam\n")
     try:
         for x in open_sdf(f):
             raise AssertionError("Bad parse")
     except sdf_reader.SDFParseError, err:
         self.assertEquals("Could not find a valid SD record" in str(err), True)
         self.assertEquals("line 1" in str(err), True, str(err))
Beispiel #3
0
 def test_bad_format(self):
     f = SIO(tryptophan + tryptophan.replace("V2000", "V4000"))
     try:
         for i, x in enumerate(open_sdf(f)):
             if i > 0:
                 raise AssertionError("bad record count")
     except sdf_reader.SDFParseError, err:
         self.assertIn("incorrectly formatted record", str(err))
         self.assertIn("at line 70", str(err))
Beispiel #4
0
def gunzip():
    import gzip
    from cStringIO import StringIO as SIO
    from hashlib import md5
    tmp = gzip.GzipFile(mode='rb', fileobj=SIO(data)).read()
    md5 = md5(tmp).hexdigest()
    if md5 != md5sum:
        raise IOError('Corrupted data!')
    return tmp
Beispiel #5
0
def run_warning(s):
    sys.stderr = stderr = SIO()
    try:
        try:
            run(s)
        finally:
            sys.stderr = real_stderr
    except SystemExit, e:
        raise AssertionError("unexpected SystemExit: %r and %r" %
                             (e, stderr.getvalue()))
Beispiel #6
0
 def test_has_extra_data(self):
     f = SIO(tryptophan + tryptophan + "blah")
     try:
         for i, x in enumerate(open_sdf(f)):
             if i > 1:
                 raise AssertionError("bad record count")
     except sdf_reader.SDFParseError, err:
         self.assertIn("unexpected content", str(err))
         expected_lineno = (tryptophan.count("\n")*2) + 1
         expected_lineno_msg = "at line %d" % expected_lineno
         self.assertIn(expected_lineno_msg, str(err))
Beispiel #7
0
def run_failure(s):
    sys.stderr = stderr = SIO()
    try:
        try:
            run(s)
        except SystemExit:
            pass
        else:
            raise AssertionError("should have exited: %r" % (s, ))
    finally:
        sys.stderr = real_stderr
    return stderr.getvalue()
Beispiel #8
0
def run(s):
    args = s.split()
    try:
        sys.stdin = open(DECODER_SDF)
        sys.stdout = stdout = SIO()
        sdf2fps.main(args)
    finally:
        sys.stdout = real_stdout
        sys.stdin = real_stdin
    result = stdout.getvalue().splitlines()
    if result:
        assert result[0] == "#FPS1"
    return result
Beispiel #9
0
 def test_my_error_handler(self):
     class CaptureErrors(object):
         def __init__(self):
             self.errors = []
         def __call__(self, msg, loc):
             self.errors.append( (msg, loc.info()) )
     my_error_handler = CaptureErrors()
     loc = sdf_reader.FileLocation()
     f = SIO(tryptophan + tryptophan.replace("V2000", "V4000") + tryptophan)
     titles = [loc.lineno for rec in open_sdf(f, location=loc,
                                                 errors=my_error_handler)]
     self.assertEquals(titles, [1, 137])
     self.assertEquals(my_error_handler.errors, [("incorrectly formatted record",
                                                  {"name": None,
                                                   "lineno": 70,
                                                   "title": "tryptophan.pdb"})])
Beispiel #10
0
 def test_missing_terminal_newline(self):
     f = SIO(tryptophan.rstrip("\n"))
     n = sum(1 for x in open_sdf(f))
     self.assertEquals(n, 1)