Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Dec 12, 2023
1 parent c528916 commit 6fa6350
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions __copy_fake.py
19 changes: 10 additions & 9 deletions fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,7 @@ def _apply_traits(cls, instance, **kwargs) -> None:

@classmethod
def create(cls, **kwargs):
model = cls.Meta.model # type: ignore
trait_keys = {
name
for name, method in cls.__dict__.items()
Expand All @@ -1826,7 +1827,7 @@ def create(cls, **kwargs):
{k: v for k, v in kwargs.items() if k not in trait_keys}
)

instance = cls.Meta.model(**model_data)
instance = model(**model_data)
cls._apply_traits(instance, **kwargs)

pre_save_hooks = [
Expand Down Expand Up @@ -1868,7 +1869,7 @@ def save(cls, instance):

@classmethod
def create(cls, **kwargs):
model = cls.Meta.model
model = cls.Meta.model # type: ignore
unique_fields = cls._meta.get("get_or_create", ["id"])

# Construct a query for unique fields
Expand Down Expand Up @@ -1908,7 +1909,7 @@ def create(cls, **kwargs):
)

# Create a new instance if none found
instance = cls.Meta.model(**model_data)
instance = model(**model_data)
cls._apply_traits(instance, **kwargs)

# Handle nested attributes
Expand Down Expand Up @@ -1971,7 +1972,7 @@ async def async_save():

@classmethod
def create(cls, **kwargs):
model = cls.Meta.model
model = cls.Meta.model # type: ignore
unique_fields = cls._meta.get("get_or_create", ["id"])

# Construct a query for unique fields
Expand Down Expand Up @@ -2016,7 +2017,7 @@ async def async_filter():
)

# Create a new instance if none found
instance = cls.Meta.model(**model_data)
instance = model(**model_data)
cls._apply_traits(instance, **kwargs)

# Handle nested attributes
Expand Down Expand Up @@ -2059,15 +2060,15 @@ class SQLAlchemyModelFactory(ModelFactory):

@classmethod
def save(cls, instance):
session = cls.MetaSQLAlchemy.get_session()
session = cls.MetaSQLAlchemy.get_session() # type: ignore
session.add(instance)
session.commit()

@classmethod
def create(cls, **kwargs):
session = cls.MetaSQLAlchemy.get_session()
session = cls.MetaSQLAlchemy.get_session() # type: ignore

model = cls.Meta.model
model = cls.Meta.model # type: ignore
unique_fields = cls._meta.get("get_or_create", ["id"])

# Check for existing instance
Expand Down Expand Up @@ -2708,7 +2709,7 @@ def test_faker_init(self) -> None:
self.assertNotEqual(faker.alias, "default")

def test_get_by_uid(self) -> None:
faker = Faker.get_by_uid("fake.Faker")
faker = Faker.get_by_uid(f"{__name__}.Faker")
self.assertIs(faker, self.faker)

def test_get_by_alias(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ addopts = [
]
testpaths = [
"fake.py",
"__copy_fake.py",
]

[tool.coverage.run]
Expand Down

0 comments on commit 6fa6350

Please sign in to comment.