forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathhigh_level_layer_test.go
More file actions
47 lines (32 loc) · 902 Bytes
/
high_level_layer_test.go
File metadata and controls
47 lines (32 loc) · 902 Bytes
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
package python3
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRunFile(t *testing.T) {
Py_Initialize()
pyErr, err := PyRun_AnyFile("tests/test.py")
assert.Zero(t, pyErr)
assert.Nil(t, err)
stdout := PySys_GetObject("stdout")
result := stdout.CallMethodArgs("getvalue")
defer result.DecRef()
assert.Equal(t, "hello world\n", PyUnicode_AsUTF8(result))
}
func TestRunString(t *testing.T) {
Py_Initialize()
pythonCode, err := ioutil.ReadFile("tests/test.py")
assert.Nil(t, err)
assert.Zero(t, PyRun_SimpleString(string(pythonCode)))
stdout := PySys_GetObject("stdout")
result := stdout.CallMethodArgs("getvalue")
defer result.DecRef()
assert.Equal(t, "hello world\n", PyUnicode_AsUTF8(result))
}
func TestPyMain(t *testing.T) {
Py_Initialize()
pyErr, err := Py_Main([]string{"tests/test.py"})
assert.Zero(t, pyErr)
assert.Nil(t, err)
}