baby-steps


Namebaby-steps JSON
Version 1.3.1 PyPI version JSON
download
home_pagehttps://github.com/tsv1/baby-steps
SummaryReadability Matters
upload_time2024-06-16 10:49:54
maintainerNone
docs_urlNone
authorNikita Tsvetkov
requires_python>=3.8
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Baby Steps

[![PyPI](https://img.shields.io/pypi/v/baby-steps.svg?style=flat-square)](https://pypi.python.org/pypi/baby-steps/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/baby-steps?style=flat-square)](https://pypi.python.org/pypi/baby-steps/)
[![Python Version](https://img.shields.io/pypi/pyversions/baby-steps.svg?style=flat-square)](https://pypi.python.org/pypi/baby-steps/)

BDD steps for test markup. Just for readability.

## Installation

```sh
pip3 install baby-steps
```

## Usage

```python
import httpx
from baby_steps import given, when, then

def test_status_code():
    with given:
        code = 200

    with when:
        resp = httpx.get(f"https://httpbin.org/status/{code}")

    with then:
        assert resp.status_code == code
```

### Named Steps

```python
import httpx
from baby_steps import given, when, then

def test_status_code():
    with given("status code"):
        code = 200

    with when("user requests a resource"):
        resp = httpx.get(f"https://httpbin.org/status/{code}")

    with then("it should return expected status code"):
        assert resp.status_code == code
```

### Hooks

```python
from baby_steps import given, then, when
from baby_steps.hooks import add_hook

def test():
    with given("status code"):
        pass

    with when("user requests a resource"):
        pass

    with then("it should return expected status code"):
        pass


def hook(step, name):
    print(step, name)

add_hook(hook)
test()

# <class 'baby_steps.Given'> 'status code'
# <class 'baby_steps.When'> 'user requests a resource'
# <class 'baby_steps.Then'> 'it should return expected status code'
```

#### Advanced

```python
from baby_steps import when
from baby_steps.hooks import add_hook

def test():
    with when:
        print("when")


def hook(step, name):
    print("before", step)
    yield
    print("after", step)

add_hook(hook)
test()

# before <class 'baby_steps.When'>
# when
# after <class 'baby_steps.When'>
```

### Custom Steps

```python
from baby_steps import Step

class AndThen(Step):
    pass

and_then = AndThen()

with and_then("smth"):
    pass
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tsv1/baby-steps",
    "name": "baby-steps",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Nikita Tsvetkov",
    "author_email": "tsv1@fastmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d0/17/c1bac3b57488801455ff8228f8c18107cbe5f4233c4b1e713fdb86e40f62/baby_steps-1.3.1.tar.gz",
    "platform": null,
    "description": "# Baby Steps\n\n[![PyPI](https://img.shields.io/pypi/v/baby-steps.svg?style=flat-square)](https://pypi.python.org/pypi/baby-steps/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/baby-steps?style=flat-square)](https://pypi.python.org/pypi/baby-steps/)\n[![Python Version](https://img.shields.io/pypi/pyversions/baby-steps.svg?style=flat-square)](https://pypi.python.org/pypi/baby-steps/)\n\nBDD steps for test markup. Just for readability.\n\n## Installation\n\n```sh\npip3 install baby-steps\n```\n\n## Usage\n\n```python\nimport httpx\nfrom baby_steps import given, when, then\n\ndef test_status_code():\n    with given:\n        code = 200\n\n    with when:\n        resp = httpx.get(f\"https://httpbin.org/status/{code}\")\n\n    with then:\n        assert resp.status_code == code\n```\n\n### Named Steps\n\n```python\nimport httpx\nfrom baby_steps import given, when, then\n\ndef test_status_code():\n    with given(\"status code\"):\n        code = 200\n\n    with when(\"user requests a resource\"):\n        resp = httpx.get(f\"https://httpbin.org/status/{code}\")\n\n    with then(\"it should return expected status code\"):\n        assert resp.status_code == code\n```\n\n### Hooks\n\n```python\nfrom baby_steps import given, then, when\nfrom baby_steps.hooks import add_hook\n\ndef test():\n    with given(\"status code\"):\n        pass\n\n    with when(\"user requests a resource\"):\n        pass\n\n    with then(\"it should return expected status code\"):\n        pass\n\n\ndef hook(step, name):\n    print(step, name)\n\nadd_hook(hook)\ntest()\n\n# <class 'baby_steps.Given'> 'status code'\n# <class 'baby_steps.When'> 'user requests a resource'\n# <class 'baby_steps.Then'> 'it should return expected status code'\n```\n\n#### Advanced\n\n```python\nfrom baby_steps import when\nfrom baby_steps.hooks import add_hook\n\ndef test():\n    with when:\n        print(\"when\")\n\n\ndef hook(step, name):\n    print(\"before\", step)\n    yield\n    print(\"after\", step)\n\nadd_hook(hook)\ntest()\n\n# before <class 'baby_steps.When'>\n# when\n# after <class 'baby_steps.When'>\n```\n\n### Custom Steps\n\n```python\nfrom baby_steps import Step\n\nclass AndThen(Step):\n    pass\n\nand_then = AndThen()\n\nwith and_then(\"smth\"):\n    pass\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Readability Matters",
    "version": "1.3.1",
    "project_urls": {
        "Homepage": "https://github.com/tsv1/baby-steps"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b75cd931faf5df31683d1b4c12c663147b4ca7315bf6ed484b34ab362452506",
                "md5": "aab6a6c3938370005a279092cb970bc4",
                "sha256": "0409b453ff5dc2d0830f058b5241a06475534f32337be0a192497085347ac820"
            },
            "downloads": -1,
            "filename": "baby_steps-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aab6a6c3938370005a279092cb970bc4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7482,
            "upload_time": "2024-06-16T10:49:53",
            "upload_time_iso_8601": "2024-06-16T10:49:53.374488Z",
            "url": "https://files.pythonhosted.org/packages/6b/75/cd931faf5df31683d1b4c12c663147b4ca7315bf6ed484b34ab362452506/baby_steps-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d017c1bac3b57488801455ff8228f8c18107cbe5f4233c4b1e713fdb86e40f62",
                "md5": "29a2e45014284e5602dc628d2dab368d",
                "sha256": "4312f88e8d92a7a7b9a070b32a114ea6d8c432e6a10e4c8b2163a6bcc2461036"
            },
            "downloads": -1,
            "filename": "baby_steps-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "29a2e45014284e5602dc628d2dab368d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8027,
            "upload_time": "2024-06-16T10:49:54",
            "upload_time_iso_8601": "2024-06-16T10:49:54.899222Z",
            "url": "https://files.pythonhosted.org/packages/d0/17/c1bac3b57488801455ff8228f8c18107cbe5f4233c4b1e713fdb86e40f62/baby_steps-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-16 10:49:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tsv1",
    "github_project": "baby-steps",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "baby-steps"
}
        
Elapsed time: 0.26154s