Skip to content

Commit 0ca58b2

Browse files
authored
Improve testing UX (#28)
- use proper ids which are being used for visualisation - add .vscode configs
1 parent dfe318c commit 0ca58b2

File tree

5 files changed

+63
-39
lines changed

5 files changed

+63
-39
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,5 @@ cython_debug/
152152
#.idea/
153153

154154
# Example dags for testing
155-
example_dags/
155+
example_dags/*
156+
!.gitkeep

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "airflint",
9+
"type": "python",
10+
"request": "launch",
11+
"module": "airflint",
12+
"justMyCode": true,
13+
"args": ["example_dags/"]
14+
}
15+
]
16+
}

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

example_dags/.gitkeep

Whitespace-only changes.

tests/test_rules.py

+38-38
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
@pytest.mark.parametrize(
1111
"rule, source, expected",
1212
[
13-
(
13+
pytest.param(
1414
UseFunctionLevelImports,
15-
# Test that all required imports within functions are being added to functions.
1615
"""
1716
from functools import reduce
1817
from operator import add
@@ -42,10 +41,10 @@ def other_thing():
4241
import dataclass
4342
return dataclass(something(1, 2))
4443
""",
44+
id="UseFunctionLevelImports | SUCCESS | general",
4545
),
46-
(
46+
pytest.param(
4747
UseFunctionLevelImports,
48-
# Test that it skips the dag decoratored functions.
4948
"""
5049
from airflow.decorators import dag, task
5150
from operator import add
@@ -67,10 +66,10 @@ def my_task():
6766
from operator import add
6867
add(1, 2)
6968
""",
69+
id="UseFunctionLevelImports | SKIP | dag decorator",
7070
),
71-
(
71+
pytest.param(
7272
UseFunctionLevelImports,
73-
# Test that it only adds unique imports i.e. only once
7473
"""
7574
from airflow.decorators import dag, task
7675
from operator import add
@@ -94,10 +93,10 @@ def my_task():
9493
add(1, 2)
9594
add(1, 2)
9695
""",
96+
id="UseFunctionLevelImports | SUCCESS | unique",
9797
),
98-
(
98+
pytest.param(
9999
UseFunctionLevelImports,
100-
# Test that it ignores imports for function decorators.
101100
"""
102101
import random
103102
from airflow import DAG
@@ -119,10 +118,10 @@ def random_choice():
119118
import random
120119
return random.choice(['task_1', 'task_2'])
121120
""",
121+
id="UseFunctionLevelImports | SKIP | function decorators",
122122
),
123-
(
123+
pytest.param(
124124
UseJinjaVariableGet,
125-
# Test that direct assignment of Variable.get is being transformed to jinja equivalent.
126125
"""
127126
from airflow.models import Variable
128127
from operators.fake import FakeOperator
@@ -135,10 +134,10 @@ def random_choice():
135134
136135
FakeOperator(task_id="fake", foo='{{ var.value.FOO }}')
137136
""",
137+
id="UseJinjaVariableGet | SUCCESS | direct assignment with key",
138138
),
139-
(
139+
pytest.param(
140140
UseJinjaVariableGet,
141-
# Test that nothing happens if it cannot import the module.
142141
"""
143142
from airflow.models import Variable
144143
from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator
@@ -151,10 +150,10 @@ def random_choice():
151150
152151
KubernetesPodOperator(task_id="fake", image=Variable.get("FOO"))
153152
""",
153+
id="UseJinjaVariableGet | SKIP | cannot import module",
154154
),
155-
(
155+
pytest.param(
156156
UseJinjaVariableGet,
157-
# Test that nothing happens if the import cannot be reached.
158157
"""
159158
from airflow.models import Variable
160159
@@ -171,10 +170,10 @@ def foo():
171170
172171
FakeOperator(task_id="fake", foo=Variable.get("FOO"))
173172
""",
173+
id="UseJinjaVariableGet | SKIP | cannot reach import",
174174
),
175-
(
175+
pytest.param(
176176
UseJinjaVariableGet,
177-
# Test that nothing happens if it is not in template_fields.
178177
"""
179178
from airflow.models import Variable
180179
from operators.fake import FakeOperator
@@ -187,10 +186,10 @@ def foo():
187186
188187
FakeOperator(task_id="fake", fizz=Variable.get("FOO"))
189188
""",
189+
id="UseJinjaVariableGet | SKIP | keyword not in template_fields",
190190
),
191-
(
191+
pytest.param(
192192
UseJinjaVariableGet,
193-
# Test that variable assignment of Variable.get is being transformed to jinja equivalent.
194193
"""
195194
from airflow.models import Variable
196195
from operators.fake import FakeOperator
@@ -207,10 +206,10 @@ def foo():
207206
208207
FakeOperator(task_id="fake", foo=var)
209208
""",
209+
id="UseJinjaVariableGet | SUCCESS | variable assignment",
210210
),
211-
(
211+
pytest.param(
212212
UseJinjaVariableGet,
213-
# Test that nothing happens if the variable cannot be reached.
214213
"""
215214
from airflow.models import Variable
216215
from operators.fake import FakeOperator
@@ -229,10 +228,10 @@ def foo():
229228
230229
FakeOperator(task_id="fake", foo=var)
231230
""",
231+
id="UseJinjaVariableGet | SKIP | cannot reach variable",
232232
),
233-
(
233+
pytest.param(
234234
UseJinjaVariableGet,
235-
# Test that variable assignment works for multiple keywords.
236235
"""
237236
from airflow.models import Variable
238237
from operators.fake import FakeOperator
@@ -249,10 +248,10 @@ def foo():
249248
250249
FakeOperator(task_id="fake", foo=var, bar=var)
251250
""",
251+
id="UseJinjaVariableGet | SUCCESS | variable assignment with multiple keywords",
252252
),
253-
(
253+
pytest.param(
254254
UseJinjaVariableGet,
255-
# Test that nothing happens if at least one keyword is not in template_fields.
256255
"""
257256
from airflow.models import Variable
258257
from operators.fake import FakeOperator
@@ -269,10 +268,10 @@ def foo():
269268
270269
FakeOperator(task_id="fake", foo=var, fizz=var)
271270
""",
271+
id="UseJinjaVariableGet | SKIP | variable assignment at least one keyword not in template_fields",
272272
),
273-
(
273+
pytest.param(
274274
UseJinjaVariableGet,
275-
# Test that nothing happens if variable is being referenced in multiple Calls where at least one keyword is not in template_fields.
276275
"""
277276
from airflow.models import Variable
278277
from operators.fake import FakeOperator
@@ -291,10 +290,10 @@ def foo():
291290
FakeOperator(task_id="fake", foo=var)
292291
FakeOperator(task_id="fake2", fizz=var)
293292
""",
293+
id="UseJinjaVariableGet | SKIP | variable assignment for multiple calls where at least one keyword is not in template_fields",
294294
),
295-
(
295+
pytest.param(
296296
UseJinjaVariableGet,
297-
# Test that variable assignment works for multiple Calls.
298297
"""
299298
from airflow.models import Variable
300299
from operators.fake import FakeOperator
@@ -313,10 +312,10 @@ def foo():
313312
FakeOperator(task_id="fake", foo=var)
314313
FakeOperator(task_id="fake2", foo=var)
315314
""",
315+
id="UseJinjaVariableGet | SUCCESS | variable assignment for multiple calls",
316316
),
317-
(
317+
pytest.param(
318318
UseJinjaVariableGet,
319-
# Test that nothing happens if the type of Variable.get Calls parent is not implemented e.g. function call
320319
"""
321320
from airflow.models import Variable
322321
from operators.fake import FakeOperator
@@ -329,10 +328,10 @@ def foo():
329328
330329
FakeOperator(task_id="fake", fizz=str(Variable.get("FOO")))
331330
""",
331+
id="UseJinjaVariableGet | SKIP | direct assignment with unimplemented parent type",
332332
),
333-
(
333+
pytest.param(
334334
UseJinjaVariableGet,
335-
# Test that Variable.get calls with deserialize_json works.
336335
"""
337336
from airflow.models import Variable
338337
from operators.fake import FakeOperator
@@ -345,10 +344,10 @@ def foo():
345344
346345
FakeOperator(task_id="fake", foo='{{ var.json.FOO }}')
347346
""",
347+
id="UseJinjaVariableGet | SUCCESS | direct assignment with key and deserialize_json keyword",
348348
),
349-
(
349+
pytest.param(
350350
UseJinjaVariableGet,
351-
# Test that Variable.get calls with default_var works.
352351
"""
353352
from airflow.models import Variable
354353
from operators.fake import FakeOperator
@@ -361,10 +360,10 @@ def foo():
361360
362361
FakeOperator(task_id="fake", foo="{{ var.value.get('FOO', 'BAR') }}")
363362
""",
363+
id="UseJinjaVariableGet | SUCCESS | direct assignment with key and default_var keyword",
364364
),
365-
(
365+
pytest.param(
366366
UseJinjaVariableGet,
367-
# Test that Variable.get calls with default_var=None works.
368367
"""
369368
from airflow.models import Variable
370369
from operators.fake import FakeOperator
@@ -377,10 +376,10 @@ def foo():
377376
378377
FakeOperator(task_id="fake", foo="{{ var.value.get('FOO', None) }}")
379378
""",
379+
id="UseJinjaVariableGet | SUCCESS | direct assignment with key and default_var=None keyword",
380380
),
381-
(
381+
pytest.param(
382382
UseJinjaVariableGet,
383-
# Test that Variable.get calls works with both - deserialize_json and default_var.
384383
"""
385384
from airflow.models import Variable
386385
from operators.fake import FakeOperator
@@ -393,6 +392,7 @@ def foo():
393392
394393
FakeOperator(task_id="fake", foo="{{ var.json.get('FOO', 'BAR') }}")
395394
""",
395+
id="UseJinjaVariableGet | SUCCESS | direct assignment with key, deserialize_json and default_var keywords",
396396
),
397397
],
398398
)

0 commit comments

Comments
 (0)