This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
/
lifecycle_test.go
145 lines (106 loc) · 2.77 KB
/
lifecycle_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestInitialization(t *testing.T) {
Py_Initialize()
assert.True(t, Py_IsInitialized())
Py_Finalize()
assert.False(t, Py_IsInitialized())
}
func TestInitializationEx(t *testing.T) {
Py_Initialize()
assert.True(t, Py_IsInitialized())
assert.Zero(t, Py_FinalizeEx())
assert.False(t, Py_IsInitialized())
}
func TestProgramName(t *testing.T) {
Py_Finalize()
defaultName, err := Py_GetProgramName()
defer Py_SetProgramName(defaultName)
assert.Nil(t, err)
name := "py3é"
Py_SetProgramName(name)
newName, err := Py_GetProgramName()
assert.Nil(t, err)
assert.Equal(t, name, newName)
}
func TestPrefix(t *testing.T) {
prefix, err := Py_GetPrefix()
assert.Nil(t, err)
assert.IsType(t, "", prefix)
}
func TestExecPrefix(t *testing.T) {
execPrefix, err := Py_GetExecPrefix()
assert.Nil(t, err)
assert.IsType(t, "", execPrefix)
}
func TestProgramFullPath(t *testing.T) {
programFullPath, err := Py_GetProgramFullPath()
assert.Nil(t, err)
assert.IsType(t, "", programFullPath)
}
func TestPath(t *testing.T) {
Py_Finalize()
defaultPath, err := Py_GetPath()
defer Py_SetPath(defaultPath)
assert.Nil(t, err)
name := "påth"
Py_SetPath(name)
newName, err := Py_GetPath()
assert.Nil(t, err)
assert.Equal(t, name, newName)
}
func TestVersion(t *testing.T) {
version := Py_GetVersion()
assert.IsType(t, "", version)
}
func TestPlatform(t *testing.T) {
platform := Py_GetPlatform()
assert.IsType(t, "", platform)
}
func TestCopyright(t *testing.T) {
copyright := Py_GetCopyright()
assert.IsType(t, "", copyright)
}
func TestCompiler(t *testing.T) {
compiler := Py_GetCompiler()
assert.IsType(t, "", compiler)
}
func TestBuildInfo(t *testing.T) {
buildInfo := Py_GetBuildInfo()
assert.IsType(t, "", buildInfo)
}
func TestPythonHome(t *testing.T) {
name := "høme"
defaultHome, err := Py_GetPythonHome()
defer Py_SetPythonHome(defaultHome)
assert.Nil(t, err)
Py_SetPythonHome(name)
newName, err := Py_GetPythonHome()
assert.Nil(t, err)
assert.Equal(t, name, newName)
}
func TestSetArgv(t *testing.T) {
Py_Initialize()
PySys_SetArgv([]string{"test.py"})
argv := PySys_GetObject("argv")
assert.Equal(t, 1, PyList_Size(argv))
assert.Equal(t, "test.py", PyUnicode_AsUTF8(PyList_GetItem(argv, 0)))
Py_Finalize()
}
func TestSetArgvEx(t *testing.T) {
Py_Initialize()
PySys_SetArgvEx([]string{"test.py"}, false)
argv := PySys_GetObject("argv")
assert.Equal(t, 1, PyList_Size(argv))
assert.Equal(t, "test.py", PyUnicode_AsUTF8(PyList_GetItem(argv, 0)))
Py_Finalize()
}