[Jython-checkins] jython: Fix regression in test_bytecodetools_jy
jeff.allen
jython-checkins at python.org
Sat Aug 10 15:19:41 EDT 2019
https://hg.python.org/jython/rev/88117c673998
changeset: 8273:88117c673998
user: Jeff Allen <ja.py at farowl.co.uk>
date: Thu Aug 08 22:34:14 2019 +0100
summary:
Fix regression in test_bytecodetools_jy
The previous method of suppressing warnings (redirect System.err) no
longer works, now that we use a java.util.logging.
files:
Lib/test/test_bytecodetools_jy.py | 18 ++++++------------
src/org/python/core/PrePy.java | 14 +++++++++-----
2 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/Lib/test/test_bytecodetools_jy.py b/Lib/test/test_bytecodetools_jy.py
--- a/Lib/test/test_bytecodetools_jy.py
+++ b/Lib/test/test_bytecodetools_jy.py
@@ -36,32 +36,26 @@
def faulty_callback(self, name, byte, klass):
raise Exception("test exception")
+
def faulty_callback2(self, name, byte, klass, bogus):
return
def test_faulty_callback(self):
- import java.lang.System as Sys
- import java.io.PrintStream as PrintStream
- import java.io.OutputStream as OutputStream
-
- class NullOutputStream(OutputStream):
- def write(self, b): pass
- def write(self, buf, offset, len): pass
-
- syserr = Sys.err
- Sys.setErr(PrintStream(NullOutputStream()))
-
tools.register(self.faulty_callback)
tools.register(self.assert_callback)
tools.register(self.faulty_callback2)
self.count=0
try:
+ # Suppress the warning otherwise produced
+ from org.python.core import Py
+ from java.util.logging import Level
+ level = Py.setLoggingLevel(Level.SEVERE)
eval("42+1")
finally:
self.assertTrue(tools.unregister(self.faulty_callback))
self.assertTrue(tools.unregister(self.faulty_callback2))
self.assertTrue(tools.unregister(self.assert_callback))
- Sys.setErr(syserr)
+ Py.setLoggingLevel(level)
self.assertEqual(self.count, 1)
diff --git a/src/org/python/core/PrePy.java b/src/org/python/core/PrePy.java
--- a/src/org/python/core/PrePy.java
+++ b/src/org/python/core/PrePy.java
@@ -130,19 +130,23 @@
* Set the level of the Jython logger "org.python" using the standard {@code java.util.logging}
* scale. For backward compatibility with the traditional "verbosity" system, make a
* corresponding setting of {@link Options#verbose}.
+ *
+ * @param newLevel to set
+ * @return previous logging level
*/
@SuppressWarnings("deprecation")
- public static void setLoggingLevel(Level newLevel) {
- Level currentLevel = getLoggingLevel();
- if (newLevel != currentLevel) {
+ public static Level setLoggingLevel(Level newLevel) {
+ Level previousLevel = getLoggingLevel();
+ if (newLevel != previousLevel) {
try {
logger.setLevel(newLevel);
- currentLevel = newLevel;
} catch (SecurityException se) {
logger.warning("A security manager prevented a change to the logging level.");
+ newLevel = previousLevel;
}
}
- savedVerbosity = Options.verbose = verbosityFromLevel(currentLevel);
+ savedVerbosity = Options.verbose = verbosityFromLevel(newLevel);
+ return previousLevel;
}
/**
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list