Skip to main content

Python package for mocking uuid.

Project description

freeze-uuid

Python package for mocking uuid

Usage Example

from freeze_uuid import freeze_uuid


@freeze_uuid('12af6b44-8181-11ee-b890-628ab7cd4d99')
def test_uuid():
    assert str(uuid.uuid1()) == '12af6b44-8181-11ee-b890-628ab7cd4d99'
    assert str(uuid.uuid4()) == '12af6b44-8181-11ee-b890-628ab7cd4d99'

@freeze_uuid()
def test_uuid_default():
    assert str(uuid.uuid1()) == '00000000-0000-0000-0000-000000000000'
    assert str(uuid.uuid4()) == '00000000-0000-0000-0000-000000000000'

@pytest.mark.asyncio
@freeze_uuid('12af6b44-8181-11ee-b890-628ab7cd4d99')
async def test_uuid_async():
    assert str(uuid.uuid1()) == '12af6b44-8181-11ee-b890-628ab7cd4d99'
    assert str(uuid.uuid4()) == '12af6b44-8181-11ee-b890-628ab7cd4d99'

Also you can use list of uuids for multiple usage

@freeze_uuid(['12af6b44-8181-11ee-b890-628ab7cd4d99', '12af6b44-8181-11ee-b890-628ab7cd4d98'])
def test_uuid_list():
    assert str(uuid.uuid1()) == '12af6b44-8181-11ee-b890-628ab7cd4d99'
    assert str(uuid.uuid4()) == '12af6b44-8181-11ee-b890-628ab7cd4d98'
    assert str(uuid.uuid4()) == '12af6b44-8181-11ee-b890-628ab7cd4d98'
    assert str(uuid.uuid4()) == '12af6b44-8181-11ee-b890-628ab7cd4d98'

Since library mocks uuid.UUID class, it can be used with all libraries, that support UUID class, i.e. uuid7

from uuid_extensions import uuid7

@freeze_uuid(TEST_UUID)
def test_uuid_7():
    assert str(uuid7()) == TEST_UUID

With freeze_uuid context manager you can create tests with pytest parametrize

from freeze_uuid import freeze_uuid_manager

@pytest.mark.parametrize(
    ['expected_result', 'freeze_data'],
    [
        pytest.param(
            TEST_UUID_2,
            [TEST_UUID_2],
        ),
        pytest.param(
            TEST_UUID_3,
            [TEST_UUID_3],
        ),
        pytest.param(
            TEST_UUID_4,
            [TEST_UUID_4],
        ),
        pytest.param(
            TEST_UUID_5,
            [TEST_UUID_5],
        ),
    ]
)
def test_parametrize(expected_result, freeze_data):
    with freeze_uuid_manager(freeze_data):
        assert str(uuid.uuid4()) == expected_result

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

freeze_uuid-0.4.3.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

freeze_uuid-0.4.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file freeze_uuid-0.4.3.tar.gz.

File metadata

  • Download URL: freeze_uuid-0.4.3.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for freeze_uuid-0.4.3.tar.gz
Algorithm Hash digest
SHA256 fc229deb02e3bf41918ad9c377b304af79403ac6e3b8779c1212da2788be48ca
MD5 8d8123b9fa13a151859ddf3def555e79
BLAKE2b-256 6513bb583bb19c1ee627c57ff62087aacf2ee4cfba8d1241b8acb0e89969aa58

See more details on using hashes here.

File details

Details for the file freeze_uuid-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: freeze_uuid-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for freeze_uuid-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 19e28068cafb4f1ca0f1632aee2d82103b6f56c353c6b4d297406eb15dd4f6cd
MD5 927074151a3213875f84a1544472a0f0
BLAKE2b-256 a95cb4b99e178ef24ef651ade7d5114d1fde3eec84554ac0c5593aacd1bcbeca

See more details on using hashes here.

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