-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_python_test.go
More file actions
94 lines (85 loc) · 2.05 KB
/
generate_python_test.go
File metadata and controls
94 lines (85 loc) · 2.05 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"os"
"path"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func Test_GeneratePython(t *testing.T) {
type srcContents struct {
path string
data []byte
}
tests := []struct {
name string
testFiles []string
expected string
srcContents []srcContents
}{
{
name: "no requirements.txt no tests",
testFiles: []string{"hello.py"},
expected: "python_no_requirements_no_tests.yaml",
},
{
name: "requirements.txt no tests",
testFiles: []string{"requirements.txt", "hello.py"},
expected: "python_requirements_no_tests.yaml",
},
{
name: "requirements.txt has pytest",
testFiles: []string{"hello.py"},
srcContents: []srcContents{
{
path: "requirements.txt",
data: []byte("pytest==8.1.1"),
},
},
expected: "python_requirements_pytest.yaml",
},
{
name: "no requirements has pytest tests",
srcContents: []srcContents{
{
path: "tests/test_hello.py",
data: []byte("import pytest"),
},
},
expected: "python_no_requirements_has_pytest_tests.yaml",
},
{
name: "has setup.py",
testFiles: []string{"setup.py"},
expected: "python_setup.yaml",
},
{
name: "python undetected",
testFiles: []string{},
expected: "undetected_smoke.yaml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
workflowDir, srcDir := initTest(t, tt.testFiles)
for _, fc := range tt.srcContents {
fp := filepath.Join(srcDir, filepath.Dir(fc.path))
err := os.MkdirAll(fp, 0700)
require.NoError(t, err, "error creating directory path")
name := filepath.Base(fc.path)
err = os.WriteFile(filepath.Join(fp, name), fc.data, 0640)
require.NoError(t, err, "error writing file contents")
}
args := []string{
"--workflow", path.Join(workflowDir, wfFilename),
"--src", srcDir,
"--generator", "python",
}
cmd := GenerateCommand()
cmd.SetArgs(args)
err := cmd.Execute()
require.NoError(t, err)
assertWorkflow(t, workflowDir, tt.expected)
})
}
}