bddcli


Namebddcli JSON
Version 2.9.4 PyPI version JSON
download
home_pagehttp://github.com/pylover/bddcli
SummaryTest any command line interface in BDD manner.
upload_time2022-12-05 21:08:51
maintainer
docs_urlNone
authorVahid Mardani
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # bddcli
Test any command line interface in BDD manner.

[![PyPI](http://img.shields.io/pypi/v/bddcli.svg)](https://pypi.python.org/pypi/bddcli)
[![Build](https://github.com/pylover/bddcli/workflows/Build/badge.svg?branch=master)](https://github.com/pylover/bddcli/actions)
[![Coverage Status](https://coveralls.io/repos/github/pylover/bddcli/badge.svg?branch=master)](https://coveralls.io/github/pylover/bddcli?branch=master)

### About

A framework to easily test your command line interface in another(isolated) 
process and gather `stdout`, `stderr` and `exit-status` of the process.

Thanks to https://github.com/cheremnov for the Windows support.

## Installation

Only `Python >= 3.6` is supported.

```bash
pip install bddcli
```

## Quickstart

### Arguments

```python
import sys

from bddcli import Given, when, stdout, status, stderr, Application, given


def foo():
    print(' '.join(sys.argv))
    return 0


app = Application('foo', 'mymodule:foo')


with Given(app, 'bar'):
    assert status == 0
    assert stdout == 'foo bar\n'

    # Without any argument
    when(given - 'bar')
    assert stdout == 'foo\n'

    # Pass multiple arguments
    when('bar baz')
    assert stdout == 'foo bar baz\n'

    # Pass multiple arguments, another method
    when(['bar', 'baz'])
    assert stdout == 'foo bar baz\n'

    # Add an argument
    when(given + 'baz')
    assert stdout == 'foo bar baz\n'

```


### Standard input

```python
with Given(app, stdin='foo'):
    assert ...

    # stdin is empty
    when(stdin='')
    assert ...

```


### Standard output and error

```python
from bddcli import stderr, stdout

assert stderr == ... 
assert stdout == ... 
```

### Environment variables

```python
import os

from bddcli import Given, stdout, Application, when, given


def foo():
    e = os.environ.copy()
    del e['PWD']
    print(' '.join(f'{k}: {v}' for k, v in e.items()))


app = Application('foo', 'mymodule:foo')
with Given(app, environ={'bar': 'baz'}):
    assert stdout == 'bar: baz\n'

    # Without any variable
    when(environ=given - 'bar')
    assert stdout == '\n'

    # Add another variables
    when(environ=given + {'qux': 'quux'})
    assert stdout == 'bar: baz qux: quux\n'
```


See tests for more examples.
            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/pylover/bddcli",
    "name": "bddcli",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Vahid Mardani",
    "author_email": "vahid.mardani@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/00/65/510fc767394ee3af9fac7d5199ce69607fc807a48e9b5f7444e13de6b507/bddcli-2.9.4.tar.gz",
    "platform": null,
    "description": "# bddcli\nTest any command line interface in BDD manner.\n\n[![PyPI](http://img.shields.io/pypi/v/bddcli.svg)](https://pypi.python.org/pypi/bddcli)\n[![Build](https://github.com/pylover/bddcli/workflows/Build/badge.svg?branch=master)](https://github.com/pylover/bddcli/actions)\n[![Coverage Status](https://coveralls.io/repos/github/pylover/bddcli/badge.svg?branch=master)](https://coveralls.io/github/pylover/bddcli?branch=master)\n\n### About\n\nA framework to easily test your command line interface in another(isolated) \nprocess and gather `stdout`, `stderr` and `exit-status` of the process.\n\nThanks to https://github.com/cheremnov for the Windows support.\n\n## Installation\n\nOnly `Python >= 3.6` is supported.\n\n```bash\npip install bddcli\n```\n\n## Quickstart\n\n### Arguments\n\n```python\nimport sys\n\nfrom bddcli import Given, when, stdout, status, stderr, Application, given\n\n\ndef foo():\n    print(' '.join(sys.argv))\n    return 0\n\n\napp = Application('foo', 'mymodule:foo')\n\n\nwith Given(app, 'bar'):\n    assert status == 0\n    assert stdout == 'foo bar\\n'\n\n    # Without any argument\n    when(given - 'bar')\n    assert stdout == 'foo\\n'\n\n    # Pass multiple arguments\n    when('bar baz')\n    assert stdout == 'foo bar baz\\n'\n\n    # Pass multiple arguments, another method\n    when(['bar', 'baz'])\n    assert stdout == 'foo bar baz\\n'\n\n    # Add an argument\n    when(given + 'baz')\n    assert stdout == 'foo bar baz\\n'\n\n```\n\n\n### Standard input\n\n```python\nwith Given(app, stdin='foo'):\n    assert ...\n\n    # stdin is empty\n    when(stdin='')\n    assert ...\n\n```\n\n\n### Standard output and error\n\n```python\nfrom bddcli import stderr, stdout\n\nassert stderr == ... \nassert stdout == ... \n```\n\n### Environment variables\n\n```python\nimport os\n\nfrom bddcli import Given, stdout, Application, when, given\n\n\ndef foo():\n    e = os.environ.copy()\n    del e['PWD']\n    print(' '.join(f'{k}: {v}' for k, v in e.items()))\n\n\napp = Application('foo', 'mymodule:foo')\nwith Given(app, environ={'bar': 'baz'}):\n    assert stdout == 'bar: baz\\n'\n\n    # Without any variable\n    when(environ=given - 'bar')\n    assert stdout == '\\n'\n\n    # Add another variables\n    when(environ=given + {'qux': 'quux'})\n    assert stdout == 'bar: baz qux: quux\\n'\n```\n\n\nSee tests for more examples.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Test any command line interface in BDD manner.",
    "version": "2.9.4",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "6ddb89a7a18aa76e83b616dfad90619d",
                "sha256": "762944d3efdce205f121b9c0cc12b124b5caccfb0a3f44d4bb72bb318f48a175"
            },
            "downloads": -1,
            "filename": "bddcli-2.9.4.tar.gz",
            "has_sig": false,
            "md5_digest": "6ddb89a7a18aa76e83b616dfad90619d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9391,
            "upload_time": "2022-12-05T21:08:51",
            "upload_time_iso_8601": "2022-12-05T21:08:51.814660Z",
            "url": "https://files.pythonhosted.org/packages/00/65/510fc767394ee3af9fac7d5199ce69607fc807a48e9b5f7444e13de6b507/bddcli-2.9.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-05 21:08:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "pylover",
    "github_project": "bddcli",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bddcli"
}
        
Elapsed time: 0.06164s