[Jython-checkins] jython: Minor improvements/corrections to console-related Java tests.
jeff.allen
jython-checkins at python.org
Sun Sep 8 23:25:50 CEST 2013
http://hg.python.org/jython/rev/0b8df72bce68
changeset: 7120:0b8df72bce68
user: Jeff Allen <ja.py at farowl.co.uk>
date: Sun Sep 08 17:58:06 2013 +0100
summary:
Minor improvements/corrections to console-related Java tests.
Re-works the Issue1972 test so it correctly ignores sys-package-mgr messages.
Comment correction only in org.python.util.jythonTest.
files:
tests/java/javatests/Issue1972.java | 29 +++++----
tests/java/org/python/util/jythonTest.java | 4 +-
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/tests/java/javatests/Issue1972.java b/tests/java/javatests/Issue1972.java
--- a/tests/java/javatests/Issue1972.java
+++ b/tests/java/javatests/Issue1972.java
@@ -20,7 +20,7 @@
import org.junit.Test;
/**
- * Tests investigating issues with readline() first raised in Jython Issue #1972. these involve
+ * Tests investigating issues with readline() first raised in Jython Issue #1972. These involve
* sub-process input and output through the console streams. Although the console streams are used,
* the JLine console handler is not engaged, as the test {@link #jythonJLineConsole()} verifies. You
* could run this as a straight JUnit test, or in various debugging configurations, including remote
@@ -48,10 +48,10 @@
static int VERBOSE = 0;
/** Lines in stdout (as regular expressions) to ignore when checking subprocess output. */
- static String[] STDOUT_IGNORE = {"^Listening for transport dt_socket"};
+ static String[] STDOUT_IGNORE = {"Listening for transport dt_socket"};
/** Lines in stderr (as regular expressions) to ignore when checking subprocess output. */
- static String[] STDERR_IGNORE = {"^Jython 2", "^\\*sys-package-mgr"};
+ static String[] STDERR_IGNORE = {"Jython 2", "\\*sys-package-mgr"};
/**
* Extra JVM options used when debugging is enabled. <code>DEBUG_PORT</code> will be substituted
@@ -475,16 +475,21 @@
// Get the escaped form of the byte buffers in the queue
List<String> results = queue.asStrings();
- // Count through the results, stopping when either results or expected strings run out
+ // Count through the results, comparing what we can't ignore to what was expected
int count = 0;
for (String r : results) {
- if (count >= expected.length) {
- break;
- } else if (!matchesAnyOf(r, toIgnore)) {
- assertEquals(message, expected[count++], r);
+ if (!beginsWithAnyOf(r, toIgnore)) {
+ if (count < expected.length) {
+ // Check the line against the expected text
+ assertEquals(message, expected[count++], r);
+ } else {
+ // Extra line will be a failure but continue to count
+ count++;
+ }
}
}
- assertEquals(message, expected.length, results.size());
+ // Check number of lines we can't ignore against the number expected
+ assertEquals(message, expected.length, count);
}
/** Compiled regular expressions for the lines to ignore (on stdout). */
@@ -515,15 +520,15 @@
}
/**
- * Compute whether a string matches any of a set of strings.
+ * Compute whether a string begins with any of a set of strings.
*
* @param s the string in question
* @param patterns to check against
* @return
*/
- private static boolean matchesAnyOf(String s, List<Pattern> patterns) {
+ private static boolean beginsWithAnyOf(String s, List<Pattern> patterns) {
for (Pattern p : patterns) {
- if (p.matcher(s).matches()) {
+ if (p.matcher(s).lookingAt()) {
return true;
}
}
diff --git a/tests/java/org/python/util/jythonTest.java b/tests/java/org/python/util/jythonTest.java
--- a/tests/java/org/python/util/jythonTest.java
+++ b/tests/java/org/python/util/jythonTest.java
@@ -31,12 +31,10 @@
private static String[] commands = {"-c", "import sys; print type(sys._jy_console)"};
/**
- * Test that the default behaviour is to provide a JLineConsole. If CALL_RUN is true, it fails
- * under Ant (or Eclipse) as the console is not then recognised to be interactive.
+ * Test that the default behaviour is to provide a JLineConsole.
*/
@Test
public void testDefaultConsole() {
- // This path only if you changed it to run manually
jython.run(commands);
Console console = Py.getConsole();
assertEquals(JLineConsole.class, console.getClass());
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list