-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only `Factory.build()` and `Factory.create()` are properly typed, provided the class is declared as `class UserFactory(Factory[User]):`. Relies on mypy for tests. Reviewed-By: Raphaël Barrois <[email protected]>
- Loading branch information
1 parent
69809cf
commit 95dfa90
Showing
7 changed files
with
53 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Copyright: See the LICENSE file. | ||
|
||
import sys | ||
|
||
from .base import ( | ||
BaseDictFactory, | ||
BaseListFactory, | ||
|
@@ -70,10 +72,10 @@ | |
pass | ||
|
||
__author__ = 'Raphaël Barrois <[email protected]>' | ||
try: | ||
if sys.version_info >= (3, 8): | ||
# Python 3.8+ | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
else: | ||
import importlib_metadata | ||
|
||
__version__ = importlib_metadata.version("factory_boy") |
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
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 |
---|---|---|
|
@@ -47,6 +47,7 @@ dev = | |
Django | ||
flake8 | ||
isort | ||
mypy | ||
Pillow | ||
SQLAlchemy | ||
sqlalchemy_utils | ||
|
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,28 @@ | ||
# Copyright: See the LICENSE file. | ||
|
||
import dataclasses | ||
import unittest | ||
import typing | ||
|
||
import factory | ||
|
||
|
||
@dataclasses.dataclass | ||
class User: | ||
name: str | ||
email: str | ||
id: int | ||
|
||
|
||
class TypingTests(unittest.TestCase): | ||
def test_simple_factory(self) -> None: | ||
class UserFactory(factory.Factory[User]): | ||
name = "John Doe" | ||
email = "[email protected]" | ||
id = 42 | ||
class Meta: | ||
model = User | ||
|
||
result: User | ||
result = UserFactory.build() | ||
result = UserFactory.create() |