Skip to content

Commit c00b290

Browse files
committed
tests added for the new linting check
1 parent 1806273 commit c00b290

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

scripts/tests/test_validate_unwanted_patterns.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,72 @@ def test_strings_with_wrong_placed_whitespace_raises(self, data, expected):
375375
validate_unwanted_patterns.strings_with_wrong_placed_whitespace(fd)
376376
)
377377
assert result == expected
378+
379+
380+
class TestNoDefaultNotUsedForTyping:
381+
@pytest.mark.parametrize(
382+
"data",
383+
[
384+
(
385+
"""
386+
def f(
387+
a: int | NoDefault,
388+
b: float | lib.NoDefault = 0.1,
389+
c: pandas._libs.lib.NoDefault = lib.no_default,
390+
) -> lib.NoDefault | None:
391+
pass
392+
"""
393+
),
394+
(
395+
"""
396+
# var = lib.NoDefault
397+
# the above is incorrect
398+
a: NoDefault | int
399+
b: lib.NoDefault = lib.no_default
400+
"""
401+
),
402+
],
403+
)
404+
def test_nodefault_not_used_for_typing(self, data):
405+
fd = io.StringIO(data.strip())
406+
result = list(validate_unwanted_patterns.nodefault_not_used_for_typing(fd))
407+
assert result == []
408+
409+
@pytest.mark.parametrize(
410+
"data, expected",
411+
[
412+
(
413+
(
414+
"""
415+
def f(
416+
a = lib.NoDefault,
417+
b: Any
418+
= pandas._libs.lib.NoDefault,
419+
):
420+
pass
421+
"""
422+
),
423+
[
424+
(2, "NoDefault is not used for typing"),
425+
(4, "NoDefault is not used for typing"),
426+
],
427+
),
428+
(
429+
(
430+
"""
431+
a: Any = lib.NoDefault
432+
if a is NoDefault:
433+
pass
434+
"""
435+
),
436+
[
437+
(1, "NoDefault is not used for typing"),
438+
(2, "NoDefault is not used for typing"),
439+
],
440+
),
441+
],
442+
)
443+
def test_nodefault_not_used_for_typing_raises(self, data, expected):
444+
fd = io.StringIO(data.strip())
445+
result = list(validate_unwanted_patterns.nodefault_not_used_for_typing(fd))
446+
assert result == expected

0 commit comments

Comments
 (0)