object-mother-pattern


Nameobject-mother-pattern JSON
Version 3.5.0 PyPI version JSON
download
home_pageNone
SummaryThe Object Mother Pattern is a Python package that simplifies and standardizes the creation of test objects.
upload_time2025-08-26 08:38:27
maintainerNone
docs_urlNone
authorAdria Montoto
requires_python>=3.11
licenseNone
keywords development object-mother pattern python testing tools utilities validation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <a name="readme-top"></a>

# โš’๏ธ Object Mother Pattern

<p align="center">
    <a href="https://github.com/adriamontoto/object-mother-pattern/actions/workflows/ci.yaml?event=push&branch=master" target="_blank">
        <img src="https://github.com/adriamontoto/object-mother-pattern/actions/workflows/ci.yaml/badge.svg?event=push&branch=master" alt="CI Pipeline">
    </a>
    <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/adriamontoto/object-mother-pattern" target="_blank">
        <img src="https://coverage-badge.samuelcolvin.workers.dev/adriamontoto/object-mother-pattern.svg" alt="Coverage Pipeline">
    </a>
    <a href="https://pypi.org/project/object-mother-pattern" target="_blank">
        <img src="https://img.shields.io/pypi/v/object-mother-pattern?color=%2334D058&label=pypi%20package" alt="Package Version">
    </a>
    <a href="https://pypi.org/project/object-mother-pattern/" target="_blank">
        <img src="https://img.shields.io/pypi/pyversions/object-mother-pattern.svg?color=%2334D058" alt="Supported Python Versions">
    </a>
    <a href="https://pepy.tech/projects/object-mother-pattern" target="_blank">
        <img src="https://static.pepy.tech/badge/object-mother-pattern/month" alt="Package Downloads">
    </a>
    <a href="https://deepwiki.com/adriamontoto/object-mother-pattern" target="_blank">
        <img src="https://img.shields.io/badge/DeepWiki-adriamontoto%2Fobject--mother--pattern-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==" alt="Project Documentation">
    </a>
</p>

The **Object Mother Pattern** is a Python ๐Ÿ package that simplifies and standardizes the creation of test ๐Ÿงช objects. This pattern is especially helpful in testing scenarios where you need to generate multiple instances of complex objects quickly and consistently. By providing a set of prebuilt ๐Ÿ› ๏ธ object mothers, you can drop these into your existing test suite and skip the boilerplate setup yourself.
<br><br>

## Table of Contents

- [๐Ÿ“ฅ Installation](#installation)
- [๐Ÿ“š Documentation](#-documentation)
- [๐Ÿ’ป Utilization](#utilization)
  - [๐Ÿ“ƒ Available Mothers](#available-mothers)
  - [๐ŸŽ„ Real-Life Case: Christmas Detector Service](#real-life-case-christmas-detector-service)
  - [๐Ÿง‘โ€๐Ÿ”ง Creating your own Object Mother](#creating-your-own-object-mother)
- [๐Ÿค Contributing](#contributing)
- [๐Ÿ”‘ License](#license)

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="installation"></a>

## ๐Ÿ“ฅ Installation

You can install **Object Mother Pattern** using `pip`:

```bash
pip install object-mother-pattern
```

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="documentation"></a>

## ๐Ÿ“š Documentation

This [project's documentation](https://deepwiki.com/adriamontoto/object-mother-pattern) is powered by DeepWiki, which provides a comprehensive overview of the **Object Mother Pattern** and its usage.

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="utilization"></a>

## ๐Ÿ’ป Utilization

Here is how you can utilize the **Object Mother** library to generate various types of test data:

```python
from object_mother_pattern import (
    BooleanMother,
    FloatMother,
    IntegerMother,
    StringDateMother,
    StringMother,
    UuidMother,
)

# Generate a random integer between -4 and 15
number = IntegerMother.create(min=-4, max=15)
print(number)
# >>> 8

# Generate a random float between -4 and 15 with 5 Decimal Places
number = FloatMother.create(min=-4, max=15, decimals=5)
print(number)
# >>> 0.83396

# Generate a random boolean
boolean = BooleanMother.create()
print(boolean)
# >>> True

# Generate a random string
string = StringMother.create()
print(string)
# >>> zFUmlsODZqzwyGjrOOqBtYzNwlJdOETalkXbuSegoQpgEnYQTCDeoifWrTQXMm

# Generate a random string of specific length
string = StringMother.of_length(length=10)
print(string)
# >>> TfkrYRxUFT

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

# Generate a random date
date = StringDateMother.create()
print(date)
# >>> 2015-09-15
```

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="available-mothers"></a>

## ๐Ÿ“ƒ Available Mothers

The package offers a wide collection of object mothers grouped by domain:

### Primitives

- [`object_mother_pattern.BooleanMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/boolean_mother.py) - Responsible for generating random boolean values.
- [`object_mother_pattern.BytesMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/bytes_mother.py) - Responsible for generating random bytes objects.
- [`object_mother_pattern.FloatMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/float_mother.py) - Responsible for generating random float values within a range.
- [`object_mother_pattern.IntegerMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/integer_mother.py) - Responsible for generating random integer numbers within a range.
- [`object_mother_pattern.StringMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/string_mother.py) - Responsible for generating random strings with configurable length and characters.

### Dates

- [`object_mother_pattern.DateMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/date/date_mother.py) - Responsible for generating random date instances.
- [`object_mother_pattern.DatetimeMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/datetime/datetime_mother.py) - Responsible for generating random datetime instances.
- [`object_mother_pattern.StringDateMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/date/string_date_mother.py) - Responsible for generating ISO formatted date strings.
- [`object_mother_pattern.StringDatetimeMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/datetime/string_datetime_mother.py) - Responsible for generating ISO 8601 formatted datetime strings.
- [`object_mother_pattern.mothers.dates.TimezoneMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/timezone/timezone_mother.py) - Responsible for generating random timezone objects.
- [`object_mother_pattern.mothers.dates.StringTimezoneMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/timezone/string_timezone_mother.py) - Responsible for generating timezone names as strings.

### Identifiers

- [`object_mother_pattern.UuidMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/uuid_mother.py) - Responsible for generating random UUIDv4 values.
- [`object_mother_pattern.StringUuidMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/string_uuid_mother.py) - Responsible for generating UUIDv4 as strings.
- [`object_mother_pattern.mothers.identifiers.countries.spain.DniMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/countries/spain/dni_mother.py) - Responsible for generating valid Spanish DNI numbers.
- [`object_mother_pattern.mothers.identifiers.countries.spain.NieMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/countries/spain/nie_mother.py) - Responsible for generating valid Spanish NIE numbers.

### Internet

- [`object_mother_pattern.mothers.internet.AwsCloudRegionMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/aws_cloud_region_mother.py) - Responsible for generating AWS region codes.
- [`object_mother_pattern.mothers.internet.DomainMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/domain_mother.py) - Responsible for generating domain names with valid TLDs.
- [`object_mother_pattern.mothers.internet.Ipv4AddressMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv4_address_mother.py) - Responsible for generating IPv4 addresses.
- [`object_mother_pattern.mothers.internet.Ipv4NetworkMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv4_network_mother.py) - Responsible for generating IPv4 network ranges.
- [`object_mother_pattern.mothers.internet.Ipv6AddressMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv6_address_mother.py) - Responsible for generating IPv6 addresses.
- [`object_mother_pattern.mothers.internet.Ipv6NetworkMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv6_network_mother.py) - Responsible for generating IPv6 network ranges.
- [`object_mother_pattern.mothers.internet.MacAddressMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/mac_address_mother.py) - Responsible for generating MAC addresses in various formats.
- [`object_mother_pattern.mothers.internet.PortMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/port_mother.py) - Responsible for generating network port numbers.

### Money

- [`object_mother_pattern.mothers.money.cryptocurrencies.BtcWalletMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/money/cryptocurrencies/btc_wallet_mother.py) - Responsible for generating Bitcoin wallet addresses using BIP39 words list.

### People

- [`object_mother_pattern.mothers.people.FullNameMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/people/full_name_mother.py) - Responsible for generating realistic full names.
- [`object_mother_pattern.mothers.people.PasswordMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/people/password_mother.py) - Responsible for generating password strings with strength options.
- [`object_mother_pattern.mothers.people.UsernameMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/people/username_mother.py) - Responsible for generating username strings.

### Extra

- [`object_mother_pattern.mothers.extra.TextMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/extra/text_mother.py) - Responsible for generating random text snippets.

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="real-life-case-christmas-detector-service"></a>

### ๐ŸŽ„ Real-Life Case: Christmas Detector Service

Below is an example of a real-life scenario where **Object Mother Pattern** can help simplify test date creation. We have a `ChristmasDetectorService` that checks if a given date falls within a specific Christmas holiday range. Using the [`DateMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/date/date_mother.py) class, we can easily generate dates both within and outside of this range for our tests, this ensuring that every possible scenario is covered.

```python
from datetime import date
from object_mother_pattern import DateMother


class ChristmasDetectorService:
    def __init__(self) -> None:
        self.christmas_start = date(year=2024, month=12, day=24)
        self.christmas_end = date(year=2025, month=1, day=6)

    def is_christmas(self, today: date) -> bool:
        return self.christmas_start <= today <= self.christmas_end


christmas_detector_service = ChristmasDetectorService()


def test_christmas_detector_is_christmas() -> None:
    date_mother = DateMother.create(
        start_date=date(year=2024, month=12, day=25),
        end_date=date(year=2025, month=1, day=6),
    )

    assert christmas_detector_service.is_christmas(today=date_mother)


def test_christmas_detector_is_not_christmas() -> None:
    date_mother = DateMother.out_of_range(
        start_date=date(year=2024, month=12, day=24),
        end_date=date(year=2025, month=1, day=6),
    )

    assert not christmas_detector_service.is_christmas(today=date_mother)
```

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="creating-your-own-object-mother"></a>

### ๐Ÿง‘โ€๐Ÿ”ง Creating your own Object Mother

You can extend the functionality of this library by subclassing the
[`BaseMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/models/base_mother.py)
class. Your custom mother must implement the `create` method to generate the
desired type.

```python
from random import randint

from object_mother_pattern.models import BaseMother


class IntegerMother(BaseMother[int]):
    @classmethod
    def create(cls, *, value: int | None = None, min: int = -100, max: int = 100) -> int:
        if value is not None:
            if not isinstance(value, int):
                raise TypeError('IntegerMother value must be an integer.')

            return value

        return randint(a=min, b=max)
```

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="contributing"></a>

## ๐Ÿค Contributing

We love community help! Before you open an issue or pull request, please read:

- [`๐Ÿค How to Contribute`](https://github.com/adriamontoto/object-mother-pattern/blob/master/.github/CONTRIBUTING.md)
- [`๐Ÿงญ Code of Conduct`](https://github.com/adriamontoto/object-mother-pattern/blob/master/.github/CODE_OF_CONDUCT.md)
- [`๐Ÿ” Security Policy`](https://github.com/adriamontoto/object-mother-pattern/blob/master/.github/SECURITY.md)

_Thank you for helping make **โš’๏ธ Object Mother Pattern** package awesome! ๐ŸŒŸ_

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p><br><br>

<a name="license"></a>

## ๐Ÿ”‘ License

This project is licensed under the terms of the [`MIT license`](https://github.com/adriamontoto/object-mother-pattern/blob/master/LICENSE.md).

<p align="right">
    <a href="#readme-top">๐Ÿ”ผ Back to top</a>
</p>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "object-mother-pattern",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "development, object-mother, pattern, python, testing, tools, utilities, validation",
    "author": "Adria Montoto",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/bf/b8/bf9959aa930cd5b64a71c8889dd13d80abe3f9d0380f82aa25cc15e00e82/object_mother_pattern-3.5.0.tar.gz",
    "platform": null,
    "description": "<a name=\"readme-top\"></a>\n\n# \u2692\ufe0f Object Mother Pattern\n\n<p align=\"center\">\n    <a href=\"https://github.com/adriamontoto/object-mother-pattern/actions/workflows/ci.yaml?event=push&branch=master\" target=\"_blank\">\n        <img src=\"https://github.com/adriamontoto/object-mother-pattern/actions/workflows/ci.yaml/badge.svg?event=push&branch=master\" alt=\"CI Pipeline\">\n    </a>\n    <a href=\"https://coverage-badge.samuelcolvin.workers.dev/redirect/adriamontoto/object-mother-pattern\" target=\"_blank\">\n        <img src=\"https://coverage-badge.samuelcolvin.workers.dev/adriamontoto/object-mother-pattern.svg\" alt=\"Coverage Pipeline\">\n    </a>\n    <a href=\"https://pypi.org/project/object-mother-pattern\" target=\"_blank\">\n        <img src=\"https://img.shields.io/pypi/v/object-mother-pattern?color=%2334D058&label=pypi%20package\" alt=\"Package Version\">\n    </a>\n    <a href=\"https://pypi.org/project/object-mother-pattern/\" target=\"_blank\">\n        <img src=\"https://img.shields.io/pypi/pyversions/object-mother-pattern.svg?color=%2334D058\" alt=\"Supported Python Versions\">\n    </a>\n    <a href=\"https://pepy.tech/projects/object-mother-pattern\" target=\"_blank\">\n        <img src=\"https://static.pepy.tech/badge/object-mother-pattern/month\" alt=\"Package Downloads\">\n    </a>\n    <a href=\"https://deepwiki.com/adriamontoto/object-mother-pattern\" target=\"_blank\">\n        <img src=\"https://img.shields.io/badge/DeepWiki-adriamontoto%2Fobject--mother--pattern-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==\" alt=\"Project Documentation\">\n    </a>\n</p>\n\nThe **Object Mother Pattern** is a Python \ud83d\udc0d package that simplifies and standardizes the creation of test \ud83e\uddea objects. This pattern is especially helpful in testing scenarios where you need to generate multiple instances of complex objects quickly and consistently. By providing a set of prebuilt \ud83d\udee0\ufe0f object mothers, you can drop these into your existing test suite and skip the boilerplate setup yourself.\n<br><br>\n\n## Table of Contents\n\n- [\ud83d\udce5 Installation](#installation)\n- [\ud83d\udcda Documentation](#-documentation)\n- [\ud83d\udcbb Utilization](#utilization)\n  - [\ud83d\udcc3 Available Mothers](#available-mothers)\n  - [\ud83c\udf84 Real-Life Case: Christmas Detector Service](#real-life-case-christmas-detector-service)\n  - [\ud83e\uddd1\u200d\ud83d\udd27 Creating your own Object Mother](#creating-your-own-object-mother)\n- [\ud83e\udd1d Contributing](#contributing)\n- [\ud83d\udd11 License](#license)\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"installation\"></a>\n\n## \ud83d\udce5 Installation\n\nYou can install **Object Mother Pattern** using `pip`:\n\n```bash\npip install object-mother-pattern\n```\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"documentation\"></a>\n\n## \ud83d\udcda Documentation\n\nThis [project's documentation](https://deepwiki.com/adriamontoto/object-mother-pattern) is powered by DeepWiki, which provides a comprehensive overview of the **Object Mother Pattern** and its usage.\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"utilization\"></a>\n\n## \ud83d\udcbb Utilization\n\nHere is how you can utilize the **Object Mother** library to generate various types of test data:\n\n```python\nfrom object_mother_pattern import (\n    BooleanMother,\n    FloatMother,\n    IntegerMother,\n    StringDateMother,\n    StringMother,\n    UuidMother,\n)\n\n# Generate a random integer between -4 and 15\nnumber = IntegerMother.create(min=-4, max=15)\nprint(number)\n# >>> 8\n\n# Generate a random float between -4 and 15 with 5 Decimal Places\nnumber = FloatMother.create(min=-4, max=15, decimals=5)\nprint(number)\n# >>> 0.83396\n\n# Generate a random boolean\nboolean = BooleanMother.create()\nprint(boolean)\n# >>> True\n\n# Generate a random string\nstring = StringMother.create()\nprint(string)\n# >>> zFUmlsODZqzwyGjrOOqBtYzNwlJdOETalkXbuSegoQpgEnYQTCDeoifWrTQXMm\n\n# Generate a random string of specific length\nstring = StringMother.of_length(length=10)\nprint(string)\n# >>> TfkrYRxUFT\n\n# Generate a random UUID\nuuid = UuidMother.create()\nprint(uuid)\n# >>> 3e9e0f3a-64a3-474f-9127-368e723f389f\n\n# Generate a random date\ndate = StringDateMother.create()\nprint(date)\n# >>> 2015-09-15\n```\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"available-mothers\"></a>\n\n## \ud83d\udcc3 Available Mothers\n\nThe package offers a wide collection of object mothers grouped by domain:\n\n### Primitives\n\n- [`object_mother_pattern.BooleanMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/boolean_mother.py) - Responsible for generating random boolean values.\n- [`object_mother_pattern.BytesMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/bytes_mother.py) - Responsible for generating random bytes objects.\n- [`object_mother_pattern.FloatMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/float_mother.py) - Responsible for generating random float values within a range.\n- [`object_mother_pattern.IntegerMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/integer_mother.py) - Responsible for generating random integer numbers within a range.\n- [`object_mother_pattern.StringMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/primitives/string_mother.py) - Responsible for generating random strings with configurable length and characters.\n\n### Dates\n\n- [`object_mother_pattern.DateMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/date/date_mother.py) - Responsible for generating random date instances.\n- [`object_mother_pattern.DatetimeMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/datetime/datetime_mother.py) - Responsible for generating random datetime instances.\n- [`object_mother_pattern.StringDateMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/date/string_date_mother.py) - Responsible for generating ISO formatted date strings.\n- [`object_mother_pattern.StringDatetimeMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/datetime/string_datetime_mother.py) - Responsible for generating ISO 8601 formatted datetime strings.\n- [`object_mother_pattern.mothers.dates.TimezoneMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/timezone/timezone_mother.py) - Responsible for generating random timezone objects.\n- [`object_mother_pattern.mothers.dates.StringTimezoneMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/timezone/string_timezone_mother.py) - Responsible for generating timezone names as strings.\n\n### Identifiers\n\n- [`object_mother_pattern.UuidMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/uuid_mother.py) - Responsible for generating random UUIDv4 values.\n- [`object_mother_pattern.StringUuidMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/string_uuid_mother.py) - Responsible for generating UUIDv4 as strings.\n- [`object_mother_pattern.mothers.identifiers.countries.spain.DniMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/countries/spain/dni_mother.py) - Responsible for generating valid Spanish DNI numbers.\n- [`object_mother_pattern.mothers.identifiers.countries.spain.NieMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/identifiers/countries/spain/nie_mother.py) - Responsible for generating valid Spanish NIE numbers.\n\n### Internet\n\n- [`object_mother_pattern.mothers.internet.AwsCloudRegionMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/aws_cloud_region_mother.py) - Responsible for generating AWS region codes.\n- [`object_mother_pattern.mothers.internet.DomainMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/domain_mother.py) - Responsible for generating domain names with valid TLDs.\n- [`object_mother_pattern.mothers.internet.Ipv4AddressMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv4_address_mother.py) - Responsible for generating IPv4 addresses.\n- [`object_mother_pattern.mothers.internet.Ipv4NetworkMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv4_network_mother.py) - Responsible for generating IPv4 network ranges.\n- [`object_mother_pattern.mothers.internet.Ipv6AddressMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv6_address_mother.py) - Responsible for generating IPv6 addresses.\n- [`object_mother_pattern.mothers.internet.Ipv6NetworkMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/ipv6_network_mother.py) - Responsible for generating IPv6 network ranges.\n- [`object_mother_pattern.mothers.internet.MacAddressMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/mac_address_mother.py) - Responsible for generating MAC addresses in various formats.\n- [`object_mother_pattern.mothers.internet.PortMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/internet/port_mother.py) - Responsible for generating network port numbers.\n\n### Money\n\n- [`object_mother_pattern.mothers.money.cryptocurrencies.BtcWalletMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/money/cryptocurrencies/btc_wallet_mother.py) - Responsible for generating Bitcoin wallet addresses using BIP39 words list.\n\n### People\n\n- [`object_mother_pattern.mothers.people.FullNameMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/people/full_name_mother.py) - Responsible for generating realistic full names.\n- [`object_mother_pattern.mothers.people.PasswordMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/people/password_mother.py) - Responsible for generating password strings with strength options.\n- [`object_mother_pattern.mothers.people.UsernameMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/people/username_mother.py) - Responsible for generating username strings.\n\n### Extra\n\n- [`object_mother_pattern.mothers.extra.TextMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/extra/text_mother.py) - Responsible for generating random text snippets.\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"real-life-case-christmas-detector-service\"></a>\n\n### \ud83c\udf84 Real-Life Case: Christmas Detector Service\n\nBelow is an example of a real-life scenario where **Object Mother Pattern** can help simplify test date creation. We have a `ChristmasDetectorService` that checks if a given date falls within a specific Christmas holiday range. Using the [`DateMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/mothers/dates/date/date_mother.py) class, we can easily generate dates both within and outside of this range for our tests, this ensuring that every possible scenario is covered.\n\n```python\nfrom datetime import date\nfrom object_mother_pattern import DateMother\n\n\nclass ChristmasDetectorService:\n    def __init__(self) -> None:\n        self.christmas_start = date(year=2024, month=12, day=24)\n        self.christmas_end = date(year=2025, month=1, day=6)\n\n    def is_christmas(self, today: date) -> bool:\n        return self.christmas_start <= today <= self.christmas_end\n\n\nchristmas_detector_service = ChristmasDetectorService()\n\n\ndef test_christmas_detector_is_christmas() -> None:\n    date_mother = DateMother.create(\n        start_date=date(year=2024, month=12, day=25),\n        end_date=date(year=2025, month=1, day=6),\n    )\n\n    assert christmas_detector_service.is_christmas(today=date_mother)\n\n\ndef test_christmas_detector_is_not_christmas() -> None:\n    date_mother = DateMother.out_of_range(\n        start_date=date(year=2024, month=12, day=24),\n        end_date=date(year=2025, month=1, day=6),\n    )\n\n    assert not christmas_detector_service.is_christmas(today=date_mother)\n```\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"creating-your-own-object-mother\"></a>\n\n### \ud83e\uddd1\u200d\ud83d\udd27 Creating your own Object Mother\n\nYou can extend the functionality of this library by subclassing the\n[`BaseMother`](https://github.com/adriamontoto/object-mother-pattern/blob/master/object_mother_pattern/models/base_mother.py)\nclass. Your custom mother must implement the `create` method to generate the\ndesired type.\n\n```python\nfrom random import randint\n\nfrom object_mother_pattern.models import BaseMother\n\n\nclass IntegerMother(BaseMother[int]):\n    @classmethod\n    def create(cls, *, value: int | None = None, min: int = -100, max: int = 100) -> int:\n        if value is not None:\n            if not isinstance(value, int):\n                raise TypeError('IntegerMother value must be an integer.')\n\n            return value\n\n        return randint(a=min, b=max)\n```\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"contributing\"></a>\n\n## \ud83e\udd1d Contributing\n\nWe love community help! Before you open an issue or pull request, please read:\n\n- [`\ud83e\udd1d How to Contribute`](https://github.com/adriamontoto/object-mother-pattern/blob/master/.github/CONTRIBUTING.md)\n- [`\ud83e\udded Code of Conduct`](https://github.com/adriamontoto/object-mother-pattern/blob/master/.github/CODE_OF_CONDUCT.md)\n- [`\ud83d\udd10 Security Policy`](https://github.com/adriamontoto/object-mother-pattern/blob/master/.github/SECURITY.md)\n\n_Thank you for helping make **\u2692\ufe0f Object Mother Pattern** package awesome! \ud83c\udf1f_\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p><br><br>\n\n<a name=\"license\"></a>\n\n## \ud83d\udd11 License\n\nThis project is licensed under the terms of the [`MIT license`](https://github.com/adriamontoto/object-mother-pattern/blob/master/LICENSE.md).\n\n<p align=\"right\">\n    <a href=\"#readme-top\">\ud83d\udd3c Back to top</a>\n</p>\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "The Object Mother Pattern is a Python package that simplifies and standardizes the creation of test objects.",
    "version": "3.5.0",
    "project_urls": {
        "Homepage": "https://github.com/adriamontoto/object-mother-pattern",
        "Issues": "https://github.com/adriamontoto/object-mother-pattern/issues",
        "Repository": "https://github.com/adriamontoto/object-mother-pattern"
    },
    "split_keywords": [
        "development",
        " object-mother",
        " pattern",
        " python",
        " testing",
        " tools",
        " utilities",
        " validation"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "56f951754f3fbeac418af8ffafd8e57836e04003ddf2d8adad98129cb69cb838",
                "md5": "c1d81730cb7dbbedf19ff717ab0dbdf4",
                "sha256": "5cf04cb676780499a90498fa8734a407ba4066232acb6f72c0d6e89e99fe4885"
            },
            "downloads": -1,
            "filename": "object_mother_pattern-3.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c1d81730cb7dbbedf19ff717ab0dbdf4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 111819,
            "upload_time": "2025-08-26T08:38:25",
            "upload_time_iso_8601": "2025-08-26T08:38:25.793496Z",
            "url": "https://files.pythonhosted.org/packages/56/f9/51754f3fbeac418af8ffafd8e57836e04003ddf2d8adad98129cb69cb838/object_mother_pattern-3.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bfb8bf9959aa930cd5b64a71c8889dd13d80abe3f9d0380f82aa25cc15e00e82",
                "md5": "7e28cebaffee8ef523cb59d544483e30",
                "sha256": "4cee5ec565054067cc511b9d7efa3d0296d2f7db40e0898849cb40475325de4b"
            },
            "downloads": -1,
            "filename": "object_mother_pattern-3.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7e28cebaffee8ef523cb59d544483e30",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 75276,
            "upload_time": "2025-08-26T08:38:27",
            "upload_time_iso_8601": "2025-08-26T08:38:27.252211Z",
            "url": "https://files.pythonhosted.org/packages/bf/b8/bf9959aa930cd5b64a71c8889dd13d80abe3f9d0380f82aa25cc15e00e82/object_mother_pattern-3.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-26 08:38:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adriamontoto",
    "github_project": "object-mother-pattern",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "object-mother-pattern"
}
        
Elapsed time: 2.34803s