File: test_jser.py

package info (click to toggle)
jython 2.1.0-20
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,388 kB
  • ctags: 12,215
  • sloc: java: 48,499; python: 16,220; xml: 403; makefile: 189; perl: 103; ansic: 24; sh: 14
file content (57 lines) | stat: -rw-r--r-- 1,221 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from test_support import *

print_test('Java Serialization (test_jser.py)', 1)

from java import io, awt
import os, sys

object1 = 42
object2 = ['a', 1, 1.0]
class Foo:
	def bar(self):
		return 'bar'

object3 = Foo()
object3.baz	= 99

object4 = awt.Color(1,2,3)

print_test('writing', 2)

sername = os.path.join(sys.prefix, "test.ser")
fout = io.ObjectOutputStream(io.FileOutputStream(sername))
print_test('Python int', 3)
fout.writeObject(object1)
print_test('Python list', 3)
fout.writeObject(object2)
print_test('Python instance', 3)
fout.writeObject(object3)
print_test('Java instance', 3)
fout.writeObject(object4)
fout.close()

fin	= io.ObjectInputStream(io.FileInputStream(sername))
print_test('reading', 2)
iobject1 = fin.readObject()
iobject2 = fin.readObject()
iobject3 = fin.readObject()
iobject4 = fin.readObject()
fin.close()

#print iobject1, iobject2, iobject3, iobject3.__class__, iobject4

print_test('Python int', 3)
assert iobject1	== object1

print_test('Python list', 3)
assert iobject2	== object2

print_test('Python instance', 3)
assert iobject3.baz	== 99
assert iobject3.bar() == 'bar'
assert iobject3.__class__ == Foo

print_test('Java instance', 3)
assert iobject4 == object4

os.remove(sername)