mirror of
https://github.com/hanzoai/cpy3.git
synced 2026-10-30 18:42:30 +00:00
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]>
48 lines
891 B
Go
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)
|
|
}
|