Skip to content

Commit 7f2689c

Browse files
committed
Added some testing scripts
1 parent b9bb435 commit 7f2689c

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

tests/testapp/main.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from kivy.app import App
2+
3+
from kivy.lang import Builder
4+
from kivy.properties import StringProperty
5+
6+
from kivy.uix.popup import Popup
7+
8+
9+
kv = '''
10+
<FixedSizeButton@Button>:
11+
size_hint_y: None
12+
height: dp(60)
13+
14+
15+
ScrollView:
16+
GridLayout:
17+
cols: 1
18+
size_hint_y: None
19+
height: self.minimum_height
20+
FixedSizeButton:
21+
text: 'test pyjnius'
22+
on_press: app.test_pyjnius()
23+
24+
<ErrorPopup>:
25+
title: 'Error'
26+
size_hint: 0.75, 0.75
27+
Label:
28+
text: root.error_text
29+
'''
30+
31+
32+
class ErrorPopup(Popup):
33+
error_text = StringProperty('')
34+
35+
def raise_error(error):
36+
print('ERROR:', error)
37+
ErrorPopup(error_text=error).open()
38+
39+
class TestApp(App):
40+
def build(self):
41+
root = Builder.load_string(kv)
42+
return root
43+
44+
def on_pause(self):
45+
return True
46+
47+
def test_pyjnius(self):
48+
try:
49+
from jnius import autoclass
50+
except ImportError:
51+
raise_error('Could not import pyjnius')
52+
return
53+
54+
print('Attempting to vibrate with pyjnius')
55+
PythonActivity = autoclass('org.renpy.android.PythonActivity')
56+
activity = PythonActivity.mActivity
57+
Intent = autoclass('android.content.Intent')
58+
Context = autoclass('android.content.Context')
59+
vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE)
60+
61+
vibrator.vibrate(1000)
62+
63+
64+
TestApp().run()

tests/testapp_nogui/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
from math import sqrt
3+
4+
for i in range(50):
5+
print i, sqrt(i)
6+
7+
print 'Just printing stuff apparently worked, trying pyjnius'
8+
9+
import jnius
10+
11+
print 'Importing jnius worked'
12+
13+
print 'Trying to autoclass activity'
14+
15+
from jnius import autoclass
16+
17+
NewPythonActivity = autoclass('net.inclem.android.NewPythonActivity')
18+
19+
print ':o the autoclass worked!'
20+

0 commit comments

Comments
 (0)