forked from go-python/cpy3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuple_test.go
70 lines (49 loc) · 1.29 KB
/
tuple_test.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
package python3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTupleCheck(t *testing.T) {
Py_Initialize()
tuple := PyTuple_New(0)
assert.True(t, PyTuple_Check(tuple))
assert.True(t, PyTuple_CheckExact(tuple))
defer tuple.DecRef()
}
func TestTupleNew(t *testing.T) {
Py_Initialize()
tuple := PyTuple_New(0)
assert.NotNil(t, tuple)
defer tuple.DecRef()
}
func TestTupleSize(t *testing.T) {
Py_Initialize()
size := 45
tuple := PyTuple_New(size)
assert.Equal(t, size, PyTuple_Size(tuple))
defer tuple.DecRef()
}
func TestTupleGetSetItem(t *testing.T) {
Py_Initialize()
s := PyUnicode_FromString("test")
i := PyLong_FromGoInt(34)
tuple := PyTuple_New(2)
defer tuple.DecRef()
assert.Zero(t, PyTuple_SetItem(tuple, 0, s))
assert.Zero(t, PyTuple_SetItem(tuple, 1, i))
assert.Equal(t, i, PyTuple_GetItem(tuple, 1))
}
func TestTupleGetSlice(t *testing.T) {
Py_Initialize()
s := PyUnicode_FromString("test")
i := PyLong_FromGoInt(34)
tuple := PyTuple_New(2)
defer tuple.DecRef()
assert.Zero(t, PyTuple_SetItem(tuple, 0, s))
assert.Zero(t, PyTuple_SetItem(tuple, 1, i))
slice := PyTuple_GetSlice(tuple, 0, 1)
defer slice.DecRef()
assert.True(t, PyTuple_Check(slice))
assert.Equal(t, 1, PyTuple_Size(slice))
assert.Equal(t, s, PyTuple_GetItem(slice, 0))
}