File: test_jser.py

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (57 lines) | stat: -rw-r--r-- 1,144 bytes parent folder | download | duplicates (5)
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 'Java Serialization (test_jser.py)'

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 'writing'

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

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

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

print 'Python int'
assert iobject1 == object1

print 'Python list'
assert iobject2 == object2

print 'Python instance'
assert iobject3.baz     == 99
assert iobject3.bar() == 'bar'
assert iobject3.__class__ == Foo

print 'Java instance'
assert iobject4 == object4

os.remove(sername)