Skip to content

Commit a7c08f6

Browse files
committed
pyhal: Added tests for item object
1 parent b9a6a90 commit a7c08f6

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

tests/halmodule.0/expected

+9
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ set s -2147483649 fail
2424
set u -1 fail
2525
set u 4294967296 fail
2626
set f 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216 fail
27+
pincheck s True True True
28+
pincheck u True True True
29+
pincheck f True True True
30+
pincheck s True True True
31+
getitem not-found fail
32+
pincheck param False True True
33+
pincheck param False True True
34+
set u 0 0
35+
set u -1 fail

tests/halmodule.0/test.sh

+33-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import hal
55
import os
66
h = hal.component("x")
77
try:
8-
h.newpin("s", hal.HAL_S32, hal.HAL_OUT);
9-
h.newpin("u", hal.HAL_U32, hal.HAL_OUT);
10-
h.newpin("f", hal.HAL_FLOAT, hal.HAL_OUT);
8+
ps = h.newpin("s", hal.HAL_S32, hal.HAL_OUT);
9+
pu = h.newpin("u", hal.HAL_U32, hal.HAL_OUT);
10+
pf = h.newpin("f", hal.HAL_FLOAT, hal.HAL_OUT);
11+
param = h.newparam("param", hal.HAL_BIT, hal.HAL_RW)
1112
h.ready()
1213
1314
def try_set(p, v):
@@ -17,6 +18,13 @@ try:
1718
except (ValueError, OverflowError):
1819
print "set", p, v, "fail"
1920
21+
def try_set_pin(p, v):
22+
try:
23+
p.set(v)
24+
print "set", p.get_name(), v, p.get()
25+
except (ValueError, OverflowError):
26+
print "set", p.get_name(), v, "fail"
27+
2028
try_set("s", -1)
2129
try_set("s", 0)
2230
try_set("s", 1)
@@ -51,6 +59,28 @@ try:
5159
5260
try_set("f", 1l<<1024)
5361
62+
pin = h.getitem("s")
63+
64+
def pin_validate(i, t, d):
65+
print "pincheck", i.get_name(), i.is_pin(), i.get_type() == t, i.get_dir() == d
66+
pin_validate(ps, hal.HAL_S32, hal.HAL_OUT)
67+
pin_validate(pu, hal.HAL_U32, hal.HAL_OUT)
68+
pin_validate(pf, hal.HAL_FLOAT, hal.HAL_OUT)
69+
70+
pin = h.getitem("s")
71+
pin_validate(pin, hal.HAL_S32, hal.HAL_OUT)
72+
try:
73+
pin = h.getitem("not-found")
74+
print "getitem", "not-found", "ok"
75+
except:
76+
print "getitem", "not-found", "fail"
77+
78+
pin_validate(param, hal.HAL_BIT, hal.HAL_RW)
79+
param = h.getitem("param")
80+
pin_validate(param, hal.HAL_BIT, hal.HAL_RW)
81+
82+
try_set_pin(pu, 0)
83+
try_set_pin(pu, -1)
5484
except:
5585
import traceback
5686
print "Exception:", traceback.format_exc()

0 commit comments

Comments
 (0)