type-comparable


Nametype-comparable JSON
Version 2 PyPI version JSON
download
home_pagehttps://github.com/sirkonst/type_comparable
SummaryHelper for checking variable equivalence by type. Useful for tests.
upload_time2023-10-11 20:11:56
maintainerKonstantin Enchant
docs_urlNone
authorKonstantin Enchant
requires_python>=3.7
licenseMIT
keywords test tests pytest pytest-pluggin type typing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            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/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sirkonst/type_comparable",
    "name": "type-comparable",
    "maintainer": "Konstantin Enchant",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "sirkonst@gmail.com",
    "keywords": "test,tests,pytest,pytest-pluggin,type,typing",
    "author": "Konstantin Enchant",
    "author_email": "sirkonst@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d1/10/b49801874c9f7e5eab9bb48d7c592b0d6b1031d162698feedffa9d748d77/type_comparable-2.tar.gz",
    "platform": null,
    "description": "About\n=====\n\nModule allows to compare variables not only by value but by type too. \n\nQuick example:\n\n.. code-block:: python\n\n    from typing import Any\n\n    from type_comparable import make_type_comparable\n\n    response = {\n        'id': 144233,\n        'date_create': '2020-01-25T17:31:33.910803',\n        'important_data': 'important data',\n        'other_data': 'other data',\n        'inner_data': {\n            'field a': 'value a',\n            'field d': 'value b'\n        },\n        'line': [1, 'some text', 3]\n    }\n    assert make_type_comparable(response) == {\n        'id': int,  # <-- will compare by type int\n        'date_create': str, # < -- will compare by type str\n        'important_data': 'important data',  # <-- exact match as is\n        'other_data': Any, # <-- allow any data,\n        'inner_date': {  # <-- also work with nested dictionaries\n            'field a': str,\n            'field b': 'value b'\n        }\n        'line': [int, Any, 3]  # <- check elements in array\n    }\n\n    # if you don't want wrap left variable (response) if can wrap right:\n    assert response == make_type_comparable(...)\n\nVery useful for tests by pytest.\n\n\nSupport types\n=============\n\nComparable types (which can be passed to `make_type_comparable()`):\n\n- `int`\n- `bool`\n- `str`\n- `list`\n- `dict`\n- other\n\nTypes for comparison:\n\n- all python builtin (`int`, `str`, `bool`, `list`, `dict`, etc.)\n- `object` and `typing.Any` - mean any type but not `None`\n- `typing.Optional` - mean any type and `None`. `Optional[int]` now not supported\n\nAlso you can try to use with your custom types but without guaranteed (verify \nmanually before use in product)\n\n\nKnow issues\n===========\n\nWrapped `None` is not `None` :-(\n\n.. code-block:: python\n\n    >> make_type_comparable(None) is None\n    False\n\n    # use equal\n    >> make_type_comparable(None) == None\n    True\n\n\nInstall\n=======\n\nFrom PyPi:\n\n.. code-block:: bash\n\n    $ pip install type_comparable\n\n\nFrom local:\n\n.. code-block:: bash\n\n    # update setuptools\n    $ pip install 'setuptools >= 30.4'\n    # do install\n    $ make install\n    # or\n    $ pip install .\n\n\nDevelopment\n===========\n\nPrepare and activate virtual environment like:\n\n.. code-block:: bash\n\n    $ python3 -m venv .env\n    # for bash\n    $ source .env/bin/activate\n    # for fish\n    $ . .env/bin/activate.fish\n    \nUpdate pre-install dependencies:\n\n.. code-block:: bash\n\n    $ pip install 'setuptools >= 30.4'\n\n\nInstall:\n\n.. code-block:: bash\n\n    $ make install_dev\n    # or\n    $ pip install --editable .[develop]\n\nRun tests:\n\n.. code-block:: bash\n\n    $ make test\n    # or \n    $ pytest tests/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Helper for checking variable equivalence by type. Useful for tests.",
    "version": "2",
    "project_urls": {
        "Homepage": "https://github.com/sirkonst/type_comparable"
    },
    "split_keywords": [
        "test",
        "tests",
        "pytest",
        "pytest-pluggin",
        "type",
        "typing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eed147375be7f3ddef02b5a9471557b85c9b104303fceed3d35027536e5eb553",
                "md5": "2f0c728e170a61a6b6e8e9d861c0d0b9",
                "sha256": "c66978b2a87883c480f7c848e42018a0d33a809a6dd0827f321f5a6d8a921ed2"
            },
            "downloads": -1,
            "filename": "type_comparable-2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2f0c728e170a61a6b6e8e9d861c0d0b9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4751,
            "upload_time": "2023-10-11T20:11:54",
            "upload_time_iso_8601": "2023-10-11T20:11:54.868181Z",
            "url": "https://files.pythonhosted.org/packages/ee/d1/47375be7f3ddef02b5a9471557b85c9b104303fceed3d35027536e5eb553/type_comparable-2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d110b49801874c9f7e5eab9bb48d7c592b0d6b1031d162698feedffa9d748d77",
                "md5": "02c40d37a0ad9fa56901cd102271fdac",
                "sha256": "ab8e0627483563f158324514b459be0004fd8c03016005f8d1a9170e8df236a9"
            },
            "downloads": -1,
            "filename": "type_comparable-2.tar.gz",
            "has_sig": false,
            "md5_digest": "02c40d37a0ad9fa56901cd102271fdac",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7627,
            "upload_time": "2023-10-11T20:11:56",
            "upload_time_iso_8601": "2023-10-11T20:11:56.032937Z",
            "url": "https://files.pythonhosted.org/packages/d1/10/b49801874c9f7e5eab9bb48d7c592b0d6b1031d162698feedffa9d748d77/type_comparable-2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-11 20:11:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sirkonst",
    "github_project": "type_comparable",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "tox": true,
    "lcname": "type-comparable"
}
        
Elapsed time: 0.21592s