forked from RedHatOfficial/GoCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example RedHatOfficial#13: Python interpreter cooperation as unit test
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |