Files
cpy3/high_level_layer_test.go
zeekayandHanzo Dev a9a8522156 Go 1.27.1, and the code it can say more simply
The module declares go 1.27.1. go fix applied the modernizers; omitzero
is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 19:42:39 -07:00

48 lines
891 B
Go

package python3
import (
"os"
"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 := os.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)
}