diff --git a/tests/test_interval.py b/tests/test_interval.py index 36504ed..978b248 100644 --- a/tests/test_interval.py +++ b/tests/test_interval.py @@ -341,7 +341,7 @@ class TestIntervalTree: render(iset, "In-order insertion") class TestIntervalSpeed: - #@unittest.skip("this is slow") + @unittest.skip("this is slow") def test_interval_speed(self): import yappi import time diff --git a/tests/test_mustclose.py b/tests/test_mustclose.py index c81514c..08161a3 100644 --- a/tests/test_mustclose.py +++ b/tests/test_mustclose.py @@ -9,6 +9,7 @@ from testutil.helpers import * import sys import cStringIO +import gc err = cStringIO.StringIO() @@ -23,8 +24,22 @@ class Foo: def close(self): fprintf(err, "Closing\n") -@nilmdb.utils.must_close(errorfile = err) +@nilmdb.utils.must_close(errorfile = err, wrap_verify = True) class Bar: + def __init__(self): + fprintf(err, "Init\n") + + def __del__(self): + fprintf(err, "Deleting\n") + + def close(self): + fprintf(err, "Closing\n") + + def blah(self): + fprintf(err, "Blah\n") + +@nilmdb.utils.must_close(errorfile = err) +class Baz: pass class TestMustClose(object): @@ -34,26 +49,51 @@ class TestMustClose(object): # garbage collect the object (and call its __del__ function) # right after a "del x". + # Trigger error + err.truncate() x = Foo() del x + gc.collect() eq_(err.getvalue(), "Init\n" "error: Foo.close() wasn't called!\n" "Deleting\n") + # No error err.truncate(0) - y = Foo() y.close() del y + gc.collect() eq_(err.getvalue(), "Init\n" "Closing\n" "Deleting\n") + # Verify errors err.truncate(0) - z = Bar() + z.blah() z.close() + with assert_raises(AssertionError): + z.blah() + # Since the most recent assertion references 'z', + # we need to raise another assertion here so that + # 'z' will get properly deleted. + with assert_raises(AssertionError): + raise AssertionError() del z + gc.collect() + eq_(err.getvalue(), + "Init\n" + "Blah\n" + "Closing\n" + "Deleting\n") + + # Class with missing methods + err.truncate(0) + w = Baz() + w.close() + del w eq_(err.getvalue(), "") +