Skip to content
Permalink
Browse files

Merge pull request #531 from Thrameos/autocloseable

Fix for autocloseable
  • Loading branch information...
marscher committed Oct 25, 2019
2 parents bf6f8b6 + 0df4a52 commit 3ffb1e7a75402545c1d669f4bc5836b08b76b6ae
Showing with 14 additions and 3 deletions.
  1. +1 −0 doc/CHANGELOG.rst
  2. +3 −3 jpype/_jio.py
  3. +10 −0 test/jpypetest/test_closeable.py
@@ -4,6 +4,7 @@ Changelog
This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards.

- **Next version - unreleased**
- java.lang.AutoCloseable supports Python "with" statement.

- Updated getJVMVersion to work with JDK 9+.

@@ -25,12 +25,12 @@
pass


@_jcustomizer.JImplementationFor("java.io.Closeable")
@_jcustomizer.JImplementationFor("java.lang.AutoCloseable")
class _JCloseable(object):
""" Customizer for ``java.io.Closable``
""" Customizer for ``java.lang.AutoCloseable`` and ``java.io.Closeable``
This customizer adds support of the `with` operator to all Java
classes that implement Java Closable interface.
classes that implement Java AutoCloseable interface.
Example:
@@ -122,3 +122,13 @@ def testCloseableJExceptFail(self):
self.assertEqual(CloseableTest.printed, "hello 5")
self.assertTrue(CloseableTest.closed)
self.assertTrue(CloseableTest.failed)

def testCloseableAttr(self):
cls = jpype.JClass("java.io.Closeable")
self.assertTrue(hasattr(cls, '__enter__'))
self.assertTrue(hasattr(cls, '__exit__'))

def testAutoCloseableAttr(self):
cls = jpype.JClass("java.lang.AutoCloseable")
self.assertTrue(hasattr(cls, '__enter__'))
self.assertTrue(hasattr(cls, '__exit__'))

0 comments on commit 3ffb1e7

Please sign in to comment.
You can’t perform that action at this time.