object-mother-pattern

The Object Mother Pattern is a Python 🐍 package that simplifies and standardizes the creation of test πŸ§ͺ objects.

https://github.com/adriamontoto/object-mother-pattern

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • βœ“
    CITATION.cff file
    Found CITATION.cff file
  • βœ“
    codemeta.json file
    Found codemeta.json file
  • βœ“
    .zenodo.json file
    Found .zenodo.json file
  • β—‹
    DOI references
  • β—‹
    Academic publication links
  • β—‹
    Committers with academic emails
  • β—‹
    Institutional organization owner
  • β—‹
    JOSS paper metadata
  • β—‹
    Scientific vocabulary similarity
    Low similarity (8.8%) to scientific vocabulary

Keywords

development object-mother pattern python python3 python311 python312 python313 testing tools utilities validation

Keywords from Contributors

interpretability standardization animal hack
Last synced: 4 months ago · JSON representation ·

Repository

The Object Mother Pattern is a Python 🐍 package that simplifies and standardizes the creation of test πŸ§ͺ objects.

Basic Info
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • Open Issues: 9
  • Releases: 28
Topics
development object-mother pattern python python3 python311 python312 python313 testing tools utilities validation
Created about 1 year ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing Funding License Code of conduct Citation Codeowners Security

README.md

βš’οΈ Object Mother Pattern

CI Pipeline Coverage Pipeline Package Version Supported Python Versions Package Downloads Project Documentation

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.

Table of Contents

πŸ”Ό Back to top



## πŸ“₯ Installation You can install **Object Mother Pattern** using `pip`: ```bash pip install object-mother-pattern ```

πŸ”Ό Back to top



## πŸ“š 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.

πŸ”Ό Back to top



## πŸ’» 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 ```

πŸ”Ό Back to top



## πŸ“ƒ 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.

πŸ”Ό Back to top



### πŸŽ„ 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) ```

πŸ”Ό Back to top



### πŸ§‘β€πŸ”§ 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) ```

πŸ”Ό Back to top



## 🀝 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! 🌟_

πŸ”Ό Back to top



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

πŸ”Ό Back to top

Owner

  • Login: adriamontoto
  • Kind: user
  • Location: /dev/null
  • Company: Amazon

Software Development Engineer @ Amazon

Citation (CITATION.cff)

cff-version: 1.2.0
title: Object Mother Pattern
message: >
  If you use this software, please cite it using the metadata below.
type: software
authors:
  - given-names: AdriΓ 
    family-names: Montoto
repository-code: https://github.com/adriamontoto/object-mother-pattern
url: https://pypi.org/project/object-mother-pattern
abstract: >
  Object Mother Pattern is a Python library that simplifies and
  standardises the creation of complex test fixtures by providing
  reusable object mothers for common data types.
keywords:
  - python
  - testing
  - fixtures
  - object-mother
license: MIT

GitHub Events

Total
  • Create event: 115
  • Release event: 34
  • Issues event: 7
  • Watch event: 2
  • Delete event: 93
  • Member event: 2
  • Issue comment event: 59
  • Public event: 1
  • Push event: 372
  • Pull request review comment event: 12
  • Pull request review event: 40
  • Pull request event: 125
Last Year
  • Create event: 115
  • Release event: 34
  • Issues event: 7
  • Watch event: 2
  • Delete event: 93
  • Member event: 2
  • Issue comment event: 59
  • Public event: 1
  • Push event: 372
  • Pull request review comment event: 12
  • Pull request review event: 40
  • Pull request event: 125

Committers

Last synced: 12 months ago

All Time
  • Total Commits: 45
  • Total Committers: 2
  • Avg Commits per committer: 22.5
  • Development Distribution Score (DDS): 0.022
Past Year
  • Commits: 45
  • Committers: 2
  • Avg Commits per committer: 22.5
  • Development Distribution Score (DDS): 0.022
Top Committers
Name Email Commits
Adria Montoto 7****o 44
github-actions 4****] 1

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 7
  • Total pull requests: 131
  • Average time to close issues: N/A
  • Average time to close pull requests: 6 days
  • Total issue authors: 1
  • Total pull request authors: 4
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.67
  • Merged pull requests: 56
  • Bot issues: 0
  • Bot pull requests: 118
Past Year
  • Issues: 7
  • Pull requests: 131
  • Average time to close issues: N/A
  • Average time to close pull requests: 6 days
  • Issue authors: 1
  • Pull request authors: 4
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.67
  • Merged pull requests: 56
  • Bot issues: 0
  • Bot pull requests: 118
Top Authors
Issue Authors
  • adriamontoto (7)
Pull Request Authors
  • dependabot[bot] (118)
  • adriamontoto (7)
  • oriol-bustos (3)
  • oriolbustos (3)
Top Labels
Issue Labels
enhancement (7)
Pull Request Labels
dependencies (117) github_actions (105) python (16) enhancement (6) good first issue (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 3,283 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 27
  • Total maintainers: 1
pypi.org: object-mother-pattern

The Object Mother Pattern is a Python package that simplifies and standardizes the creation of test objects.

  • Versions: 27
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 3,283 Last month
Rankings
Dependent packages count: 9.9%
Average: 32.7%
Dependent repos count: 55.5%
Maintainers (1)
Last synced: 4 months ago

Dependencies

.github/workflows/codeql.yaml actions
  • actions/checkout v4.2.2 composite
  • github/codeql-action/analyze v3.27.9 composite
  • github/codeql-action/init v3.27.9 composite
.github/workflows/coverage.yaml actions
  • actions/download-artifact v4.1.8 composite
  • actions/setup-python v5.3.0 composite
.github/workflows/format.yaml actions
  • EndBug/add-and-commit v9.1.4 composite
  • actions/cache v4.2.0 composite
  • actions/checkout v4.2.2 composite
  • actions/setup-python v5.3.0 composite
.github/workflows/lint.yaml actions
  • actions/cache v4.2.0 composite
  • actions/checkout v4.2.2 composite
  • actions/setup-python v5.3.0 composite
  • actions/upload-artifact v4.5.0 composite
.github/workflows/publish.yaml actions
  • actions/checkout v4.2.2 composite
  • actions/setup-python v5.3.0 composite
  • actions/upload-artifact v4.5.0 composite
  • pypa/gh-action-pypi-publish v1.12.3 composite
.github/workflows/test.yaml actions
  • actions/cache v4.2.0 composite
  • actions/checkout v4.2.2 composite
  • actions/download-artifact v4.1.8 composite
  • actions/setup-python v5.3.0 composite
  • actions/upload-artifact v4.5.0 composite
  • re-actors/alls-green v1.2.2 composite
pyproject.toml pypi
  • Faker >=28.0.0,<34.0.0
requirements.txt pypi
requirements_dev.txt pypi