forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 50
/
module_test.go
111 lines (79 loc) · 2.05 KB
/
module_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package python3
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestModuleCheck(t *testing.T) {
Py_Initialize()
name := "test_module"
module := PyModule_New(name)
assert.True(t, PyModule_Check(module))
assert.True(t, PyModule_CheckExact(module))
defer module.DecRef()
}
func TestModuleNew(t *testing.T) {
Py_Initialize()
name := "test_module"
module := PyModule_New(name)
assert.NotNil(t, module)
defer module.DecRef()
}
func TestModuleNewObject(t *testing.T) {
Py_Initialize()
name := "test_module"
pyName := PyUnicode_FromString(name)
assert.NotNil(t, pyName)
defer pyName.DecRef()
module := PyModule_NewObject(pyName)
assert.NotNil(t, module)
defer module.DecRef()
}
func TestModuleGetDict(t *testing.T) {
Py_Initialize()
name := "sys"
pyName := PyUnicode_FromString(name)
defer pyName.DecRef()
sys := PyImport_ImportModule(name)
defer sys.DecRef()
dict := PyModule_GetDict(sys)
assert.True(t, PyDict_Check(dict))
}
func TestModuleGetName(t *testing.T) {
Py_Initialize()
name := "sys"
pyName := PyUnicode_FromString(name)
defer pyName.DecRef()
sys := PyImport_ImportModule(name)
defer sys.DecRef()
assert.Equal(t, name, PyModule_GetName(sys))
}
func TestModuleGetNameObject(t *testing.T) {
Py_Initialize()
name := "sys"
pyName := PyUnicode_FromString(name)
defer pyName.DecRef()
sys := PyImport_ImportModule(name)
defer sys.DecRef()
assert.Equal(t, 1, pyName.RichCompareBool(PyModule_GetNameObject(sys), Py_EQ))
}
func TestModuleGetState(t *testing.T) {
Py_Initialize()
name := "sys"
pyName := PyUnicode_FromString(name)
defer pyName.DecRef()
sys := PyImport_ImportModule(name)
defer sys.DecRef()
state := PyModule_GetState(sys)
assert.True(t, state == nil)
}
func TestModuleGetFilenameObject(t *testing.T) {
Py_Initialize()
name := "queue"
queue := PyImport_ImportModule(name)
defer queue.DecRef()
pyFilename := PyModule_GetFilenameObject(queue)
assert.NotNil(t, pyFilename)
filename := PyUnicode_AsUTF8(pyFilename)
assert.True(t, strings.HasSuffix(filename, "/queue.py"))
}