mirror of https://github.com/go-python/gopy.git
_examples,bind: add a test for types.Named
This CL adds a test for #220.
This commit is contained in:
parent
87be7f7b22
commit
ac88620b22
|
@ -27,3 +27,10 @@ type S2 struct {
|
|||
Public int
|
||||
private int
|
||||
}
|
||||
|
||||
type Dim int
|
||||
|
||||
type S3 struct {
|
||||
X Dim
|
||||
Y Dim
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -16,7 +16,7 @@ print("s.Upper('boo')= %s" % repr(s.Upper("boo")).lstrip('u'))
|
|||
|
||||
print("s1 = structs.S1()")
|
||||
s1 = structs.S1()
|
||||
print("s1 = %s" %(s1,))
|
||||
print("s1 = %s" % (s1,))
|
||||
|
||||
try:
|
||||
s1 = structs.S1(1)
|
||||
|
@ -31,17 +31,17 @@ except Exception as err:
|
|||
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,))
|
||||
|
@ -51,14 +51,17 @@ except Exception as err:
|
|||
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,))
|
||||
|
@ -69,4 +72,13 @@ except Exception as err:
|
|||
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")
|
||||
|
|
|
@ -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")
|
||||
|
|
2
go.mod
2
go.mod
|
@ -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
go.sum
12
go.sum
|
@ -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=
|
||||
|
|
|
@ -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
|
||||
`),
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue