Skip to content

Commit 8cd903b

Browse files
committed
test: remove special inline tests
1 parent ae80dc7 commit 8cd903b

File tree

1 file changed

+34
-43
lines changed

1 file changed

+34
-43
lines changed

internal/runtime/python/python_test.go

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ func Test_Python_IgnoreDirectories(t *testing.T) {
6969

7070
func Test_Python_InstallProjectDependencies(t *testing.T) {
7171
tests := []struct {
72-
name string
73-
existingFiles map[string]string
74-
expectedFiles map[string]string
75-
expectedOutputs string
76-
expectedError bool
72+
name string
73+
existingFiles map[string]string
74+
expectedFiles map[string]string
75+
expectedOutputs []string
76+
notExpectedOutputs []string
77+
expectedError bool
7778
}{
7879
{
7980
name: "Error when requirements.txt is missing",
8081
existingFiles: map[string]string{}, // No files
81-
expectedOutputs: "Error",
82+
expectedOutputs: []string{"Error"},
8283
expectedError: true,
8384
},
8485
{
@@ -89,7 +90,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
8990
expectedFiles: map[string]string{
9091
"requirements.txt": "slack-cli-hooks\npytest==8.3.2\nruff==0.7.2",
9192
},
92-
expectedOutputs: "Found",
93+
expectedOutputs: []string{"Found"},
9394
expectedError: false,
9495
},
9596
{
@@ -100,7 +101,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
100101
expectedFiles: map[string]string{
101102
"requirements.txt": "slack-cli-hooks<1.0.0\npytest==8.3.2\nruff==0.7.2",
102103
},
103-
expectedOutputs: "Found",
104+
expectedOutputs: []string{"Found"},
104105
expectedError: false,
105106
},
106107
{
@@ -111,7 +112,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
111112
expectedFiles: map[string]string{
112113
"requirements.txt": "slack-bolt==2.31.2\nslack-cli-hooks<1.0.0\npytest==8.3.2\nruff==0.7.2",
113114
},
114-
expectedOutputs: "Updated",
115+
expectedOutputs: []string{"Updated"},
115116
expectedError: false,
116117
},
117118
{
@@ -122,7 +123,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
122123
expectedFiles: map[string]string{
123124
"requirements.txt": "pytest==8.3.2\nslack-bolt==2.31.2\nslack-cli-hooks<1.0.0\nruff==0.7.2",
124125
},
125-
expectedOutputs: "Updated",
126+
expectedOutputs: []string{"Updated"},
126127
expectedError: false,
127128
},
128129
{
@@ -133,7 +134,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
133134
expectedFiles: map[string]string{
134135
"requirements.txt": "pytest==8.3.2\nruff==0.7.2\nslack-bolt==2.31.2\nslack-cli-hooks<1.0.0",
135136
},
136-
expectedOutputs: "Updated",
137+
expectedOutputs: []string{"Updated"},
137138
expectedError: false,
138139
},
139140
{
@@ -144,7 +145,7 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
144145
expectedFiles: map[string]string{
145146
"requirements.txt": "pytest==8.3.2\nruff==0.7.2\nslack-cli-hooks<1.0.0",
146147
},
147-
expectedOutputs: "Updated",
148+
expectedOutputs: []string{"Updated"},
148149
expectedError: false,
149150
},
150151
{
@@ -155,24 +156,25 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
155156
expectedFiles: map[string]string{
156157
"requirements.txt": "pytest==8.3.2\nruff==0.7.2\nslack-cli-hooks<1.0.0",
157158
},
158-
expectedOutputs: "Updated",
159+
expectedOutputs: []string{"Updated"},
159160
expectedError: false,
160161
},
161162
{
162163
name: "Should output help text because installing project dependencies is unsupported",
163164
existingFiles: map[string]string{
164165
"requirements.txt": "slack-cli-hooks\npytest==8.3.2\nruff==0.7.2",
165166
},
167+
expectedOutputs: []string{"Manually setup a Python virtual environment"},
166168
expectedError: false,
167-
expectedOutputs: "Manually setup a Python virtual environment",
168169
},
169170
{
170171
name: "Should output pip install -r requirements.txt when only requirements.txt exists",
171172
existingFiles: map[string]string{
172173
"requirements.txt": "slack-cli-hooks\npytest==8.3.2",
173174
},
174-
expectedError: false,
175-
expectedOutputs: "pip install -r requirements.txt",
175+
expectedOutputs: []string{"pip install -r requirements.txt"},
176+
notExpectedOutputs: []string{"pip install -e ."},
177+
expectedError: false,
176178
},
177179
{
178180
name: "Should output pip install -e . when only pyproject.toml exists",
@@ -181,8 +183,9 @@ func Test_Python_InstallProjectDependencies(t *testing.T) {
181183
name = "my-app"
182184
dependencies = ["slack-cli-hooks<1.0.0"]`,
183185
},
184-
expectedError: false,
185-
expectedOutputs: "pip install -e .",
186+
expectedOutputs: []string{"pip install -e ."},
187+
notExpectedOutputs: []string{"pip install -r requirements.txt"},
188+
expectedError: false,
186189
},
187190
{
188191
name: "Should output both install commands when both files exist",
@@ -192,15 +195,15 @@ dependencies = ["slack-cli-hooks<1.0.0"]`,
192195
name = "my-app"
193196
dependencies = ["slack-cli-hooks<1.0.0"]`,
194197
},
198+
expectedOutputs: []string{"pip install -r requirements.txt", "pip install -e ."},
195199
expectedError: false,
196-
expectedOutputs: "pip install -r requirements.txt",
197200
},
198201
{
199202
name: "Error when neither requirements.txt nor pyproject.toml exists",
200203
existingFiles: map[string]string{
201204
"main.py": "# some python code",
202205
},
203-
expectedOutputs: "Error: no Python dependency file found",
206+
expectedOutputs: []string{"Error: no Python dependency file found"},
204207
expectedError: true,
205208
},
206209
{
@@ -221,7 +224,7 @@ dependencies = [
221224
"pytest==8.3.2",
222225
]`,
223226
},
224-
expectedOutputs: "Found pyproject.toml",
227+
expectedOutputs: []string{"Found pyproject.toml"},
225228
expectedError: false,
226229
},
227230
{
@@ -243,7 +246,7 @@ dependencies = [
243246
"slack-cli-hooks<1.0.0",
244247
]`,
245248
},
246-
expectedOutputs: "Updated pyproject.toml",
249+
expectedOutputs: []string{"Updated pyproject.toml"},
247250
expectedError: false,
248251
},
249252
{
@@ -263,7 +266,7 @@ dependencies = [
263266
"slack-cli-hooks<1.0.0",
264267
]`,
265268
},
266-
expectedOutputs: "Updated pyproject.toml",
269+
expectedOutputs: []string{"Updated pyproject.toml"},
267270
expectedError: false,
268271
},
269272
{
@@ -285,7 +288,7 @@ dependencies = [
285288
"slack-cli-hooks<1.0.0",
286289
]`,
287290
},
288-
expectedOutputs: "Updated requirements.txt",
291+
expectedOutputs: []string{"Updated requirements.txt"},
289292
expectedError: false,
290293
},
291294
{
@@ -294,7 +297,7 @@ dependencies = [
294297
"pyproject.toml": `[project]
295298
name = "my-app"`,
296299
},
297-
expectedOutputs: "Error: pyproject.toml missing dependencies array",
300+
expectedOutputs: []string{"Error: pyproject.toml missing dependencies array"},
298301
expectedError: true,
299302
},
300303
{
@@ -303,7 +306,7 @@ name = "my-app"`,
303306
"pyproject.toml": `[tool.black]
304307
line-length = 88`,
305308
},
306-
expectedOutputs: "Error: pyproject.toml missing [project] section",
309+
expectedOutputs: []string{"Error: pyproject.toml missing project section"},
307310
expectedError: true,
308311
},
309312
{
@@ -312,7 +315,7 @@ line-length = 88`,
312315
"pyproject.toml": `[project
313316
name = "broken`,
314317
},
315-
expectedOutputs: "Error parsing pyproject.toml",
318+
expectedOutputs: []string{"Error parsing pyproject.toml"},
316319
expectedError: true,
317320
},
318321
}
@@ -356,24 +359,12 @@ name = "broken`,
356359
require.Equal(t, fileData, string(d))
357360
}
358361

359-
require.Contains(t, outputs, tt.expectedOutputs)
360-
361-
// Special check for when both files exist - should show both install commands
362-
if tt.name == "Should output both install commands when both files exist" {
363-
require.Contains(t, outputs, "pip install -r requirements.txt", "Should contain requirements.txt install command")
364-
require.Contains(t, outputs, "pip install -e .", "Should contain pyproject.toml install command")
365-
}
366-
367-
// Special check to ensure only requirements.txt command appears
368-
if tt.name == "Should output pip install -r requirements.txt when only requirements.txt exists" {
369-
require.Contains(t, outputs, "pip install -r requirements.txt")
370-
require.NotContains(t, outputs, "pip install -e .", "Should NOT contain pyproject.toml install command when only requirements.txt exists")
362+
for _, expected := range tt.expectedOutputs {
363+
require.Contains(t, outputs, expected)
371364
}
372365

373-
// Special check to ensure only pyproject.toml command appears
374-
if tt.name == "Should output pip install -e . when only pyproject.toml exists" {
375-
require.Contains(t, outputs, "pip install -e .")
376-
require.NotContains(t, outputs, "pip install -r requirements.txt", "Should NOT contain requirements.txt install command when only pyproject.toml exists")
366+
for _, notExpected := range tt.notExpectedOutputs {
367+
require.NotContains(t, outputs, notExpected)
377368
}
378369

379370
if tt.expectedError {

0 commit comments

Comments
 (0)