From: <cg...@us...> - 2009-01-05 03:56:32
|
Revision: 5845 http://jython.svn.sourceforge.net/jython/?rev=5845&view=rev Author: cgroves Date: 2009-01-05 03:56:25 +0000 (Mon, 05 Jan 2009) Log Message: ----------- test292 - Moved to test_java_integration test293 - Importing no longer auto-imports submodules; deleted test294 - Moved to test_java_subclasses test295 - Moved to test_traceback test296 - Moved to test_import_jy test297,301,310,313,314,315,317 - Testing jythonc; deleted test298 - Moved to test_import_jy test299,300 - Tested by test_file test303 - Moved to test_java_visibility test307,308 - Moved to test_zipimport_jy test309 - Tested by test_scope test311 - Already disabled; deleted test312 - Moved to test_sax_jy test316 - Moved to test_java_integration test318 - Tested by test_syntax test319 - Moved to test_java_visibility Modified Paths: -------------- trunk/jython/Lib/test/test_import_jy.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_subclasses.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/Lib/test/test_traceback.py trunk/jython/Lib/test/test_traceback_jy.py trunk/jython/bugtests/test302.py trunk/jython/src/org/python/core/APIReader.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/core/util/importer.java trunk/jython/tests/java/org/python/tests/BeanInterface.java Added Paths: ----------- trunk/jython/Lib/test/anygui.py trunk/jython/Lib/test/import_nonexistent.py trunk/jython/Lib/test/python_home.policy trunk/jython/Lib/test/syspath_import.jar trunk/jython/Lib/test/test_sax_jy.py trunk/jython/Lib/test/test_zipimport_jy.py trunk/jython/tests/java/org/python/tests/Matryoshka.java Removed Paths: ------------- trunk/jython/bugtests/test292.policy trunk/jython/bugtests/test292.py trunk/jython/bugtests/test293.py trunk/jython/bugtests/test293p/ trunk/jython/bugtests/test294.py trunk/jython/bugtests/test294j.java trunk/jython/bugtests/test295.py trunk/jython/bugtests/test296.py trunk/jython/bugtests/test296p/ trunk/jython/bugtests/test297.py trunk/jython/bugtests/test297c.py trunk/jython/bugtests/test298.py trunk/jython/bugtests/test298m1.py trunk/jython/bugtests/test299.py trunk/jython/bugtests/test300.py trunk/jython/bugtests/test301.py trunk/jython/bugtests/test301c.py trunk/jython/bugtests/test303.py trunk/jython/bugtests/test303j.java trunk/jython/bugtests/test307.py trunk/jython/bugtests/test307foobar.template trunk/jython/bugtests/test307m.template trunk/jython/bugtests/test307p.template trunk/jython/bugtests/test308.py trunk/jython/bugtests/test308d/ trunk/jython/bugtests/test309.py trunk/jython/bugtests/test310.py trunk/jython/bugtests/test310c.py trunk/jython/bugtests/test311.py trunk/jython/bugtests/test312.py trunk/jython/bugtests/test313.py trunk/jython/bugtests/test313c.py trunk/jython/bugtests/test314.py trunk/jython/bugtests/test314c.py trunk/jython/bugtests/test315.py trunk/jython/bugtests/test315c.py trunk/jython/bugtests/test316.py trunk/jython/bugtests/test317.py trunk/jython/bugtests/test317c.py trunk/jython/bugtests/test318.py trunk/jython/bugtests/test319.py trunk/jython/bugtests/test319j.java Added: trunk/jython/Lib/test/anygui.py =================================================================== --- trunk/jython/Lib/test/anygui.py (rev 0) +++ trunk/jython/Lib/test/anygui.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -0,0 +1,40 @@ +'''Used by test_import_jy/test_getattr_module''' +import sys + +class anygui: + __all__ = ['Window'] # Etc... + + def __init__(self): + self.__backend = None + self.__backends = ['msw', 'x', 'mac', 'wx', 'tk', 'java'] + + def __try_to_get(self, modulename): + import imp + try: + module = imp.find_module(modulename) + except (IOError, ImportError, AttributeError, AssertionError): + return None + else: + return module + + def __import_backend(self, wishlist): + candidates = self.__backends[:] + for wish in wishlist: + if wish in candidates: + candidates.remove(wish) + else: + wishlist.remove(wish) + candidates = wishlist + candidates + + for name in candidates: + backend = self.__try_to_get('%sgui' % name) + if not backend: + raise Exception, 'not able to import any GUI backends' + self.__backend = backend + + def __getattr__(self, name): + if not self.__backend: + self.__import_backend(self.__dict__.get('wishlist', [])) + return self.__backend.__dict__[name] + +sys.modules[__name__] = anygui() Added: trunk/jython/Lib/test/import_nonexistent.py =================================================================== --- trunk/jython/Lib/test/import_nonexistent.py (rev 0) +++ trunk/jython/Lib/test/import_nonexistent.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -0,0 +1,7 @@ +try: + import nonexistent_module +except ImportError: + pass # This should cause an import error, but as there's a security manager in place it hasn't + # always done so +else: + raise Error("Should've caused an import error!") Added: trunk/jython/Lib/test/python_home.policy =================================================================== --- trunk/jython/Lib/test/python_home.policy (rev 0) +++ trunk/jython/Lib/test/python_home.policy 2009-01-05 03:56:25 UTC (rev 5845) @@ -0,0 +1,5 @@ +grant codeBase "file:${python.home}/-" { + permission java.util.PropertyPermission "*", "read,write"; + permission java.io.FilePermission "<<ALL FILES>>", "read,write"; +}; + Added: trunk/jython/Lib/test/syspath_import.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/syspath_import.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/jython/Lib/test/test_import_jy.py =================================================================== --- trunk/jython/Lib/test/test_import_jy.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/Lib/test/test_import_jy.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -89,8 +89,14 @@ # Again ensure we didn't recompile self.assertEquals(bytecode, read(init_compiled), 'bytecode was recompiled') + def test_corrupt_bytecode(self): + f = open("empty$py.class", "w") + f.close() + self.assertRaises(ImportError, __import__, "empty") + f = open("empty.py", "w") + f.close() + self.assertRaises(ImportError, __import__, "empty") - class OverrideBuiltinsImportTestCase(unittest.TestCase): def test_override(self): tests = [ @@ -136,7 +142,15 @@ (None, '__builtin__', ('', '', 6))) self.assertEqual(imp.find_module('imp'), (None, 'imp', ('', '', 6))) + def test_getattr_module(self): + '''Replacing __getattr__ in a class shouldn't lead to calls to __getitem__ + http://bugs.jython.org/issue438108''' + from test import anygui + # causes a stack overflow if the bug occurs + self.assertRaises(Exception, getattr, anygui, 'abc') + + def test_main(): test_support.run_unittest(MislabeledImportTestCase, OverrideBuiltinsImportTestCase, Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,5 +1,6 @@ import os import unittest +import subprocess import sys import re @@ -279,6 +280,7 @@ def test_list_delegation(self): for c in ArrayList, Vector: a = c() + self.assertRaises(IndexError, a.__getitem__, 0) a.add("blah") self.assertTrue("blah" in a) self.assertEquals(1, len(a)) @@ -318,6 +320,14 @@ for i in v: pass +class SecurityManagerTest(unittest.TestCase): + def test_nonexistent_import_with_security(self): + policy = test_support.findfile("python_home.policy") + script = test_support.findfile("import_nonexistent.py") + self.assertEquals(subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", + "-J-Djava.security.manager", "-J-Djava.security.policy=%s" % policy, script]), + 0) + def test_main(): test_support.run_unittest(InstantiationTest, BeanTest, @@ -331,7 +341,7 @@ BigDecimalTest, JavaStringTest, JavaDelegationTest, - ) + SecurityManagerTest) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_java_subclasses.py =================================================================== --- trunk/jython/Lib/test/test_java_subclasses.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -12,7 +12,7 @@ from java.awt import Color, Component, Dimension, Rectangle from javax.swing.table import AbstractTableModel -from org.python.tests import Callbacker +from org.python.tests import BeanInterface, Callbacker class InterfaceTest(unittest.TestCase): def test_java_calling_python_interface_implementation(self): @@ -146,7 +146,34 @@ ht.put("a", fv) self.failUnless(fv is ht.get("a")) + def test_proxy_generates_protected_methods(self): + """Jython proxies should generate methods for protected methods on their superclasses + Tests for bug #416871""" + output = [] + class RegularBean(BeanInterface): + def __init__(self): + output.append("init") + + def getName(self): + output.append("getName") + class FinalizingBean(RegularBean): + def finalize(self): + pass + def clone(self): + return self.__class__() + + for a in FinalizingBean(), RegularBean(): + self.assertEquals("init", output.pop()) + a.getName() + self.assertEquals("getName", output.pop()) + aa = a.clone() + if isinstance(a, FinalizingBean): + self.assertEquals("init", output.pop()) + aa.name + self.assertEquals("getName", output.pop()) + + """ public abstract class Abstract { public Abstract() { Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -5,8 +5,8 @@ from test import test_support from java.lang import Byte, Class from java.util import HashMap, Observable, Observer -from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, OnlySubclassable, - OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) +from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, Matryoshka, + OnlySubclassable, OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): @@ -131,6 +131,17 @@ '''Bug #222847 - Can't access public member of package private base class''' self.assertEquals("hi", HiddenSuper().hi()) + def test_nested_classes(self): + """Test deeply nested classes + + Bug #440660 - using nested java cls @ level >2 fails""" + + Matryoshka.Outermost.Middle.Innermost + + def test_inner_class_identity(self): + """Bug #452947 - Class of innerclass inst <> innerclass""" + self.assertEquals(id(Matryoshka.Outermost), id(Matryoshka.makeOutermost().__class__)) + class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): self.assertFalse(HashMap.isInterface(), @@ -212,7 +223,7 @@ test_support.run_unittest(VisibilityTest, JavaClassTest, CoercionTest, -# RespectJavaAccessibilityTest, + RespectJavaAccessibilityTest, ClassloaderTest) if __name__ == "__main__": Added: trunk/jython/Lib/test/test_sax_jy.py =================================================================== --- trunk/jython/Lib/test/test_sax_jy.py (rev 0) +++ trunk/jython/Lib/test/test_sax_jy.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -0,0 +1,50 @@ +import sys +import StringIO +import unittest + +from xml.sax import saxutils +from xml.sax import make_parser +from xml.sax.handler import feature_namespaces + +from test import test_support + +file = StringIO.StringIO("""<collection> + <comic title="Sandman" number='62'> + <writer>Neil Gaiman</writer> + <penciller pages='1-9,18-24'>Glyn Dillon</penciller> + <penciller pages="10-17">Charles Vess</penciller> + </comic> + <comic title="Shade, the Changing Man" number="7"> + <writer>Peter Milligan</writer> + <penciller>Chris Bachalo</penciller> + </comic> +</collection>""") + +class FindIssue(saxutils.DefaultHandler): + def __init__(self, title, number): + self.search_title, self.search_number = title, number + self.match = 0 + + def startElement(self,name,attrs): + global match + if name != 'comic' : return + + title = attrs.get('title', None) + number = attrs.get('number',None) + if title == self.search_title and number == self.search_number: + self.match += 1 + +class SimpleSaxTest(unittest.TestCase): + def test_find_issue(self): + parser = make_parser() + parser.setFeature(feature_namespaces,0) + dh = FindIssue('Sandman', '62') + parser.setContentHandler(dh) + parser.parse(file) + self.assertEquals(1, dh.match) +def test_main(): + test_support.run_unittest(SimpleSaxTest) + +if __name__ == "__main__": + test_main() + Modified: trunk/jython/Lib/test/test_traceback.py =================================================================== --- trunk/jython/Lib/test/test_traceback.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/Lib/test/test_traceback.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -158,7 +158,6 @@ err = traceback.format_exception_only(None, None) self.assertEqual(err, ['None\n']) - def test_main(): run_unittest(TracebackCases) Modified: trunk/jython/Lib/test/test_traceback_jy.py =================================================================== --- trunk/jython/Lib/test/test_traceback_jy.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/Lib/test/test_traceback_jy.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -46,7 +46,12 @@ else: self.fail('Expected Exception') + def test_extract_stack(self): + # http://bugs.jython.org/issue437809 + traceback.extract_stack() + + try: raise Exception('foo') except Exception: Added: trunk/jython/Lib/test/test_zipimport_jy.py =================================================================== --- trunk/jython/Lib/test/test_zipimport_jy.py (rev 0) +++ trunk/jython/Lib/test/test_zipimport_jy.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -0,0 +1,31 @@ +import unittest +import sys + +from test import test_support + +class SyspathZipimportTest(unittest.TestCase): + def setUp(self): + self.orig_path = sys.path + sys.path.insert(0, test_support.findfile("syspath_import.jar")) + + def tearDown(self): + sys.path = self.orig_path + + def test_load_class_from_syspath_zip(self): + from syspathonly import Syspath + self.assertEquals(Syspath.staticCall(), "result") + + def test_load_pkg_from_syspath(self): + import syspathpkg + self.assertEquals(syspathpkg.__name__, 'syspathpkg') + self.assert_('syspath_import.jar' in syspathpkg.__file__) + from syspathpkg import module + self.assertEquals(module.__name__, 'syspathpkg.module') + +def test_main(): + test_support.run_unittest(SyspathZipimportTest) + +if __name__ == "__main__": + test_main() + + Deleted: trunk/jython/bugtests/test292.policy =================================================================== --- trunk/jython/bugtests/test292.policy 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test292.policy 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,11 +0,0 @@ - -grant codeBase "file:./classes/-" { - permission java.util.PropertyPermission "*", "read,write"; - permission java.io.FilePermission "<<ALL FILES>>", "read,write"; -}; - -grant codeBase "file:${python.home}/-" { - permission java.util.PropertyPermission "*", "read,write"; - permission java.io.FilePermission "<<ALL FILES>>", "read,write"; -}; - Deleted: trunk/jython/bugtests/test292.py =================================================================== --- trunk/jython/bugtests/test292.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test292.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,16 +0,0 @@ -""" -Test sys.path import when a security profile prevents -creating classloaders. -""" - -import support, java - -support.compileJava("classes/test292j.java") - -home = java.lang.System.getProperty("python.home") -cmd = """\ --Djava.security.manager -Djava.security.policy=test292.policy \ --Dpython.home=%s test292j""" % home - -support.runJava(cmd) - Deleted: trunk/jython/bugtests/test293.py =================================================================== --- trunk/jython/bugtests/test293.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test293.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,13 +0,0 @@ -""" -Test lost syntax error when auto importing submodules. -""" - -import support - -import test293p -try: - test293p.submod.func() -except SyntaxError: - pass -else: - raise support.TestError('should raise a syntax error') Deleted: trunk/jython/bugtests/test294.py =================================================================== --- trunk/jython/bugtests/test294.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test294.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,48 +0,0 @@ -""" -[ #416871 ] proxy fails to have all needed methods -""" - -import support - -support.compileJava('test294j.java') - -import test294j - - -class PyTestA(test294j): - def __init__(self): - output.append( "inited") - def doStart(self): - output.append( "started") - def doEnd(self): - output.append( "completed") - def finalize(self): - pass - def clone(self): - return self.__class__() - -class PyTestB(test294j): - def __init__(self): - output.append( "inited") - def doStart(self): - output.append( "started") - def doEnd(self): - output.append( "completed") - -output = [] - -a = PyTestA() -a.doStart() -aa = a.clone() -aa.doStart() - -assert output == ['inited', 'started', 'inited', 'started'] - -output = [] - -a = PyTestB() -a.doStart() -aa = a.clone() -aa.doStart() - -assert output == ['inited', 'started', 'started'] Deleted: trunk/jython/bugtests/test294j.java =================================================================== --- trunk/jython/bugtests/test294j.java 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test294j.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,10 +0,0 @@ -/** - * Just a simple interface to demonstrate how subclassing - * from Jython breaks because of the two protected - * methods 'finalize' and 'clone'. - */ -public interface test294j extends Cloneable { - public void doStart(); - public void doEnd(); -} - Deleted: trunk/jython/bugtests/test295.py =================================================================== --- trunk/jython/bugtests/test295.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test295.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,9 +0,0 @@ -""" -[ #437809 ] traceback error -""" - -import support - -import traceback -traceback.extract_stack() - Deleted: trunk/jython/bugtests/test296.py =================================================================== --- trunk/jython/bugtests/test296.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test296.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,15 +0,0 @@ -""" -[ #438108 ] __getitem__ called when it shouldn't? -""" - -import support -import java - -import test296p -try: - print test296p.abc -except java.lang.StackOverflowError: - raise support.TestError("Shouldn't raise a Stack overflow") -except Exception: - pass - Deleted: trunk/jython/bugtests/test297.py =================================================================== --- trunk/jython/bugtests/test297.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test297.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test297c.py", output="test297.err") - -if support.grep("jpywork/test297c.java", - r'TestFactory extends .*HTMLFactory', count=1) != 1: - raise support.TestError('Subclassing an inner class should be possible') Deleted: trunk/jython/bugtests/test297c.py =================================================================== --- trunk/jython/bugtests/test297c.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test297c.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,23 +0,0 @@ -from javax.swing.text.html import HTMLEditorKit, FormView - -class TestEditorKit(HTMLEditorKit): - def getViewFactory(self): - return self.TestFactory() - - class TestFactory(HTMLEditorKit.HTMLFactory): - def create(self,e): - o = e.getAttributes().getAttribute(StyleConstants.NameAttribute) - if o == HTML.Tag.INPUT: - return TestFormView(e) - return HTMLEditorKit.HTMLFactory.create(self,e) - -class TestFormView(FormView): - def __init__(self,e): - FormView.__init__(self,e) - - def test(self): - print 'hello' - - def actionPerformed(self,e): - self.test() - Deleted: trunk/jython/bugtests/test298.py =================================================================== --- trunk/jython/bugtests/test298.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test298.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,22 +0,0 @@ -""" -Test a obviously corrupt $py.class file. -""" - -import support -import java - -f = open("test298m1.py", "w") -f.close() - -f = open("test298m1$py.class", "w") -f.close() - -try: - import test298m1 -except ImportError, e: - pass -except java.lang.ArrayIndexOutOfBoundsException: - raise support.TestWarning('Should not throw an ArratIndexOutOfBound') -else: - raise support.TestError('Should throw an import error') - Deleted: trunk/jython/bugtests/test299.py =================================================================== --- trunk/jython/bugtests/test299.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test299.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,24 +0,0 @@ -""" -Test that open append position filepointer at the end -""" - -import support - -s1 = "abcdefghijklmnopqrstuvwxyz" -s2 = "0123456789" -f = open("test299.out", "wb") -f.write(s1) -f.close() -f = open("test299.out", "ab") -f.write(s2) -f.close() - -f = open("test299.out", "rb") -res = f.read() -f.close() - -if res != s1 + s2: - raise support.TestError('File did not append correctly') - - - Deleted: trunk/jython/bugtests/test300.py =================================================================== --- trunk/jython/bugtests/test300.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test300.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,39 +0,0 @@ -""" -test of double seek -""" - -import support - -s1 = "abcdefghijklmnopqrstuvwxyz" -s2 = "0123456789" -f = open("test299.out", "wb") -f.write(s1) -f.close() - -def verify(pos, res): - #print pos, res - if pos != res: - raise support.TestError, "Wrong filepos #1 (%d, %d)" % (pos, res) - - -f = open("test299.out", "rb") -f.read() -verify(f.tell(), 26) -f.seek(-10, 1) -verify(f.tell(), 16) -f.seek(-10, 1) -verify(f.tell(), 6) -f.seek(-1, 1) -verify(f.tell(), 5) -f.seek(-1, 1) -verify(f.tell(), 4) -f.close() - -#raise support.TestWarning('A test of TestWarning. It is not an error') - - - - - - - Deleted: trunk/jython/bugtests/test301.py =================================================================== --- trunk/jython/bugtests/test301.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test301.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,14 +0,0 @@ -""" -[ #434324 ] jythonc -A and dead java vars -""" - -import support - -support.compileJava("classes/test301p/B.java") -support.compileJava("classes/test301p/A.java") -support.compileJPythonc("test301c.py", jar="test301.jar", core=1, - addpackages="test301p", - output="test301.err") - -support.runJava("test301c", classpath="test301.jar", output="test301c.err") - Deleted: trunk/jython/bugtests/test301c.py =================================================================== --- trunk/jython/bugtests/test301c.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test301c.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,9 +0,0 @@ - -import test301p - -class test301c(test301p.A): - pass - -#print test301c() -#print test301p.A() - Modified: trunk/jython/bugtests/test302.py =================================================================== --- trunk/jython/bugtests/test302.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test302.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -2,16 +2,13 @@ In bug #439688 the value 0x99 does not survive the JavaCC parser. """ -import support - +import sys +print sys.defaultencoding f = open("test302s.py", "wb") f.write('v = "\x99"\n') f.close() -try: - import test302s -except SyntaxError: - raise support.TestError('Importing a file with str byte > 128 should not raise a Syntaxerror') +import test302s f = open("test302.out", "w") f.write("\x99") @@ -20,6 +17,4 @@ from java.io import FileInputStream, InputStreamReader readval = InputStreamReader(FileInputStream("test302.out"), 'ISO-8859-1').read() -if ord(test302s.v) != readval: - raise support.TestError("Module source was not decoded correctly %x %x" % - (ord(test302s.v), readval)) +print ord(test302s.v) == readval Deleted: trunk/jython/bugtests/test303.py =================================================================== --- trunk/jython/bugtests/test303.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test303.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,10 +0,0 @@ -""" -Test deeply nested classes -[ #440660 ] using nested java cls @ level >2 fails -""" - -import support -support.compileJava("test303j.java") - -import test303j.A -import test303j.A.B Deleted: trunk/jython/bugtests/test303j.java =================================================================== --- trunk/jython/bugtests/test303j.java 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test303j.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,10 +0,0 @@ -public class test303j { - public static class A { - public static class B { - public static class C { - } - } - } -} - - Deleted: trunk/jython/bugtests/test307.py =================================================================== --- trunk/jython/bugtests/test307.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test307.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,42 +0,0 @@ -""" -Test import of modules and packages from sys.path zipfile. -""" - -import support -import zipfile, time -from java.io import File - - -def addZipEntry(zip, name, templateName): - template = open('test307%s.template' % templateName) - entry = zipfile.ZipInfo() - entry.filename = name - entry.date_time = time.gmtime(time.time()) - zip.writestr(entry, template.read()) - template.close() - -zip = zipfile.ZipFile("test307.zip", "w") - -addZipEntry(zip, 'test307m.py', 'm') -addZipEntry(zip, 'test307p/__init__.py', 'p') -addZipEntry(zip, "foo/bar/foobar.py", "foobar") - -zip.close() - -import sys -sys.path.append("test307.zip") - -import test307m -assert test307m.__name__ == "test307m" -assert "test307.zip" in test307m.__file__ -import test307p - -sys.path.pop() -del test307p, test307m -del sys.modules['test307p'], sys.modules['test307m'] - -import java -java.lang.System.gc() -time.sleep(4) - - Deleted: trunk/jython/bugtests/test307foobar.template =================================================================== --- trunk/jython/bugtests/test307foobar.template 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test307foobar.template 2009-01-05 03:56:25 UTC (rev 5845) @@ -1 +0,0 @@ -assert __name__ == 'test307p.foobar', "__name__ should've been test307p.foobar but was %s" % __name__ Deleted: trunk/jython/bugtests/test307m.template =================================================================== --- trunk/jython/bugtests/test307m.template 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test307m.template 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,4 +0,0 @@ -assert __name__ == 'test307m', " __name__ should've been test307m but was %s" % __name__ -from java.io import File -expected = "test307.zip%stest307m.py" % File.separator -assert expected in __file__, "%s should've been in __file__ but was %s" % (expected, __file__) Deleted: trunk/jython/bugtests/test307p.template =================================================================== --- trunk/jython/bugtests/test307p.template 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test307p.template 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,7 +0,0 @@ -assert __name__ == 'test307p', " __name__ should've been test307p but was %s" % __name__ - -#compare("__file__", __file__, "test307p/__init__.py") -#compare("__path__", __path__, ["test307.zip/test307p"]) -#import test307m -__path__.append("test307.zip/foo/bar") -import foobar Deleted: trunk/jython/bugtests/test308.py =================================================================== --- trunk/jython/bugtests/test308.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test308.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,32 +0,0 @@ -""" -Test import of java class from sys.path zipfile. -""" - -import support -import zipfile, time - -support.compileJava("test308d/test308j.java") - -def addZipEntry(zip, name, data): - entry = zipfile.ZipInfo() - entry.filename = name - entry.date_time = time.gmtime(time.time()) - zip.writestr(entry, data) - - -zip = zipfile.ZipFile("test308.zip", "w", zipfile.ZIP_DEFLATED) - -addZipEntry(zip, "test308m.py", """ -import test308j -assert test308j().foo() == "bar" -""") - -zip.write("test308d/test308j.class", "test308j.class") - -zip.close() - -import sys -sys.path.append("test308.zip") - -import test308m - Deleted: trunk/jython/bugtests/test309.py =================================================================== --- trunk/jython/bugtests/test309.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test309.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,13 +0,0 @@ -""" -[ #444292 ] local var binding overrides local import -""" - -import support - -def foo(pickle): - assert pickle == 1 - import pickle - assert pickle != 1 - -foo(1) - Deleted: trunk/jython/bugtests/test310.py =================================================================== --- trunk/jython/bugtests/test310.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test310.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,10 +0,0 @@ -""" -[ #444292 ] local var binding overrides local import with jythonc -""" - -import support - -support.compileJPythonc("test310c.py", output="test310.err", - jar="test310.jar", core=1) -support.runJava("test310c", classpath="test310.jar") - Deleted: trunk/jython/bugtests/test310c.py =================================================================== --- trunk/jython/bugtests/test310c.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test310c.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,13 +0,0 @@ -""" -[ #444292 ] local var binding overrides local import -""" - -import support - -def foo(pickle): - assert pickle == 1 - import pickle - assert pickle != 1 - -foo(1) - Deleted: trunk/jython/bugtests/test311.py =================================================================== --- trunk/jython/bugtests/test311.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test311.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,22 +0,0 @@ -""" -Test DST for time.mktime -""" - -import support -import time - -def check(tup, facit): - #print tup, long(time.mktime(tup)), facit, (long(time.mktime(tup))-facit) - assert time.mktime(tup) == facit - -# These tests fail for CPython also. - -''' -check((1998, 6, 13, 0, 0, 0, 0, 0, 0), 897692400) -check((1998, 6, 13, 0, 0, 0, 0, 0, -1), 897688800) -check((1998, 6, 13, 0, 0, 0, 0, 0, 0), 897692400) -check((1998, 6, 13, 0, 0, 0, 0, 0, 1), 897688800) -check((1998, 1, 13, 0, 0, 0, 0, 0, -1), 884646000) -check((1998, 1, 13, 0, 0, 0, 0, 0, 0), 884646000) -check((1998, 1, 13, 0, 0, 0, 0, 0, 1), 884642400) -''' Deleted: trunk/jython/bugtests/test312.py =================================================================== --- trunk/jython/bugtests/test312.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test312.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,47 +0,0 @@ -""" -Simple test of xml. -""" - -import support -import sys, StringIO - -from xml.sax import saxutils -from xml.sax import make_parser -from xml.sax.handler import feature_namespaces - -#print sys.modules - -file = StringIO.StringIO("""<collection> - <comic title="Sandman" number='62'> - <writer>Neil Gaiman</writer> - <penciller pages='1-9,18-24'>Glyn Dillon</penciller> - <penciller pages="10-17">Charles Vess</penciller> - </comic> - <comic title="Shade, the Changing Man" number="7"> - <writer>Peter Milligan</writer> - <penciller>Chris Bachalo</penciller> - </comic> -</collection>""") - -class FindIssue(saxutils.DefaultHandler): - def __init__(self, title, number): - self.search_title, self.search_number = title, number - - def startElement(self,name,attrs): - global match - if name != 'comic' : return - - title = attrs.get('title', None) - number = attrs.get('number',None) - if title == self.search_title and number == self.search_number: - match += 1 - -parser = make_parser() -parser.setFeature(feature_namespaces,0) -dh = FindIssue('Sandman', '62') -parser.setContentHandler(dh) - -match = 0 -parser.parse(file) -assert match == 1 - Deleted: trunk/jython/bugtests/test313.py =================================================================== --- trunk/jython/bugtests/test313.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test313.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,10 +0,0 @@ -""" -Jythonc test of xml -""" - -import support - -support.compileJPythonc("test313c.py", output="test313.err", - jar="test313.jar", core=1) -support.runJava("test313c", classpath="test313.jar") - Deleted: trunk/jython/bugtests/test313c.py =================================================================== --- trunk/jython/bugtests/test313c.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test313c.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,46 +0,0 @@ - -import sys, StringIO - -from xml.sax import saxutils -from xml.sax import make_parser -from xml.sax.handler import feature_namespaces - -def dummy_jythonc(): - import xml.sax.drivers2.drv_xmlproc - import encodings.utf_16_be - import dumbdbm - -file = StringIO.StringIO("""<collection> - <comic title="Sandman" number='62'> - <writer>Neil Gaiman</writer> - <penciller pages='1-9,18-24'>Glyn Dillon</penciller> - <penciller pages="10-17">Charles Vess</penciller> - </comic> - <comic title="Shade, the Changing Man" number="7"> - <writer>Peter Milligan</writer> - <penciller>Chris Bachalo</penciller> - </comic> -</collection>""") - -class FindIssue(saxutils.DefaultHandler): - def __init__(self, title, number): - self.search_title, self.search_number = title, number - - def startElement(self,name,attrs): - global match - if name != 'comic' : return - - title = attrs.get('title', None) - number = attrs.get('number',None) - if title == self.search_title and number == self.search_number: - match += 1 - -parser = make_parser() -parser.setFeature(feature_namespaces,0) -dh = FindIssue('Sandman', '62') -parser.setContentHandler(dh) - -match = 0 -parser.parse(file) -assert match == 1 - Deleted: trunk/jython/bugtests/test314.py =================================================================== --- trunk/jython/bugtests/test314.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test314.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,19 +0,0 @@ -""" -[ #448485 ] Tuple unpacking raises KeyError -""" - -import support - -import string -s = "elem1 elem2" -try: - (a, b, c) = string.split(s) -except ValueError: - pass -else: - print support.TestError("Should raise a ValueError") - -support.compileJPythonc("test314c.py", output="test314.err", - jar="test314.jar", core=1) -support.runJava("test314c", classpath="test314.jar") - Deleted: trunk/jython/bugtests/test314c.py =================================================================== --- trunk/jython/bugtests/test314c.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test314c.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,13 +0,0 @@ - -import string -s = "elem1 elem2" -try: - (a, b, c) = string.split(s) - (d, e, f) = string.split(s) - pass -except ValueError: - pass -else: - print support.TestError("Should raise a ValueError") - - Deleted: trunk/jython/bugtests/test315.py =================================================================== --- trunk/jython/bugtests/test315.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test315.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,11 +0,0 @@ -""" -Basic test, just raises an TestError -""" - -import support -support.compileJPythonc("test315c.py", output="test315.err", - jar="test315.jar", core=1) -support.runJava("test315c", classpath="test315.jar") - - - Deleted: trunk/jython/bugtests/test315c.py =================================================================== --- trunk/jython/bugtests/test315c.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test315c.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,2 +0,0 @@ - -"abc".encode("ASCII") Deleted: trunk/jython/bugtests/test316.py =================================================================== --- trunk/jython/bugtests/test316.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test316.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,14 +0,0 @@ -""" -[ #449316 ] ArrayList()[0] should raise IndexError -""" - -import support - -from java.util import ArrayList -al = ArrayList() -try: - foo = al[0] -except KeyError: - pass -else: - raise support.TestError("Should raise a KeyError") Deleted: trunk/jython/bugtests/test317.py =================================================================== --- trunk/jython/bugtests/test317.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test317.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,11 +0,0 @@ -""" -[ #448485 ] Tuple unpacking raises KeyError -""" - -import support -support.compileJPythonc("test317c.py", output="test317.err", - jar="test317.jar", core=1) -support.runJava("test317c", classpath="test317.jar") - - - Deleted: trunk/jython/bugtests/test317c.py =================================================================== --- trunk/jython/bugtests/test317c.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test317c.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,7 +0,0 @@ - -import string -try: - (a, b, c) = string.split("elem1 elem2") -except ValueError: - pass - Deleted: trunk/jython/bugtests/test318.py =================================================================== --- trunk/jython/bugtests/test318.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test318.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,14 +0,0 @@ -""" -Test against AIOOB exceptions. -""" - -import support - -def go2( a, b ): - pass - -try: - go2( 1, 2, 3 ) -except TypeError: - pass - Deleted: trunk/jython/bugtests/test319.py =================================================================== --- trunk/jython/bugtests/test319.py 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test319.py 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,18 +0,0 @@ -""" -Test class identity for inner classes -[ #452947 ] Class of innerclass inst <> innerclas -""" - -import support - -support.compileJava('test319j.java') - -import test319j - -id1 = id(test319j.inner) -id2 = id(test319j.mkinner().__class__) - -if id1 != id2: - print "innerclass different", test319j.inner, test319j.mkinner().__class__ - raise support.TestWarning("innerclass different %s %s" % ( - test319j.inner, test319j.mkinner().__class__)) Deleted: trunk/jython/bugtests/test319j.java =================================================================== --- trunk/jython/bugtests/test319j.java 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/bugtests/test319j.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,9 +0,0 @@ - -public class test319j { - public static class inner { } - - public static inner mkinner() { - return new inner(); - } -} - Modified: trunk/jython/src/org/python/core/APIReader.java =================================================================== --- trunk/jython/src/org/python/core/APIReader.java 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/src/org/python/core/APIReader.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -4,22 +4,19 @@ */ package org.python.core; +import java.io.IOException; + import org.python.objectweb.asm.AnnotationVisitor; import org.python.objectweb.asm.ClassReader; import org.python.objectweb.asm.commons.EmptyVisitor; -import java.io.InputStream; -import java.io.IOException; - /** - * This class reads a classfile from a byte array and pulls out the value of - * the class annotation for APIVersion, which can then be retrieved by a call - * to getVersion(). + * This class reads a classfile from a byte array and pulls out the value of the class annotation + * for APIVersion, which can then be retrieved by a call to getVersion(). * - * Hopefully the use of ClassReader in this implementation is not too - * expensive. I suspect it is not since EmptyVisitor is just a bag of empty - * methods so shouldn't cost too much. If it turns out to cost too much, we - * will want to implement a special purpose ClassReader that only reads out the + * Hopefully the use of ClassReader in this implementation is not too expensive. I suspect it is not + * since EmptyVisitor is just a bag of empty methods so shouldn't cost too much. If it turns out to + * cost too much, we will want to implement a special purpose ClassReader that only reads out the * APIVersion annotation I think. */ public class APIReader extends EmptyVisitor { @@ -28,17 +25,29 @@ private int version = -1; + /** + * Reads the classfile bytecode in data and to extract the version. + * @throws IOException - if the classfile is malformed. + */ public APIReader(byte[] data) throws IOException { - ClassReader r = new ClassReader(data); - r.accept(this, 0); + ClassReader r; + try { + r = new ClassReader(data); + } catch (ArrayIndexOutOfBoundsException e) { + IOException ioe = new IOException("Malformed bytecode: not enough data"); + ioe.initCause(e);// IOException didn't grow a constructor that could take a cause till + // 1.6, so do it the old fashioned way + throw ioe; + } + r.accept(this, 0); } - public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { nextVisitIsVersion = desc.equals("Lorg/python/compiler/APIVersion;"); return this; } - public void visit(String name, Object value) { + public void visit(String name, Object value) { if (nextVisitIsVersion) { version = (Integer)value; nextVisitIsVersion = false; Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/src/org/python/core/imp.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -87,7 +87,15 @@ static PyObject createFromPyClass(String name, InputStream fp, boolean testing, String sourceName, String compiledName) { - byte[] data = readCode(name, fp, testing); + byte[] data = null; + try { + data = readCode(name, fp, testing); + } catch (IOException ioe) { + if (!testing) { + throw Py.ImportError(ioe.getMessage() + "[name=" + name + ", source=" + sourceName + + ", compiled=" + compiledName + "]"); + } + } if (testing && data == null) { return null; } @@ -108,15 +116,11 @@ return createFromCode(name, code, compiledName); } - public static byte[] readCode(String name, InputStream fp, boolean testing) { + public static byte[] readCode(String name, InputStream fp, boolean testing) throws IOException { byte[] data = readBytes(fp); int api; - try { - APIReader ar = new APIReader(data); - api = ar.getVersion(); - } catch (IOException i) { - api = -1; - } + APIReader ar = new APIReader(data); + api = ar.getVersion(); if (api != APIVersion) { if (testing) { return null; Modified: trunk/jython/src/org/python/core/util/importer.java =================================================================== --- trunk/jython/src/org/python/core/util/importer.java 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/src/org/python/core/util/importer.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,5 +1,6 @@ package org.python.core.util; +import java.io.IOException; import java.io.InputStream; import java.util.EnumSet; import org.python.core.BytecodeLoader; @@ -182,7 +183,11 @@ Bundle bundle = makeBundle(searchPath, tocEntry); byte[] codeBytes; if (isbytecode) { - codeBytes = imp.readCode(fullname, bundle.inputStream, true); + try { + codeBytes = imp.readCode(fullname, bundle.inputStream, true); + } catch (IOException ioe) { + throw Py.ImportError(ioe.getMessage() + "[path=" + fullPath + searchPath + "]"); + } } else { codeBytes = imp.compileSource(fullname, bundle.inputStream, fullSearchPath); } Modified: trunk/jython/tests/java/org/python/tests/BeanInterface.java =================================================================== --- trunk/jython/tests/java/org/python/tests/BeanInterface.java 2009-01-04 23:20:34 UTC (rev 5844) +++ trunk/jython/tests/java/org/python/tests/BeanInterface.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -1,6 +1,6 @@ package org.python.tests; -public interface BeanInterface { +public interface BeanInterface extends Cloneable { String getName(); } Added: trunk/jython/tests/java/org/python/tests/Matryoshka.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Matryoshka.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/Matryoshka.java 2009-01-05 03:56:25 UTC (rev 5845) @@ -0,0 +1,16 @@ +package org.python.tests; + +public class Matryoshka { + + public static Outermost makeOutermost() { + return new Outermost(); + } + + public static class Outermost { + + public static class Middle { + + public static class Innermost {} + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |