"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "docs/testing.rst" between
flask-1.1.1.tar.gz and flask-1.1.2.tar.gz

About: Flask is a lightweight Python WSGI web application framework.

testing.rst  (flask-1.1.1):testing.rst  (flask-1.1.2)
skipping to change at line 416 skipping to change at line 416
Flask provides :meth:`~flask.Flask.test_cli_runner` to create a Flask provides :meth:`~flask.Flask.test_cli_runner` to create a
:class:`~flask.testing.FlaskCliRunner` that passes the Flask app to the :class:`~flask.testing.FlaskCliRunner` that passes the Flask app to the
CLI automatically. Use its :meth:`~flask.testing.FlaskCliRunner.invoke` CLI automatically. Use its :meth:`~flask.testing.FlaskCliRunner.invoke`
method to call commands in the same way they would be called from the method to call commands in the same way they would be called from the
command line. :: command line. ::
import click import click
@app.cli.command('hello') @app.cli.command('hello')
@click.option('--name', default='World') @click.option('--name', default='World')
def hello_command(name) def hello_command(name):
click.echo(f'Hello, {name}!') click.echo(f'Hello, {name}!')
def test_hello(): def test_hello():
runner = app.test_cli_runner() runner = app.test_cli_runner()
# invoke the command directly # invoke the command directly
result = runner.invoke(hello_command, ['--name', 'Flask']) result = runner.invoke(hello_command, ['--name', 'Flask'])
assert 'Hello, Flask' in result.output assert 'Hello, Flask' in result.output
# or by name # or by name
skipping to change at line 443 skipping to change at line 443
If you want to test how your command parses parameters, without running If you want to test how your command parses parameters, without running
the command, use its :meth:`~click.BaseCommand.make_context` method. the command, use its :meth:`~click.BaseCommand.make_context` method.
This is useful for testing complex validation rules and custom types. :: This is useful for testing complex validation rules and custom types. ::
def upper(ctx, param, value): def upper(ctx, param, value):
if value is not None: if value is not None:
return value.upper() return value.upper()
@app.cli.command('hello') @app.cli.command('hello')
@click.option('--name', default='World', callback=upper) @click.option('--name', default='World', callback=upper)
def hello_command(name) def hello_command(name):
click.echo(f'Hello, {name}!') click.echo(f'Hello, {name}!')
def test_hello_params(): def test_hello_params():
context = hello_command.make_context('hello', ['--name', 'flask']) context = hello_command.make_context('hello', ['--name', 'flask'])
assert context.params['name'] == 'FLASK' assert context.params['name'] == 'FLASK'
.. _click: https://click.palletsprojects.com/ .. _click: https://click.palletsprojects.com/
.. _utilities for testing: https://click.palletsprojects.com/testing/ .. _utilities for testing: https://click.palletsprojects.com/testing/
 End of changes. 2 change blocks. 
2 lines changed or deleted 2 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)