-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_test.go
More file actions
58 lines (45 loc) · 1.18 KB
/
import_test.go
File metadata and controls
58 lines (45 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package python_test
import (
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
python3 "go.nhat.io/python/v3"
)
func TestMustImportModule(t *testing.T) {
module := python3.MustImportModule("sys")
attr := module.GetAttr("platform")
defer attr.DecRef()
actual := python3.AsString(attr)
expected := runtime.GOOS
assert.Equal(t, expected, actual)
}
func TestMustImportModule2_NotExists(t *testing.T) {
err := python3.ModuleNotFoundError{
ImportError: python3.ImportError{
Exception: python3.Exception{
Message: `No module named 'not_exists'`,
},
Module: "not_exists",
Path: "None",
},
}
assert.PanicsWithValue(t, err, func() {
python3.MustImportModule("not_exists")
})
}
func TestImportModule_NotExists(t *testing.T) {
module, actual := python3.ImportModule("not_exists")
require.Nil(t, module)
expected := python3.ModuleNotFoundError{
ImportError: python3.ImportError{
Exception: python3.Exception{
Message: `No module named 'not_exists'`,
},
Module: "not_exists",
Path: "None",
},
}
require.Equal(t, expected, actual)
require.EqualError(t, actual, `No module named 'not_exists'`)
}