示例#1
0
'''
From bug #1548501
Check that __file__ is set on a file run directly from jython.
'''
import support
support.runJython('test393m.py')
示例#2
0
"""
[ #448398 ] open('test.txt','w').write('test') fails
"""

import support

support.runJython("test322m.py")

import os

l = os.stat("test322.out")[6]

if l != 7:
    raise support.TestWarning('The file should have been auto flushed')
示例#3
0
import support
import os


def check(filename, result):
    f = open(filename)
    l = f.readlines()
    f.close()
    if l != result:
        raise support.TestError("Result was wrong: %s" % l)


# Different exit situations in the interpreter.

support.runJython("test333s1.py", output="test333s1.out")
check("test333s1.out", ["myfunc\n"])

ret = support.runJython("test333s2.py", output="test333s2.out", expectError=1)
if ret != 42:
    raise support.TestError("Return code was wrong: %d" % ret)
check("test333s2.out", ["myfunc\n"])

support.runJython("test333s3.py",
                  output="test333s3.out",
                  error="test333s3.err",
                  expectError=1)
check("test333s3.out", ["myfunc\n"])
check("test333s3.err", [
    'Traceback (innermost last):\n',
    '  File "test333s3.py", line 8, in ?\n',
示例#4
0
'''

test402m adds a jar file to sys.path and imports a package from it.  The first
run ensures that, by default, package scanning is enabled for jars added to
sys.path.  The second run turns off package scanning, so it checks that the
package is unimportable without the scan.  Finally, we run test402n which adds
the same jar to its sys.path and imports a fully qualified class from it.  We
run it with package scanning off to make sure that even without package
scanning, jars are correctly added to sys.path and fully qualified class
imports work on them.

'''

import support
import jarmaker

jarmaker.mkjar()

support.runJython('test402m.py')
ret = support.runJython('test402m.py', error='test402.err',
        javaargs='-Dpython.cachedir.skip=true', expectError=1)
if ret == 0:
    raise support.TestError('Successfully imported a package from a jar on sys.path without caching!')
support.runJython('test402n.py', javaargs='-Dpython.cachedir.skip=true')
示例#5
0
"""
From bug #1548501
Check that __file__ is set on a file run directly from jython.
"""
import support

support.runJython("test393m.py")
示例#6
0
'''
From bug #1284344
import a compiled module moved to a new location and check that its __file__
matches its new spot.
'''

fname = 'test392m.py'

open(fname, 'w').close()#touch!

import test392m
del test392m
import os
compiledName = 'test392m$py.class'
os.rename(compiledName, 'test392LibDir/%s' % compiledName)
os.remove(fname)

import support
ret = support.runJython('test392importer.py', expectError=True)
if ret == 1:
    raise support.TestError, '__file__ on test392m reflected where it was compiled, not where it was imported.'
elif ret != 0:
    raise support.TestError, 'running test392importer.py exited with an unexpected code'

示例#7
0
[ #476772 ] shutdowns in jython / atexit
"""

import support
import os

def check(filename, result):
    f = open(filename)
    l = f.readlines()
    f.close()
    if l != result:
        raise support.TestError("Result was wrong: %s" % l)

# Different exit situations in the interpreter.

support.runJython("test333s1.py", output="test333s1.out")
check("test333s1.out", [ "myfunc\n" ])

ret = support.runJython("test333s2.py", output="test333s2.out", expectError=1)
if ret != 42:
    raise support.TestError("Return code was wrong: %d" % ret)
check("test333s2.out", [ "myfunc\n" ])

support.runJython("test333s3.py",
        output="test333s3.out", error="test333s3.err", expectError=1)
check("test333s3.out", [ "myfunc\n" ])
check("test333s3.err", [
    'Traceback (innermost last):\n',
    '  File "test333s3.py", line 8, in ?\n',
    'Exc\n',
])
示例#8
0
'''

test402m adds a jar file to sys.path and imports a package from it.  The first
run ensures that, by default, package scanning is enabled for jars added to
sys.path.  The second run turns off package scanning, so it checks that the
package is unimportable without the scan.  Finally, we run test402n which adds
the same jar to its sys.path and imports a fully qualified class from it.  We
run it with package scanning off to make sure that even without package
scanning, jars are correctly added to sys.path and fully qualified class
imports work on them.

'''

import support
import jarmaker

jarmaker.mkjar()

support.runJython('test402m.py')
ret = support.runJython('test402m.py',
                        error='test402.err',
                        javaargs='-Dpython.cachedir.skip=true',
                        expectError=1)
if ret == 0:
    raise support.TestError(
        'Successfully imported a package from a jar on sys.path without caching!'
    )
support.runJython('test402n.py', javaargs='-Dpython.cachedir.skip=true')
示例#9
0
"""
[ #488632 ] -c sys.argv diff
"""

import support

support.runJython(
    """-c "import sys; assert sys.argv == ['-c', '-v', 'args']" -v args""")

示例#10
0
from java.lang import System, Thread

def check(fn='test.txt'):
    f = File(fn)
    if not f.exists():
        raise support.TestError('"%s" should exist' % fn)
    if not f.length():
        raise support.TestError('"%s" should have contents' % fn)
    os.remove(fn)


open("garbagecollected", "w").write("test")

#Wait up to 2 seconds for garbage collected to disappear
System.gc()
for i in range(10):
    if not os.path.exists('garbagecollected'):
        break
    Thread.sleep(200)

check("garbagecollected")

f = open("normalclose", "w")
f.write("test")
f.close()
check("normalclose")

#test397m writes to "shutdown" and exits
support.runJython('test397m.py')
check('shutdown')