Skip to main content

A general purpose mock library for Python

Project description

Python Fake

🌟 Overview

This project provides a Fake class that can be used to replace any object in a test, in development environment or in any other situation where you need to replace an object with a fake one.

The tries to provide a mock implementation for any usage, including properties, items, length, iterator, return value, await value, etc so that it never fails in runtime due to a missing implementation.

On the other hand, sometimes other pieces of code expect a certain implementation and the default implementation of the Fake class is not enough. In this case, you can use the __Fake_... parameters in the constructor to provide a more specific implementation.

At the moment, it doesn't provide tools for monitoring how the object was used, but it is planned to be implemented in the future.

🔎 Sample Usage

Fakeing the picamera2 module of Raspberry Pi so that one can run the code on a non-Raspberry Pi development environment:

from fake import Fake

sys.modules['picamera2'] = Fake(
    _Fake__props={
        'Picamera2': Fake(
            _Fake__return_value=Fake(
                _Fake__props={
                    'capture_array': Fake(
                        _Fake__return_value=np.zeros((1, 1, 3), dtype=np.uint8),
                    ),
                },
            ),
        ),
    },
)

⚙️ Parameters

A Fake object can be created with the following parameters:

  • _Fake__props: A dictionary that contains the properties of the object and their respective values.
  • _Fake__items: A dictionary that contains the items of the object and their respective values.
  • _Fake__list: A list that contains the items of the object. (in case the index is a number and not listed in the __items dictionary). It also sets the length of the object if _Fake__length is not set.
  • _Fake__return_value: The return value of the object when it is called.
  • _Fake__await_value: The return value of the object when it is awaited.
  • _Fake__length: The length of the object when it is queried via the len function.
  • _Fake__iter: The iterator of the object when it is queried via the iter function.

📦 Installation

Pip

pip install python-fake

Poetry

poetry add python-fake

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_fake-0.1.4.dev1250331103485452101.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file python_fake-0.1.4.dev1250331103485452101.tar.gz.

File metadata

File hashes

Hashes for python_fake-0.1.4.dev1250331103485452101.tar.gz
Algorithm Hash digest
SHA256 f0391f01a08f3a578a89272596556428d5250ab540990eb1adfe4208673c9fda
MD5 1ed70581cc2747ea92af45775f2e09c5
BLAKE2b-256 ae5b4ecb146b86c028f31f6a999ec7a58c6960cec95c7a37a47b32b7a6b6e8f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_fake-0.1.4.dev1250331103485452101.tar.gz:

Publisher: integration_delivery.yml on sassanh/python-fake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_fake-0.1.4.dev1250331103485452101-py3-none-any.whl.

File metadata

File hashes

Hashes for python_fake-0.1.4.dev1250331103485452101-py3-none-any.whl
Algorithm Hash digest
SHA256 c9c2f10c6917df06168c9d8c4e00347a68a1d59f75711d86d499f9c5b851676d
MD5 94e8dd6f8565cc85c417757b7c1a7efd
BLAKE2b-256 8d54c811d31a00785dcaee3c056c8099b0a1dc18f4bf70a39f6f2b336cd94335

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_fake-0.1.4.dev1250331103485452101-py3-none-any.whl:

Publisher: integration_delivery.yml on sassanh/python-fake

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page