Skip to content

Commit

Permalink
Example RedHatOfficial#13: Python interpreter cooperation as unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Nov 27, 2019
1 parent 4be2e1e commit 01a7d36
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions testing/goexpect/13_python_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"regexp"
"testing"
"time"

"github.com/google/goexpect"
)

func TestPythonInterpreter(t *testing.T) {
child, _, err := expect.Spawn("python", 2*time.Second)
if err != nil {
t.Fatal(err)
}
t.Log("Python interpreter has been started")

defer child.Close()

_, m, err := child.Expect(regexp.MustCompile("Python ([23])"), 2*time.Second)

err = child.Send("quit()\n")
if err != nil {
t.Fatal(err)
}

if len(m) < 1 {
t.Fatal("No match (should not happen")
}
version := m[1]
t.Log("Detected Python version:", version)
}

0 comments on commit 01a7d36

Please sign in to comment.