Skip to content

Commit e865158

Browse files
committed
examples/{embedding,multi-context}: add LICENSE blurb, cosmetics
Signed-off-by: Sebastien Binet <binet@cern.ch>
1 parent 7f55cd3 commit e865158

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

examples/embedding/lib/REPL-startup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
1+
# Copyright 2022 The go-python Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
24

35
# This file is called from main.go when in REPL mode
46

examples/embedding/lib/mylib.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2022 The go-python Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
15
import mylib_go as _go
26

37
PY_VERSION = _go.PY_VERSION
@@ -47,5 +51,3 @@ def PrintItinerary(self):
4751
i += 1
4852

4953
print("### Made with %s " % self._libVers)
50-
51-

examples/embedding/main_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The go-python Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package main
26

37
import (
@@ -9,8 +13,6 @@ import (
913
"testing"
1014
)
1115

12-
const embeddingTestOutput = "testdata/embedding_out_golden.txt"
13-
1416
var regen = flag.Bool("regen", false, "regenerate golden files")
1517

1618
func TestEmbeddedExample(t *testing.T) {
@@ -25,33 +27,36 @@ func TestEmbeddedExample(t *testing.T) {
2527
cmd := exec.Command("go", "build", "-o", exe, ".")
2628
err = cmd.Run()
2729
if err != nil {
28-
t.Fatalf("failed to compile embedding example: %v", err)
30+
t.Fatalf("failed to compile embedding example: %+v", err)
2931
}
3032

3133
out := new(bytes.Buffer)
3234
cmd = exec.Command(exe, "mylib-demo.py")
3335
cmd.Stdout = out
36+
cmd.Stderr = out
3437

3538
err = cmd.Run()
3639
if err != nil {
37-
t.Fatalf("failed to run embedding binary: %v", err)
40+
t.Fatalf("failed to run embedding binary: %+v", err)
3841
}
3942

40-
testOutput := out.Bytes()
43+
const fname = "testdata/embedding_out_golden.txt"
44+
45+
got := out.Bytes()
4146

4247
flag.Parse()
4348
if *regen {
44-
err = os.WriteFile(embeddingTestOutput, testOutput, 0644)
49+
err = os.WriteFile(fname, got, 0644)
4550
if err != nil {
46-
t.Fatalf("failed to write test output: %v", err)
51+
t.Fatalf("could not write golden file: %+v", err)
4752
}
4853
}
4954

50-
mustMatch, err := os.ReadFile(embeddingTestOutput)
55+
want, err := os.ReadFile(fname)
5156
if err != nil {
52-
t.Fatalf("failed read %q", embeddingTestOutput)
57+
t.Fatalf("could not read golden file: %+v", err)
5358
}
54-
if !bytes.Equal(testOutput, mustMatch) {
55-
t.Fatalf("embedded test output did not match accepted output from %q", embeddingTestOutput)
59+
if !bytes.Equal(got, want) {
60+
t.Fatalf("stdout differ:\ngot:\n%s\nwant:\n%s\n", got, want)
5661
}
5762
}

examples/embedding/mylib-demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2022 The go-python Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
15
print('''
26
Welcome to a gpython embedded example,
37
where your wildest Go-based python dreams come true!''')

examples/multi-context/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func main() {
3636
// Give each trial a fresh start
3737
runtime.GC()
3838
}
39-
4039
}
4140

4241
var jobScript = `

0 commit comments

Comments
 (0)