all: tests more of module generation

This commit is contained in:
Sebastien Binet 2015-07-27 18:46:30 +02:00
parent 878510074c
commit f4f8220837
3 changed files with 60 additions and 4 deletions

View File

@ -49,5 +49,10 @@ func (p Person) String() string {
// Greet sends greetings
func (p *Person) Greet() string {
return p.greet()
}
// greet sends greetings
func (p *Person) greet() string {
return fmt.Sprintf("Hello, I am %s", p.Name)
}

View File

@ -29,12 +29,14 @@ print hi.Person.__doc__
print "--- p = hi.Person()..."
p = hi.Person()
print p
print dir(p)
print "--- p.Name:", p.Name
print "--- p.Age:",p.Age
#print "--- p.Greet()..."
#print p.Greet()
print "--- doc(p):"
print p.__doc__

View File

@ -5,10 +5,12 @@
package main
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"testing"
)
@ -47,13 +49,60 @@ func TestBind(t *testing.T) {
t.Fatalf("error copying 'test.py': %v\n", err)
}
want := []byte(`hi from go
hello you from go
--- doc(hi)...
package hi exposes a few Go functions to be wrapped and used from Python.
--- doc(hi.Hi)...
Hi()
Hi prints hi from Go
--- hi.Hi()...
--- doc(hi.Hello)...
Hello(str s)
Hello prints a greeting from Go
--- hi.Hello('you')...
--- doc(hi.Add)...
Add(int i, int j) int
Add returns the sum of its arguments.
--- hi.Add(1, 41)...
42
--- hi.Concat('4', '2')...
42
--- doc(hi.Person):
Person is a simple struct
--- p = hi.Person()...
['Age', 'Greet', 'Name', 'String', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
--- p.Name: None
--- p.Age: None
--- doc(p):
Person is a simple struct
`)
buf := new(bytes.Buffer)
cmd = exec.Command("python2", "./test.py")
cmd.Dir = workdir
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdout = buf
cmd.Stderr = buf
err = cmd.Run()
if err != nil {
t.Fatal("error running python module: %v\n", err)
t.Fatalf(
"error running python module: %v\n%v\n", err,
string(buf.Bytes()),
)
}
if !reflect.DeepEqual(string(buf.Bytes()), string(want)) {
t.Fatalf("error running python module:\nwant:\n%s\n\ngot:\n%s\n",
string(want), string(buf.Bytes()),
)
}
}