Skip to content

Commit

Permalink
🔨 refactor: reorganize mother classes into date and identifier module…
Browse files Browse the repository at this point in the history
…s, update naming conventions
  • Loading branch information
adriamontoto committed Jan 5, 2025
1 parent 675450a commit b125b36
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 144 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ from object_mother_pattern.mothers import (
FloatMother,
BoolMother,
StringMother,
UUIDMother,
UuidMother,
StringDateMother,
)

Expand Down Expand Up @@ -93,7 +93,7 @@ print(string)
# >>> 'TfkrYRxUFT'

# Generate a random UUID
uuid = UUIDMother.create()
uuid = UuidMother.create()
print(uuid)
# >>> '3e9e0f3a-64a3-474f-9127-368e723f389f'

Expand Down
14 changes: 4 additions & 10 deletions object_mother_pattern/mothers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from .additional_types import (
DateMother,
DatetimeMother,
StringDateMother,
StringDatetimeMother,
StringUUIDMother,
UUIDMother,
)
from .dates import DateMother, DatetimeMother, StringDateMother, StringDatetimeMother
from .identifiers import StringUuidMother, UuidMother
from .name_mother import NameMother
from .primitives import BoolMother, BytesMother, FloatMother, IntegerMother, StringMother
from .text_mother import TextMother
Expand All @@ -21,7 +15,7 @@
'StringDateMother',
'StringDatetimeMother',
'StringMother',
'StringUUIDMother',
'StringUuidMother',
'TextMother',
'UUIDMother',
'UuidMother',
)
15 changes: 0 additions & 15 deletions object_mother_pattern/mothers/additional_types/__init__.py

This file was deleted.

9 changes: 9 additions & 0 deletions object_mother_pattern/mothers/dates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .date import DateMother, StringDateMother
from .datetime import DatetimeMother, StringDatetimeMother

__all__ = (
'DateMother',
'DatetimeMother',
'StringDateMother',
'StringDatetimeMother',
)
7 changes: 7 additions & 0 deletions object_mother_pattern/mothers/dates/date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .date_mother import DateMother
from .string_date_mother import StringDateMother

__all__ = (
'DateMother',
'StringDateMother',
)
7 changes: 7 additions & 0 deletions object_mother_pattern/mothers/dates/datetime/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .datetime_mother import DatetimeMother
from .string_datetime_mother import StringDatetimeMother

__all__ = (
'DatetimeMother',
'StringDatetimeMother',
)
7 changes: 7 additions & 0 deletions object_mother_pattern/mothers/identifiers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .string_uuid_mother import StringUuidMother
from .uuid_mother import UuidMother

__all__ = (
'StringUuidMother',
'UuidMother',
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
StringUUIDMother module.
StringUuidMother module.
"""

from random import choice
Expand All @@ -13,15 +13,15 @@
from object_mother_pattern.mothers.base_mother import BaseMother


class StringUUIDMother(BaseMother[str]):
class StringUuidMother(BaseMother[str]):
"""
StringUUIDMother class.
StringUuidMother class.
Example:
```python
from object_mother_pattern.mothers import StringUUIDMother
from object_mother_pattern.mothers import StringUuidMother
uuid = StringUUIDMother.create()
uuid = StringUuidMother.create()
print(uuid)
# >>> 3e9e0f3a-64a3-474f-9127-368e723f389f
```
Expand All @@ -46,16 +46,16 @@ def create(cls, *, value: str | None = None) -> str:
Example:
```python
from object_mother_pattern.mothers import StringUUIDMother
from object_mother_pattern.mothers import StringUuidMother
uuid = StringUUIDMother.create()
uuid = StringUuidMother.create()
print(uuid)
# >>> 3e9e0f3a-64a3-474f-9127-368e723f389f
```
"""
if value is not None:
if type(value) is not str:
raise TypeError('StringUUIDMother value must be a string.')
raise TypeError('StringUuidMother value must be a string.')

return value

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
UUIDMother module.
UuidMother module.
"""

from sys import version_info
Expand All @@ -13,15 +13,15 @@
from object_mother_pattern.mothers.base_mother import BaseMother


class UUIDMother(BaseMother[UUID]):
class UuidMother(BaseMother[UUID]):
"""
UUIDMother class.
UuidMother class.
Example:
```python
from object_mother_pattern.mothers import UUIDMother
from object_mother_pattern.mothers import UuidMother
uuid = UUIDMother.create()
uuid = UuidMother.create()
print(uuid)
# >>> 3e9e0f3a-64a3-474f-9127-368e723f389f
```
Expand All @@ -46,16 +46,16 @@ def create(cls, *, value: UUID | None = None) -> UUID:
Example:
```python
from object_mother_pattern.mothers import UUIDMother
from object_mother_pattern.mothers import UuidMother
uuid = UUIDMother.create()
uuid = UuidMother.create()
print(uuid)
# >>> 3e9e0f3a-64a3-474f-9127-368e723f389f
```
"""
if value is not None:
if type(value) is not UUID:
raise TypeError('UUIDMother value must be a UUID.')
raise TypeError('UuidMother value must be a UUID.')

return value

Expand Down
56 changes: 0 additions & 56 deletions tests/mothers/additional_types/test_string_uuid_mother.py

This file was deleted.

45 changes: 0 additions & 45 deletions tests/mothers/additional_types/test_uuid_mother.py

This file was deleted.

File renamed without changes.
Empty file.
Empty file.
Empty file.
56 changes: 56 additions & 0 deletions tests/mothers/identifiers/test_string_uuid_mother.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Test module for the StringUuidMother class.
"""

from uuid import UUID

from pytest import raises as assert_raises

from object_mother_pattern.mothers import StringUuidMother


def test_string_uuid_mother_happy_path() -> None:
"""
Test StringUuidMother happy path.
"""
value = StringUuidMother.create()

assert type(value) is str
UUID(value)


def test_string_uuid_mother_value() -> None:
"""
Test StringUuidMother create method with value.
"""
value = StringUuidMother.create()

assert StringUuidMother.create(value=value) == value


def test_string_uuid_mother_invalid_type() -> None:
"""
Test StringUuidMother create method with invalid type.
"""
assert type(StringUuidMother.invalid_type()) is not str


def test_string_uuid_mother_invalid_value() -> None:
"""
Test StringUuidMother invalid_value method.
"""
value = StringUuidMother.invalid_value()

assert type(value) is str
assert not value.isprintable()


def test_string_uuid_mother_invalid_value_type() -> None:
"""
Test StringUuidMother create method with invalid value type.
"""
with assert_raises(
expected_exception=TypeError,
match='StringUuidMother value must be a string.',
):
StringUuidMother.create(value=StringUuidMother.invalid_type())
45 changes: 45 additions & 0 deletions tests/mothers/identifiers/test_uuid_mother.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Test module for the UuidMother class.
"""

from uuid import UUID

from pytest import raises as assert_raises

from object_mother_pattern.mothers import UuidMother


def test_uuid_mother_happy_path() -> None:
"""
Test UuidMother happy path.
"""
value = UuidMother.create()

assert type(value) is UUID


def test_uuid_mother_value() -> None:
"""
Test UuidMother create method with value.
"""
value = UuidMother.create()

assert UuidMother.create(value=value) == value


def test_uuid_mother_invalid_type() -> None:
"""
Test UuidMother create method with invalid type.
"""
assert type(UuidMother.invalid_type()) is not UUID


def test_uuid_mother_invalid_value_type() -> None:
"""
Test UuidMother create method with invalid value type.
"""
with assert_raises(
expected_exception=TypeError,
match='UuidMother value must be a UUID.',
):
UuidMother.create(value=UuidMother.invalid_type())

0 comments on commit b125b36

Please sign in to comment.