-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rule for duplicate field names (#6)
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import ast | ||
|
||
import pytest | ||
|
||
from flake8_pydantic.errors import PYD006, Error | ||
from flake8_pydantic.visitor import Visitor | ||
|
||
PYD006_1 = """ | ||
class Model(BaseModel): | ||
x: int | ||
x: str = "1" | ||
""" | ||
|
||
PYD006_2 = """ | ||
class Model(BaseModel): | ||
x: int | ||
y: int | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["source", "expected"], | ||
[ | ||
(PYD006_1, [PYD006(4, 4)]), | ||
(PYD006_2, []), | ||
], | ||
) | ||
def test_pyd006(source: str, expected: list[Error]) -> None: | ||
module = ast.parse(source) | ||
visitor = Visitor() | ||
visitor.visit(module) | ||
|
||
assert visitor.errors == expected |