Lib.test.test_builtin_jy.py Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython Show documentation
Show all versions of jython Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
# -*- coding: utf-8 -*-
import test.test_support, unittest
from test.test_support import TESTFN, unlink
import sys, UserDict
from codecs import BOM_UTF8
class BuiltinTest(unittest.TestCase):
def test_in_sys_modules(self):
self.assert_("__builtin__" in sys.modules,
"__builtin__ not found in sys.modules")
def test_hasattr_swallows_exceptions(self):
class Foo(object):
def __getattr__(self, name):
raise TypeError()
self.assert_(not hasattr(Foo(), 'bar'))
def test_getattr_custom_AttributeError(self):
class Foo(object):
def __getattr__(self, name):
raise AttributeError('baz')
try:
getattr(Foo(), 'bar')
except AttributeError, ae:
self.assertEqual(str(ae), 'baz')
else:
self.assertTrue(False)
def test_dir(self):
# for http://bugs.jython.org/issue1196
class Foo(object):
def __getattribute__(self, name):
return name
self.assertEqual(dir(Foo()), [])
def test_numeric_cmp(self):
# http://bugs.jython.org/issue1449
for numeric in 1, 2L, 3.0, 4j:
self.assertTrue(numeric < Ellipsis)
self.assertTrue(Ellipsis > numeric)
def test_max_error_message(self):
'fix for http://bugs.jython.org/issue2130'
try:
max([])
except ValueError, e:
self.assertEqual(str(e), 'max of empty sequence')
else:
self.fail('max with empty sequence should raise a proper ValueError')
class LoopTest(unittest.TestCase):
def test_break(self):
while 1:
i = 0
while i<10:
i = i+1
else:
break
class DebugTest(unittest.TestCase):
def test_debug(self):
"__debug__ exists"
try:
foo = __debug__
except NameError, e:
self.assert_(False)
class GetSliceTest(unittest.TestCase):
def test_getslice(self):
class F:
def __getitem__(self,*args): return '__getitem__ '+repr(args)
def __getslice__(self,*args): return '__getslice__ '+repr(args)
self.failUnless("__getslice__ (1, 1)" in F()[1:1])
class ChrTest(unittest.TestCase):
def test_debug(self):
"chr(None) throws TypeError"
foo = False
try:
chr(None)
except TypeError, e:
foo = True
self.assert_(foo)
class ReturnTest(unittest.TestCase):
def test_finally(self):
'''return in finally causes java.lang.VerifyError at compile time'''
def timeit(f):
t0 = time.clock()
try:
f()
finally:
t1 = time.clock()
return t1 - t0
class ReprTest(unittest.TestCase):
def test_unbound(self):
"Unbound methods indicated properly in repr"
class Foo:
def bar(s):
pass
self.failUnless(repr(Foo.bar).startswith('