-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
787 additions
and
740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
name: 'update-registry' | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- v* | ||
workflow_dispatch: | ||
|
||
jobs: | ||
notify: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: nhatthm/gh-actions/checkout@master | ||
|
||
- name: Notify registries | ||
uses: nhatthm/gh-actions/notify-go-registries@master | ||
with: | ||
token: ${{ secrets.REGISTRY_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cpy3 | ||
package cpy | ||
|
||
/* | ||
#include "Python.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package cpy3_test | ||
package cpy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"go.nhat.io/cpy3" | ||
"go.nhat.io/cpy/v3" | ||
) | ||
|
||
func TestBoolCheck(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
assert.True(t, cpy3.PyBool_Check(cpy3.Py_True)) | ||
assert.True(t, cpy3.PyBool_Check(cpy3.Py_False)) | ||
assert.True(t, cpy.PyBool_Check(cpy.Py_True)) | ||
assert.True(t, cpy.PyBool_Check(cpy.Py_False)) | ||
} | ||
|
||
func TestBoolFromLong(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
assert.Equal(t, cpy3.Py_True, cpy3.PyBool_FromLong(1)) | ||
assert.Equal(t, cpy3.Py_False, cpy3.PyBool_FromLong(0)) | ||
assert.Equal(t, cpy.Py_True, cpy.PyBool_FromLong(1)) | ||
assert.Equal(t, cpy.Py_False, cpy.PyBool_FromLong(0)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cpy3 | ||
package cpy | ||
|
||
/* | ||
#include "Python.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
package cpy3_test | ||
package cpy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"go.nhat.io/cpy3" | ||
"go.nhat.io/cpy/v3" | ||
) | ||
|
||
func TestByteArrayCheck(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
|
||
array1 := cpy3.PyByteArray_FromStringAndSize(s1) | ||
array1 := cpy.PyByteArray_FromStringAndSize(s1) | ||
defer array1.DecRef() | ||
|
||
assert.True(t, cpy3.PyByteArray_Check(array1)) | ||
assert.True(t, cpy3.PyByteArray_CheckExact(array1)) | ||
assert.True(t, cpy.PyByteArray_Check(array1)) | ||
assert.True(t, cpy.PyByteArray_CheckExact(array1)) | ||
} | ||
|
||
func TestByteArrayFromAsString(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
|
||
array1 := cpy3.PyByteArray_FromStringAndSize(s1) | ||
array1 := cpy.PyByteArray_FromStringAndSize(s1) | ||
defer array1.DecRef() | ||
|
||
assert.Equal(t, s1, cpy3.PyByteArray_AsString(array1)) | ||
assert.Equal(t, s1, cpy.PyByteArray_AsString(array1)) | ||
} | ||
|
||
func TestByteArrayConcat(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
s2 := "bbbbbbbb" | ||
|
||
array1 := cpy3.PyByteArray_FromStringAndSize(s1) | ||
array1 := cpy.PyByteArray_FromStringAndSize(s1) | ||
defer array1.DecRef() | ||
|
||
bytes := cpy3.PyBytes_FromString(s2) | ||
bytes := cpy.PyBytes_FromString(s2) | ||
defer bytes.DecRef() | ||
|
||
assert.NotNil(t, bytes) | ||
|
||
array2 := cpy3.PyByteArray_FromObject(bytes) | ||
array2 := cpy.PyByteArray_FromObject(bytes) | ||
defer array2.DecRef() | ||
|
||
assert.NotNil(t, array2) | ||
|
||
newArray := cpy3.PyByteArray_Concat(array1, array2) | ||
newArray := cpy.PyByteArray_Concat(array1, array2) | ||
defer newArray.DecRef() | ||
|
||
assert.Equal(t, s1+s2, cpy3.PyByteArray_AsString(newArray)) | ||
assert.Equal(t, s1+s2, cpy.PyByteArray_AsString(newArray)) | ||
} | ||
|
||
func TestByteArrayResize(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
|
||
array1 := cpy3.PyByteArray_FromStringAndSize(s1) | ||
array1 := cpy.PyByteArray_FromStringAndSize(s1) | ||
defer array1.DecRef() | ||
|
||
length := 20 | ||
|
||
cpy3.PyByteArray_Resize(array1, 20) | ||
cpy.PyByteArray_Resize(array1, 20) | ||
|
||
assert.Equal(t, length, cpy3.PyByteArray_Size(array1)) | ||
assert.Equal(t, length, cpy.PyByteArray_Size(array1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cpy3 | ||
package cpy | ||
|
||
/* | ||
#include "Python.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,101 @@ | ||
package cpy3_test | ||
package cpy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"go.nhat.io/cpy3" | ||
"go.nhat.io/cpy/v3" | ||
) | ||
|
||
func TestBytesCheck(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
|
||
bytes1 := cpy3.PyBytes_FromString(s1) | ||
bytes1 := cpy.PyBytes_FromString(s1) | ||
defer bytes1.DecRef() | ||
|
||
assert.True(t, cpy3.PyBytes_Check(bytes1)) | ||
assert.True(t, cpy3.PyBytes_CheckExact(bytes1)) | ||
assert.True(t, cpy.PyBytes_Check(bytes1)) | ||
assert.True(t, cpy.PyBytes_CheckExact(bytes1)) | ||
} | ||
|
||
func TestBytesFromAsString(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
|
||
bytes1 := cpy3.PyBytes_FromString(s1) | ||
bytes1 := cpy.PyBytes_FromString(s1) | ||
defer bytes1.DecRef() | ||
|
||
assert.Equal(t, s1, cpy3.PyBytes_AsString(bytes1)) | ||
assert.Equal(t, s1, cpy.PyBytes_AsString(bytes1)) | ||
} | ||
|
||
func TestBytesSize(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
|
||
bytes1 := cpy3.PyBytes_FromString(s1) | ||
bytes1 := cpy.PyBytes_FromString(s1) | ||
defer bytes1.DecRef() | ||
|
||
assert.Equal(t, 8, cpy3.PyBytes_Size(bytes1)) | ||
assert.Equal(t, 8, cpy.PyBytes_Size(bytes1)) | ||
} | ||
|
||
func TestBytesConcat(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
s2 := "bbbbbbbb" | ||
|
||
bytes1 := cpy3.PyBytes_FromString(s1) | ||
bytes1 := cpy.PyBytes_FromString(s1) | ||
|
||
array := cpy3.PyByteArray_FromStringAndSize(s2) | ||
array := cpy.PyByteArray_FromStringAndSize(s2) | ||
defer array.DecRef() | ||
|
||
bytes2 := cpy3.PyBytes_FromObject(array) | ||
bytes2 := cpy.PyBytes_FromObject(array) | ||
defer bytes2.DecRef() | ||
|
||
assert.NotNil(t, bytes2) | ||
|
||
bytes1 = cpy3.PyBytes_Concat(bytes1, bytes2) | ||
bytes1 = cpy.PyBytes_Concat(bytes1, bytes2) | ||
defer bytes1.DecRef() | ||
|
||
assert.NotNil(t, bytes1) | ||
assert.Equal(t, s1+s2, cpy3.PyBytes_AsString(bytes1)) | ||
assert.Equal(t, s1+s2, cpy.PyBytes_AsString(bytes1)) | ||
} | ||
|
||
func TestBytesConcatAndDel(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := "aaaaaaaa" | ||
s2 := "bbbbbbbb" | ||
|
||
bytes1 := cpy3.PyBytes_FromString(s1) | ||
bytes1 := cpy.PyBytes_FromString(s1) | ||
|
||
bytes2 := cpy3.PyBytes_FromString(s2) | ||
bytes2 := cpy.PyBytes_FromString(s2) | ||
|
||
assert.NotNil(t, bytes2) | ||
|
||
bytes1 = cpy3.PyBytes_ConcatAndDel(bytes1, bytes2) | ||
bytes1 = cpy.PyBytes_ConcatAndDel(bytes1, bytes2) | ||
defer bytes1.DecRef() | ||
|
||
assert.NotNil(t, bytes1) | ||
assert.Equal(t, s1+s2, cpy3.PyBytes_AsString(bytes1)) | ||
assert.Equal(t, s1+s2, cpy.PyBytes_AsString(bytes1)) | ||
} | ||
|
||
func TestByteSlices(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
s1 := []byte("aaaaaaaa") | ||
s2 := []byte("bbbbbbbb") | ||
|
||
bytes1 := cpy3.PyBytes_FromByteSlice(s1) | ||
bytes1 := cpy.PyBytes_FromByteSlice(s1) | ||
defer bytes1.DecRef() | ||
|
||
bytes2 := cpy3.PyBytes_FromByteSlice(s2) | ||
bytes2 := cpy.PyBytes_FromByteSlice(s2) | ||
defer bytes2.DecRef() | ||
|
||
assert.Equal(t, s1, cpy3.PyBytes_AsByteSlice(bytes1)) | ||
assert.Equal(t, s2, cpy3.PyBytes_AsByteSlice(bytes2)) | ||
assert.Equal(t, s1, cpy.PyBytes_AsByteSlice(bytes1)) | ||
assert.Equal(t, s2, cpy.PyBytes_AsByteSlice(bytes2)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cpy3 | ||
package cpy | ||
|
||
/* | ||
#include "Python.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
package cpy3_test | ||
package cpy_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"go.nhat.io/cpy3" | ||
"go.nhat.io/cpy/v3" | ||
) | ||
|
||
func TestComplex(t *testing.T) { | ||
cpy3.Py_Initialize() | ||
cpy.Py_Initialize() | ||
|
||
nReal := 2. | ||
nImaginary := 5. | ||
|
||
nComplex := cpy3.PyComplex_FromDoubles(nReal, nImaginary) | ||
nComplex := cpy.PyComplex_FromDoubles(nReal, nImaginary) | ||
defer nComplex.DecRef() | ||
|
||
assert.True(t, cpy3.PyComplex_Check(nComplex)) | ||
assert.True(t, cpy3.PyComplex_CheckExact(nComplex)) | ||
assert.True(t, cpy.PyComplex_Check(nComplex)) | ||
assert.True(t, cpy.PyComplex_CheckExact(nComplex)) | ||
|
||
assert.InDelta(t, nReal, cpy3.PyComplex_RealAsDouble(nComplex), 0.01) | ||
assert.InDelta(t, nImaginary, cpy3.PyComplex_ImagAsDouble(nComplex), 0.01) | ||
assert.InDelta(t, nReal, cpy.PyComplex_RealAsDouble(nComplex), 0.01) | ||
assert.InDelta(t, nImaginary, cpy.PyComplex_ImagAsDouble(nComplex), 0.01) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cpy3 | ||
package cpy | ||
|
||
/* | ||
#include "Python.h" | ||
|
Oops, something went wrong.