File: test_jsubclass.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 (49 lines) | stat: -rw-r--r-- 966 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
from test_support import *

print_test('Subclassing Java from Python (test_jsubclass.py)', 1)

from java.lang import Runnable, Thread

# Overriding Methods

print_test('override methods', 2)
class MyThread(Thread):
	count = 0
	def run(self):
		self.count = self.count+1


t1 = MyThread()
t1.start()
t1.join()
assert t1.count == 1, 'subclassing java.lang.Thread'

print_test('pass subclass back to java', 2)

class MyRun(Runnable):
	count = 0
	def run(self):
		self.count = self.count+1

run = MyRun()
t = Thread(run)
t.start()
t.join()
assert run.count == 1, 'subclassing java.lang.Thread'

print_test("invoke super's constructor", 2)

class MyThread(Thread):
	def __init__(self):
		self.name = "Python-"+self.name

t = MyThread()
assert t.name[:14] == "Python-Thread-", 'automatic constructor call'

class MyThread(Thread):
	def __init__(self):
		Thread.__init__(self, "Python-Thread")

t = MyThread()
assert t.name == "Python-Thread", 'explicit constructor call'