Metadata-Version: 2.1
Name: type_comparable
Version: 2
Summary: Helper for checking variable equivalence by type. Useful for tests.
Home-page: https://github.com/sirkonst/type_comparable
Author: Konstantin Enchant
Author-email: sirkonst@gmail.com
Maintainer: Konstantin Enchant
Maintainer-email: sirkonst@gmail.com
License: MIT
Keywords: test,tests,pytest,pytest-pluggin,type,typing
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Framework :: Pytest
Requires-Python: >=3.7
License-File: LICENSE
Requires-Dist: wrapt~=1.15
Provides-Extra: develop
Requires-Dist: coverage~=7.2; extra == "develop"
Requires-Dist: docutils~=0.20; extra == "develop"
Requires-Dist: pygments~=2.16; extra == "develop"
Requires-Dist: pylama~=8.4; extra == "develop"
Requires-Dist: pytest-xdist; extra == "develop"
Requires-Dist: pytest~=7.2; extra == "develop"
Requires-Dist: setuptools~=68.2; python_version >= "3.12" and extra == "develop"
Requires-Dist: tox~=4.8; extra == "develop"
Requires-Dist: twine~=4.0; extra == "develop"
Requires-Dist: wheel~=0.38; extra == "develop"

About
=====

Module allows to compare variables not only by value but by type too. 

Quick example:

.. code-block:: python

    from typing import Any

    from type_comparable import make_type_comparable

    response = {
        'id': 144233,
        'date_create': '2020-01-25T17:31:33.910803',
        'important_data': 'important data',
        'other_data': 'other data',
        'inner_data': {
            'field a': 'value a',
            'field d': 'value b'
        },
        'line': [1, 'some text', 3]
    }
    assert make_type_comparable(response) == {
        'id': int,  # <-- will compare by type int
        'date_create': str, # < -- will compare by type str
        'important_data': 'important data',  # <-- exact match as is
        'other_data': Any, # <-- allow any data,
        'inner_date': {  # <-- also work with nested dictionaries
            'field a': str,
            'field b': 'value b'
        }
        'line': [int, Any, 3]  # <- check elements in array
    }

    # if you don't want wrap left variable (response) if can wrap right:
    assert response == make_type_comparable(...)

Very useful for tests by pytest.


Support types
=============

Comparable types (which can be passed to `make_type_comparable()`):

- `int`
- `bool`
- `str`
- `list`
- `dict`
- other

Types for comparison:

- all python builtin (`int`, `str`, `bool`, `list`, `dict`, etc.)
- `object` and `typing.Any` - mean any type but not `None`
- `typing.Optional` - mean any type and `None`. `Optional[int]` now not supported

Also you can try to use with your custom types but without guaranteed (verify 
manually before use in product)


Know issues
===========

Wrapped `None` is not `None` :-(

.. code-block:: python

    >> make_type_comparable(None) is None
    False

    # use equal
    >> make_type_comparable(None) == None
    True


Install
=======

From PyPi:

.. code-block:: bash

    $ pip install type_comparable


From local:

.. code-block:: bash

    # update setuptools
    $ pip install 'setuptools >= 30.4'
    # do install
    $ make install
    # or
    $ pip install .


Development
===========

Prepare and activate virtual environment like:

.. code-block:: bash

    $ python3 -m venv .env
    # for bash
    $ source .env/bin/activate
    # for fish
    $ . .env/bin/activate.fish
    
Update pre-install dependencies:

.. code-block:: bash

    $ pip install 'setuptools >= 30.4'


Install:

.. code-block:: bash

    $ make install_dev
    # or
    $ pip install --editable .[develop]

Run tests:

.. code-block:: bash

    $ make test
    # or 
    $ pytest tests/
