worth


Nameworth JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/johnnoone/worth
SummaryAssert relevant object attributes
upload_time2024-07-14 21:51:37
maintainerNone
docs_urlNone
authorXavier Barbosa
requires_python<4.0,>=3.10
licenseBSD-3-Clause
keywords test assertion
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Worth

Worth is a Python library that helps you assert relevant object attributes


For example

```python
from worth import Omit

def test_something_like():
    a = Model(id=12345, name="Hoff")
    b = Model(id=67890, name="Hoff")
    assert a == b | Omit("id")
```


It implements some helpers

**Always**

`Always()` assertion is always true.

```python
assert "a string" == Always()
assert 42 == Always()
assert False == Always()
```

**Never**

`Never()` assertion is always false.

```python
assert "a string" == Never()
assert 42 == Never()
assert False == Never()
```

**OneOf**

`OneOf()` asserts one of its values.

```python
assert "foo" == OneOf("foo", "bar")
assert "bar" == OneOf("foo", "bar")
assert "qux" != OneOf("foo", "bar")
```


Things that applies to models (dataclasses, attrs, or msgspec)

**Omit**

`Omit()` let you to exclude some properties of you model from the comparison.

```python
a = Model(id=12345, name="Hoff")
b = Model(id=67890, name="Hoff")
assert a == b | Omit("id")
```

**Only**

`Only()` let you to choose precisely which properties you want to compair.

```python
a = Model(id=12345, name="Hoff")
b = Model(id=67890, name="Hoff")
assert a == b | Only("name")
```


Things that applies to mappings

**contains**

`contains()` let you to compare some mapping items.

```python
assert {"foo": 42, "bar": True} == contains({"foo": 42})
assert {"foo": 42, "bar": True} != contains({"foo": "wrong"})
```


## TODO

- [x] dataclasses
- [x] attrs
- [x] msgspec
- [ ] vanilla

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/johnnoone/worth",
    "name": "worth",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "test, assertion",
    "author": "Xavier Barbosa",
    "author_email": "clint.northwood@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f5/3e/07e98e668cdf79715b0240412736668cb510af9a9c5b2bef3fe6a56ea5ea/worth-0.3.0.tar.gz",
    "platform": null,
    "description": "# Worth\n\nWorth is a Python library that helps you assert relevant object attributes\n\n\nFor example\n\n```python\nfrom worth import Omit\n\ndef test_something_like():\n    a = Model(id=12345, name=\"Hoff\")\n    b = Model(id=67890, name=\"Hoff\")\n    assert a == b | Omit(\"id\")\n```\n\n\nIt implements some helpers\n\n**Always**\n\n`Always()` assertion is always true.\n\n```python\nassert \"a string\" == Always()\nassert 42 == Always()\nassert False == Always()\n```\n\n**Never**\n\n`Never()` assertion is always false.\n\n```python\nassert \"a string\" == Never()\nassert 42 == Never()\nassert False == Never()\n```\n\n**OneOf**\n\n`OneOf()` asserts one of its values.\n\n```python\nassert \"foo\" == OneOf(\"foo\", \"bar\")\nassert \"bar\" == OneOf(\"foo\", \"bar\")\nassert \"qux\" != OneOf(\"foo\", \"bar\")\n```\n\n\nThings that applies to models (dataclasses, attrs, or msgspec)\n\n**Omit**\n\n`Omit()` let you to exclude some properties of you model from the comparison.\n\n```python\na = Model(id=12345, name=\"Hoff\")\nb = Model(id=67890, name=\"Hoff\")\nassert a == b | Omit(\"id\")\n```\n\n**Only**\n\n`Only()` let you to choose precisely which properties you want to compair.\n\n```python\na = Model(id=12345, name=\"Hoff\")\nb = Model(id=67890, name=\"Hoff\")\nassert a == b | Only(\"name\")\n```\n\n\nThings that applies to mappings\n\n**contains**\n\n`contains()` let you to compare some mapping items.\n\n```python\nassert {\"foo\": 42, \"bar\": True} == contains({\"foo\": 42})\nassert {\"foo\": 42, \"bar\": True} != contains({\"foo\": \"wrong\"})\n```\n\n\n## TODO\n\n- [x] dataclasses\n- [x] attrs\n- [x] msgspec\n- [ ] vanilla\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Assert relevant object attributes",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/johnnoone/worth",
        "Repository": "https://github.com/johnnoone/worth"
    },
    "split_keywords": [
        "test",
        " assertion"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27786719c0bad57b426dfef006fe09522ffb7fb20f26e86e15531fba9117bfcb",
                "md5": "43e6b7bbe5295ff70e30e72c9642b210",
                "sha256": "841dbd7c8583d41edf0a1cd3d93b44c21e07a90e255a86dfbf04ad2fd8108074"
            },
            "downloads": -1,
            "filename": "worth-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "43e6b7bbe5295ff70e30e72c9642b210",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 5806,
            "upload_time": "2024-07-14T21:51:36",
            "upload_time_iso_8601": "2024-07-14T21:51:36.489818Z",
            "url": "https://files.pythonhosted.org/packages/27/78/6719c0bad57b426dfef006fe09522ffb7fb20f26e86e15531fba9117bfcb/worth-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f53e07e98e668cdf79715b0240412736668cb510af9a9c5b2bef3fe6a56ea5ea",
                "md5": "623cedd1975592d251f2f2c9c85bd44a",
                "sha256": "d214cb09b0679a85c6b57742dda5f10ba0a4ed37752d6d1c4ae3c15cf2b88d17"
            },
            "downloads": -1,
            "filename": "worth-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "623cedd1975592d251f2f2c9c85bd44a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 4778,
            "upload_time": "2024-07-14T21:51:37",
            "upload_time_iso_8601": "2024-07-14T21:51:37.953147Z",
            "url": "https://files.pythonhosted.org/packages/f5/3e/07e98e668cdf79715b0240412736668cb510af9a9c5b2bef3fe6a56ea5ea/worth-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-14 21:51:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "johnnoone",
    "github_project": "worth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "worth"
}
        
Elapsed time: 0.30244s