def test_disposable():
 x = DisposableTest()
 with x:
  pass
 AreEqual(x.Called, True)
 Assert(hasattr(x, '__enter__'))
 Assert(hasattr(x, '__exit__'))
 x = DisposableTest()
 x.__enter__()
 try:
  pass
 finally:
  AreEqual(x.__exit__(None, None, None), None)
 AreEqual(x.Called, True)
 Assert(('__enter__' in dir(x)))
 Assert(('__exit__' in dir(x)))
 Assert(('__enter__' in dir(DisposableTest)))
 Assert(('__exit__' in dir(DisposableTest)))

def test_disposable ( ) : x = DisposableTest ( ) with x : pass AreEqual ( x . Called , True ) Assert ( hasattr ( x , '__enter__' ) ) Assert ( hasattr ( x , '__exit__' ) ) x = DisposableTest ( ) x . __enter__ ( ) try : pass finally : AreEqual ( x . __exit__ ( None , None , None ) , None ) AreEqual ( x . Called , True ) Assert ( ( '__enter__' in dir ( x ) ) ) Assert ( ( '__exit__' in dir ( x ) ) ) Assert ( ( '__enter__' in dir ( DisposableTest ) ) ) Assert ( ( '__exit__' in dir ( DisposableTest ) ) )
classes implementing idisposable should automatically support the with statement .