-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_wide_parameters_test.go
186 lines (142 loc) · 4.5 KB
/
process_wide_parameters_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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"fmt"
"testing"
"github.com/M-Quadra/go-python3-submodule/v11/py"
pylist "github.com/M-Quadra/go-python3-submodule/v11/py-list"
pysys "github.com/M-Quadra/go-python3-submodule/v11/py-sys"
pyunicode "github.com/M-Quadra/go-python3-submodule/v11/py-unicode"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPyGetSetProgramName(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
defaultName := py.GetProgramName()
require.Equal(t, "python3", defaultName)
defer py.SetProgramName(defaultName)
name := "py3∑åß∂"
py.SetProgramName(name)
require.Equal(t, name, py.GetProgramName())
py.SetProgramName("")
require.Equal(t, "", py.GetProgramName())
}
func TestPyGetPrefix(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
prefix := py.GetPrefix()
fmt.Println(prefix)
require.True(t, len(prefix) > 0)
}
func TestPyGetExecPrefix(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
execPrefix := py.GetExecPrefix()
fmt.Println(execPrefix)
}
func TestPyGetProgramFullPath(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
fullPath := py.GetProgramFullPath()
fmt.Println(fullPath)
assert.True(t, len(fullPath) > 0)
}
func TestPyGetSetPath(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
defaultPath := py.GetPath()
defer py.SetPath(defaultPath)
name := "påth"
py.SetPath(name)
assert.Equal(t, name, py.GetPath())
}
func TestPyGetVersion(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
version := py.GetVersion()
fmt.Println(version)
assert.True(t, len(version) > 0)
}
func TestPyGetPlatform(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
platform := py.GetPlatform()
fmt.Println(platform)
assert.True(t, len(platform) > 0)
}
func TestPyGetCopyright(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
copyright := py.GetCopyright()
fmt.Println(copyright)
assert.True(t, len(copyright) > 0)
}
func TestPyGetCompiler(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
compiler := py.GetCompiler()
fmt.Println(compiler)
assert.True(t, len(compiler) > 0)
}
func TestPyGetBuildInfo(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
buildInfo := py.GetBuildInfo()
fmt.Println(buildInfo)
assert.True(t, len(buildInfo) > 0)
}
func TestPySysSetArgvEx(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
{ // argv recovery
path := pysys.GetObject("path")
py.IncRef(path)
defer py.DecRef(path)
defer func() { assert.Equal(t, 1, py.RefCnt(path)) }()
oldPath := pylist.New(pylist.Size(path))
defer func() { assert.Equal(t, 1, py.RefCnt(oldPath)) }()
assert.True(t, pylist.SetSlice(oldPath, 0, pylist.Size(path), path))
defer func() {
assert.Equal(t, 1, py.RefCnt(oldPath))
assert.True(t, pysys.SetObject("path", oldPath))
py.DecRef(oldPath)
}()
}
pysys.SetArgvEx(false, "test.py")
argv := pysys.GetObject("argv")
defer func() { assert.Equal(t, 1, py.RefCnt(argv)) }()
assert.Equal(t, 1, pylist.Size(argv))
assert.Equal(t, "test.py", pyunicode.AsString(pylist.GetItem(argv, 0)))
}
func TestPySysSetArgv(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
{ // path recovery
path := pysys.GetObject("path")
py.IncRef(path)
defer py.DecRef(path)
defer func() { assert.Equal(t, 1, py.RefCnt(path)) }()
oldPath := pylist.New(pylist.Size(path))
defer func() { assert.Equal(t, 1, py.RefCnt(oldPath)) }()
assert.True(t, pylist.SetSlice(oldPath, 0, pylist.Size(path), path))
defer func() {
assert.Equal(t, 1, py.RefCnt(oldPath))
assert.True(t, pysys.SetObject("path", oldPath))
py.DecRef(oldPath)
}()
}
{ // argv recovery
argv := pysys.GetObject("argv")
py.IncRef(argv)
defer py.DecRef(argv)
argvArr := make([]string, 0, pylist.Size(argv))
for i := 0; i < pylist.Size(argv); i++ {
argvArr = append(argvArr, pyunicode.AsString(pylist.GetItem(argv, i)))
}
defer func() {
pysys.SetArgvEx(false, argvArr...)
assert.Equal(t, 1, py.RefCnt(argv))
}()
}
pysys.SetArgv("test.py")
argv := pysys.GetObject("argv")
defer func() { assert.Equal(t, 1, py.RefCnt(argv)) }()
assert.Equal(t, 1, pylist.Size(argv))
assert.Equal(t, "test.py", pyunicode.AsString(pylist.GetItem(argv, 0)))
}
func TestPyGetSetPythonHome(t *testing.T) {
fmt.Println("current:", assert.CallerInfo()[0])
defaultHome := py.GetPythonHome()
defer py.SetPythonHome(defaultHome)
home := "høme"
py.SetPythonHome(home)
assert.Equal(t, home, py.GetPythonHome())
}