Skip to main content

Test any command line interface in BDD manner.

Project description

bddcli

Test any command line interface in BDD manner.

PyPI Build Coverage Status

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.

pip install bddcli

Quickstart

Arguments

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

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

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

Standard output and error

from bddcli import stderr, stdout

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

Environment variables

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bddcli-2.10.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bddcli-2.10.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file bddcli-2.10.1.tar.gz.

File metadata

  • Download URL: bddcli-2.10.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bddcli-2.10.1.tar.gz
Algorithm Hash digest
SHA256 6cb92a5c472831bf85e22a6b0500a58fdcfcc1f5a06daa1add2fc4a964972f2d
MD5 6f4f4f65bcb9ba1217ca6e64b9e7d92a
BLAKE2b-256 48884205dedbf287686504f2472e82e597a84dfc5355436f967fa22050f940ba

See more details on using hashes here.

File details

Details for the file bddcli-2.10.1-py3-none-any.whl.

File metadata

  • Download URL: bddcli-2.10.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bddcli-2.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb917b404eaa69aa24b61c752d37ec0ea15af4a6f36f222999bca018da111b93
MD5 2299695508acd3a1b8b03c040234c36d
BLAKE2b-256 2343e5fd3318d6785232f29cc0bb890a11fc874e23b90cdcd026c4ccfb656196

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page