GithubHelp home page GithubHelp logo

bddcli's Introduction

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.

bddcli's People

Contributors

cheremnov avatar farzaneka avatar maadiii avatar mohammadsheikhian avatar pylover avatar zen-lover avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bddcli's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.