object-mother-pattern


Nameobject-mother-pattern JSON
Version 2025.1.12 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-01-12 15:25:00
maintainerNone
docs_urlNone
authorAdria Montoto
requires_python>=3.11
licenseNone
keywords development object-mother pattern python testing tools utilities validation
VCS
bugtrack_url
requirements Faker python-dateutil
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/test.yaml?event=push&branch=master" target="_blank">
        <img src="https://github.com/adriamontoto/object-mother-pattern/actions/workflows/test.yaml/badge.svg?event=push&branch=master" alt="Test Pipeline">
    </a>
    <a href="https://github.com/adriamontoto/object-mother-pattern/actions/workflows/lint.yaml?event=push&branch=master" target="_blank">
        <img src="https://github.com/adriamontoto/object-mother-pattern/actions/workflows/lint.yaml/badge.svg?event=push&branch=master" alt="Lint 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>
</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.

Easy to install and integrate, the **Object Mother Pattern** is a must-have for any Python developer looking to simplify their testing workflow, ensure design uniformity, and leverage the full potential of reusable test objects in their projects ๐Ÿš€.
<br><br>

## Table of Contents

- [๐Ÿ“ฅ Installation](#installation)
- [๐Ÿ’ป Utilization](#utilization)
  - [๐ŸŽ„ Real-Life Case: Christmas Detector Service](#real-life-case-christmas-detector-service)
- [๐Ÿค 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="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.mothers import (
    IntegerMother,
    FloatMother,
    BooleanMother,
    StringMother,
    UuidMother,
    StringDateMother,
)

# 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>

<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/additional_types/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.mothers 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="contributing"></a>

## ๐Ÿค Contributing

We welcome contributions to **Object Mother Pattern**! To ensure a smooth collaboration process, please follow the guidelines below.

### How to Contribute

**1. Fork the Repository:** Click the "Fork" button at the top right of the repository page.

**2. Clone Your Fork:**

```bash
git clone git+ssh://git@github.com/<your-username>/object-mother-pattern
```

**3. Create a Branch:**

```bash
git checkout -b feature/your-feature-name
```

**4. Make Your Changes:** Implement your new feature or fix a bug.

**5. Run Tests:** Ensure all the following tests pass before submitting your changes.

- Run tests:

```bash
make test
```

- Run tests with coverage:

```bash
make coverage
```

- Run linter:

```bash
make lint
```

- Run formatter:

```bash
make format
```

**6. Commit Your Changes:**

```bash
git commit -m "โœจ feature: your feature description"
```

**7. Push to Your Fork:**

```bash
git push origin feature/your-feature-name
```

**8. Create a Pull Request:** Navigate to the original repository and create a pull request from your fork.

**9. Wait for Review:** Your pull request will be reviewed by the maintainers. Make any necessary changes based on their feedback.

<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/9f/8d/bc61301c5e2003c99167b7d1431596ff4521daa766e28ba196f85a61e02b/object_mother_pattern-2025.1.12.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/test.yaml?event=push&branch=master\" target=\"_blank\">\n        <img src=\"https://github.com/adriamontoto/object-mother-pattern/actions/workflows/test.yaml/badge.svg?event=push&branch=master\" alt=\"Test Pipeline\">\n    </a>\n    <a href=\"https://github.com/adriamontoto/object-mother-pattern/actions/workflows/lint.yaml?event=push&branch=master\" target=\"_blank\">\n        <img src=\"https://github.com/adriamontoto/object-mother-pattern/actions/workflows/lint.yaml/badge.svg?event=push&branch=master\" alt=\"Lint 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</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\nEasy to install and integrate, the **Object Mother Pattern** is a must-have for any Python developer looking to simplify their testing workflow, ensure design uniformity, and leverage the full potential of reusable test objects in their projects \ud83d\ude80.\n<br><br>\n\n## Table of Contents\n\n- [\ud83d\udce5 Installation](#installation)\n- [\ud83d\udcbb Utilization](#utilization)\n  - [\ud83c\udf84 Real-Life Case: Christmas Detector Service](#real-life-case-christmas-detector-service)\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=\"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.mothers import (\n    IntegerMother,\n    FloatMother,\n    BooleanMother,\n    StringMother,\n    UuidMother,\n    StringDateMother,\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>\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/additional_types/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.mothers 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=\"contributing\"></a>\n\n## \ud83e\udd1d Contributing\n\nWe welcome contributions to **Object Mother Pattern**! To ensure a smooth collaboration process, please follow the guidelines below.\n\n### How to Contribute\n\n**1. Fork the Repository:** Click the \"Fork\" button at the top right of the repository page.\n\n**2. Clone Your Fork:**\n\n```bash\ngit clone git+ssh://git@github.com/<your-username>/object-mother-pattern\n```\n\n**3. Create a Branch:**\n\n```bash\ngit checkout -b feature/your-feature-name\n```\n\n**4. Make Your Changes:** Implement your new feature or fix a bug.\n\n**5. Run Tests:** Ensure all the following tests pass before submitting your changes.\n\n- Run tests:\n\n```bash\nmake test\n```\n\n- Run tests with coverage:\n\n```bash\nmake coverage\n```\n\n- Run linter:\n\n```bash\nmake lint\n```\n\n- Run formatter:\n\n```bash\nmake format\n```\n\n**6. Commit Your Changes:**\n\n```bash\ngit commit -m \"\u2728 feature: your feature description\"\n```\n\n**7. Push to Your Fork:**\n\n```bash\ngit push origin feature/your-feature-name\n```\n\n**8. Create a Pull Request:** Navigate to the original repository and create a pull request from your fork.\n\n**9. Wait for Review:** Your pull request will be reviewed by the maintainers. Make any necessary changes based on their feedback.\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": "2025.1.12",
    "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": "",
            "digests": {
                "blake2b_256": "28b3e36d4cd4c42cb9e8dde7ae8da60afc9c19b6ce12adadeaad239e8845d7f1",
                "md5": "a0999d7e9152e2e57577cdf8c3a0a1d9",
                "sha256": "1e0a94eadc14396d29ffcbe1380c50486e214c00750cce076360570373b5872d"
            },
            "downloads": -1,
            "filename": "object_mother_pattern-2025.1.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a0999d7e9152e2e57577cdf8c3a0a1d9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 22203,
            "upload_time": "2025-01-12T15:24:57",
            "upload_time_iso_8601": "2025-01-12T15:24:57.675465Z",
            "url": "https://files.pythonhosted.org/packages/28/b3/e36d4cd4c42cb9e8dde7ae8da60afc9c19b6ce12adadeaad239e8845d7f1/object_mother_pattern-2025.1.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f8dbc61301c5e2003c99167b7d1431596ff4521daa766e28ba196f85a61e02b",
                "md5": "5cfa728c3e5e34ea69bcd60284ddcac2",
                "sha256": "171811bf6ac5af1cbdc893d223e6223a57657674189de02d020368b1b8f06825"
            },
            "downloads": -1,
            "filename": "object_mother_pattern-2025.1.12.tar.gz",
            "has_sig": false,
            "md5_digest": "5cfa728c3e5e34ea69bcd60284ddcac2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 16183,
            "upload_time": "2025-01-12T15:25:00",
            "upload_time_iso_8601": "2025-01-12T15:25:00.136680Z",
            "url": "https://files.pythonhosted.org/packages/9f/8d/bc61301c5e2003c99167b7d1431596ff4521daa766e28ba196f85a61e02b/object_mother_pattern-2025.1.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-12 15:25:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adriamontoto",
    "github_project": "object-mother-pattern",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "Faker",
            "specs": [
                [
                    "<",
                    "34.0.0"
                ],
                [
                    ">=",
                    "29.0.0"
                ]
            ]
        },
        {
            "name": "python-dateutil",
            "specs": [
                [
                    ">=",
                    "2.9.0"
                ],
                [
                    "<",
                    "3.0.0"
                ]
            ]
        }
    ],
    "lcname": "object-mother-pattern"
}
        
Elapsed time: 9.36671s