forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 50
/
sys_test.go
72 lines (46 loc) · 1.44 KB
/
sys_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
package python3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSysGetSetObject(t *testing.T) {
Py_Initialize()
platform := PySys_GetObject("platform")
assert.NotNil(t, platform)
assert.True(t, PyUnicode_Check(platform))
platform.IncRef()
newPlatform := PyUnicode_FromString("test")
defer newPlatform.DecRef()
assert.Zero(t, PySys_SetObject("platform", newPlatform))
assert.Equal(t, newPlatform, PySys_GetObject("platform"))
assert.Zero(t, PySys_SetObject("platform", platform))
}
func TestSysWarnOption(t *testing.T) {
Py_Finalize()
assert.Nil(t, PySys_AddWarnOption("ignore"))
Py_Initialize()
warnoptions := PySys_GetObject("warnoptions")
assert.Equal(t, "ignore", PyUnicode_AsUTF8(PyList_GetItem(warnoptions, 0)))
Py_Finalize()
PySys_ResetWarnOptions()
Py_Initialize()
warnoptions = PySys_GetObject("warnoptions")
assert.Zero(t, PyList_Size(warnoptions))
}
func TestSysXOption(t *testing.T) {
Py_Finalize()
assert.Nil(t, PySys_AddXOption("faulthandler"))
Py_Initialize()
XOptions := PySys_GetXOptions()
faulthandler := PyDict_GetItemString(XOptions, "faulthandler")
assert.Equal(t, Py_True, faulthandler)
}
func TestSysPath(t *testing.T) {
Py_Initialize()
path := PySys_GetObject("path")
path.IncRef()
assert.Nil(t, PySys_SetPath("test"))
newPath := PySys_GetObject("path")
assert.Equal(t, "test", PyUnicode_AsUTF8(PyList_GetItem(newPath, 0)))
assert.Zero(t, PySys_SetObject("path", path))
}