forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytes_test.go
86 lines (59 loc) · 1.6 KB
/
bytes_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
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the $license_for_repo License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBytesCheck(t *testing.T) {
Py_Initialize()
s1 := "aaaaaaaa"
bytes1 := PyBytes_FromString(s1)
assert.True(t, PyBytes_Check(bytes1))
assert.True(t, PyBytes_CheckExact(bytes1))
defer bytes1.DecRef()
}
func TestBytesFromAsString(t *testing.T) {
Py_Initialize()
s1 := "aaaaaaaa"
bytes1 := PyBytes_FromString(s1)
defer bytes1.DecRef()
assert.Equal(t, s1, PyBytes_AsString(bytes1))
}
func TestBytesSize(t *testing.T) {
Py_Initialize()
s1 := "aaaaaaaa"
bytes1 := PyBytes_FromString(s1)
defer bytes1.DecRef()
assert.Equal(t, 8, PyBytes_Size(bytes1))
}
func TestBytesConcat(t *testing.T) {
Py_Initialize()
s1 := "aaaaaaaa"
s2 := "bbbbbbbb"
bytes1 := PyBytes_FromString(s1)
array := PyByteArray_FromStringAndSize(s2)
defer array.DecRef()
bytes2 := PyBytes_FromObject(array)
assert.NotNil(t, bytes2)
bytes1 = PyBytes_Concat(bytes1, bytes2)
assert.NotNil(t, bytes1)
defer bytes1.DecRef()
assert.Equal(t, s1+s2, PyBytes_AsString(bytes1))
}
func TestBytesConcatAndDel(t *testing.T) {
Py_Initialize()
s1 := "aaaaaaaa"
s2 := "bbbbbbbb"
bytes1 := PyBytes_FromString(s1)
bytes2 := PyBytes_FromString(s2)
assert.NotNil(t, bytes2)
bytes1 = PyBytes_ConcatAndDel(bytes1, bytes2)
assert.NotNil(t, bytes1)
defer bytes1.DecRef()
assert.Equal(t, s1+s2, PyBytes_AsString(bytes1))
}