Index: test_optparse.py =================================================================== --- test_optparse.py (revision 54885) +++ test_optparse.py (working copy) @@ -7,6 +7,7 @@ # # $Id$ # +# Amended for jython by Tim Couper 20 Apr 2007 import sys import os @@ -176,7 +177,15 @@ sys.stdout = save_stdout except InterceptedError, err: - self.assert_( + # Jython: allow unicode and str + if sys.platform.startswith('java'): + # Jython: allow unicode and str + self.assert_( + type(output) in (types.StringType,types.UnicodeType), + "expected output to be an ordinary string or unicode, not %r" + % type(output)) + else: + self.assert_( type(output) is types.StringType, "expected output to be an ordinary string, not %r" % type(output)) @@ -397,6 +406,9 @@ # object, various cycles can prevent it from being GC'd in # a timely fashion. destroy() breaks the cycles to ensure stuff # can be cleaned up. + # Jython has no ref counting; ignore test + if sys.platform.startswith('java'): + return big_thing = [42] refcount = sys.getrefcount(big_thing) parser = OptionParser() @@ -795,14 +807,16 @@ (options, args) = self.assertParseOK(["-q"], {'verbose': 0}, []) - if hasattr(__builtins__, 'False'): + # Jython has no __builtin__ .. False exists + if sys.platform.startswith('java') or hasattr(__builtins__, 'False'): self.failUnless(options.verbose is False) def test_bool_true(self): (options, args) = self.assertParseOK(["-v"], {'verbose': 1}, []) - if hasattr(__builtins__, 'True'): + # Jython has no __builtin__ .. True exists + if sys.platform.startswith('java') or hasattr(__builtins__, 'True'): self.failUnless(options.verbose is True) def test_bool_flicker_on_and_off(self): @@ -1601,14 +1615,25 @@ self.parser.add_option("-l", type=long) def test_parse_num_fail(self): + if sys.platform.startswith('java'): + # Jython error msg differs + errmsg="invalid literal for __int__: " + else: + errmsg=re.compile(r"invalid literal for int().*: '?'?") self.assertRaises( _parse_num, ("", int), {}, ValueError, - re.compile(r"invalid literal for int().*: '?'?")) + errmsg) + + if sys.platform.startswith('java'): + # Jython error msg differs + errmsg="invalid literal for __long__: Ooops" + else: + errmsg=re.compile(r"invalid literal for long().*: '?0xOoops'?") self.assertRaises( _parse_num, ("0xOoops", long), {}, ValueError, - re.compile(r"invalid literal for long().*: '?0xOoops'?")) + errmsg) def test_parse_num_ok(self): self.assertEqual(_parse_num("0", int), 0)