Skip to content

Commit

Permalink
_examples,bind: add a test for types.Named
Browse files Browse the repository at this point in the history
This CL adds a test for #220.
  • Loading branch information
cosnicolaou committed Mar 27, 2020
1 parent 87be7f7 commit ac88620
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
7 changes: 7 additions & 0 deletions _examples/structs/structs.go
Expand Up @@ -27,3 +27,10 @@ type S2 struct {
Public int
private int
}

type Dim int

type S3 struct {
X Dim
Y Dim
}
22 changes: 17 additions & 5 deletions _examples/structs/test.py
Expand Up @@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

## py2/py3 compat
# py2/py3 compat
from __future__ import print_function

import structs
Expand All @@ -16,7 +16,7 @@

print("s1 = structs.S1()")
s1 = structs.S1()
print("s1 = %s" %(s1,))
print("s1 = %s" % (s1,))

try:
s1 = structs.S1(1)
Expand All @@ -31,17 +31,17 @@
print("caught error: %s" % (err,))
pass


print("s2 = structs.S2()")
s2 = structs.S2(1)
print("s2 = %s" % (s2,))

try:
s2 = structs.S2(1,2)
s2 = structs.S2(1, 2)
except Exception as err:
print("caught error: %s" % (err,))
pass

try:
s2 = structs.S2(42)
print("s2 = %s" % (s2,))
Expand All @@ -51,14 +51,17 @@
print("caught error: %s" % (err,))
pass


class S2Child(structs.S2):
def __init__(self, a, b):
super(S2Child, self).__init__(a)
self.local = b

def __str__(self):
return ("S2Child{S2: %s, local: %d}"
% (super(S2Child, self).__str__(), self.local))


try:
s2child = S2Child(42, 123)
print("s2child = %s" % (s2child,))
Expand All @@ -69,4 +72,13 @@ def __str__(self):
print("caught error: %s" % (err,))
pass

try:
val = structs.S3()
val.X = 3
val.Y = 4
print("s3.X,Y = %d,%d" % (val.X, val.Y))
except Exception as err:
print("caught error: %s" % (err,))
pass

print("OK")
1 change: 1 addition & 0 deletions bind/gen_struct.go
Expand Up @@ -299,6 +299,7 @@ func (g *pyGen) genIfaceInit(ifc *Interface) {
handle=A Go-side object is always initialized with an explicit handle=arg
"""
`)

g.pywrap.Printf("if len(kwargs) == 1 and 'handle' in kwargs:\n")
g.pywrap.Indent()
g.pywrap.Printf("self.handle = kwargs['handle']\n")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -6,5 +6,5 @@ require (
github.com/gonuts/commander v0.1.0
github.com/gonuts/flag v0.1.0
github.com/pkg/errors v0.8.1
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f
golang.org/x/tools v0.0.0-20200326194725-b1df9901287c
)
12 changes: 12 additions & 0 deletions go.sum
Expand Up @@ -4,11 +4,23 @@ github.com/gonuts/flag v0.1.0 h1:fqMv/MZ+oNGu0i9gp0/IQ/ZaPIDoAZBOBaJoV7viCWM=
github.com/gonuts/flag v0.1.0/go.mod h1:ZTmTGtrSPejTo/SRNhCqwLTmiAgyBdCkLYhHrAoBdz4=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f h1:ESK9Jb5JOE+y4u+ozMQeXfMHwEHm6zVbaDQkeaj6wI4=
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200326194725-b1df9901287c h1:lOHr9KzDy5SxEmffvQO+sLmartg6RfDELX60/tv3qFg=
golang.org/x/tools v0.0.0-20200326194725-b1df9901287c/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1 change: 1 addition & 0 deletions main_test.go
Expand Up @@ -390,6 +390,7 @@ s2child = S2Child{S2: structs.S2{Public=42, handle=8, local=123}, local: 123}
s2child.Public = 42
s2child.local = 123
caught error: 'S2Child' object has no attribute 'private'
s3.X,Y = 3,4
OK
`),
})
Expand Down

0 comments on commit ac88620

Please sign in to comment.