Exemplo n.º 1
0
    def test_summary(self):
        target = CliApplication(tests.sample_app, name='testing')
        assert target.application_summary == 'testing version 1.2.3'

        target = CliApplication(tests.sample_app,
                                name='testing',
                                description='This is a test')
        assert target.application_summary == 'testing version 1.2.3 - This is a test'
Exemplo n.º 2
0
    def test_loading_logging(self):
        import logging
        target = CliApplication(
            tests.sample_app,
            application_settings='tests.sample_app.logging_settings')

        target.dispatch(args=('--log-level', 'WARN', 'settings'))
        assert logging.root.level == logging.WARN
Exemplo n.º 3
0
    def test_loading_logging(self):
        import logging

        target = CliApplication(
            tests.sample_app,
            application_settings="tests.sample_app.logging_settings")

        target.dispatch(args=("--log-level", "WARN", "settings"))
        assert logging.root.level == logging.WARN
Exemplo n.º 4
0
    def test_env_key_settings(self):
        target = CliApplication(tests.sample_app)
        assert target.env_loglevel_key == 'PYAPP_LOGLEVEL'
        assert target.env_settings_key == 'PYAPP_SETTINGS'

        target = CliApplication(tests.sample_app,
                                env_loglevel_key='MYAPP_LOGLEVEL',
                                env_settings_key='MYAPP_SETTINGS')
        assert target.env_loglevel_key == 'MYAPP_LOGLEVEL'
        assert target.env_settings_key == 'MYAPP_SETTINGS'
Exemplo n.º 5
0
    def test_dispatch_args(self):
        closure = {}

        target = CliApplication(tests.sample_app)

        @target.register_handler(cli_name='sample')
        @add_argument('--foo', dest='foo')
        def sample_handler(opts):
            closure['opts'] = opts

        target.dispatch(args=('sample', '--foo', 'bar'))

        assert closure['opts'].foo == 'bar'
Exemplo n.º 6
0
    def test_dispatch_args(self):
        closure = {}

        target = CliApplication(tests.sample_app)

        @target.command(name="sample")
        @argument("--foo", dest="foo")
        def sample_handler(opts):
            closure["opts"] = opts

        target.dispatch(args=("sample", "--foo", "bar"))

        assert closure["opts"].foo == "bar"
Exemplo n.º 7
0
    def test_initialisation_alternate_settings(self):
        target = CliApplication(tests.sample_app,
                                application_settings='tests.runtime_settings')

        assert target.application_settings == 'tests.runtime_settings'
Exemplo n.º 8
0
    def test_initialisation(self):
        target = CliApplication(tests.sample_app)

        assert target.root_module is tests.sample_app
        assert target.application_settings == 'tests.sample_app.default_settings'
        assert len(target._handlers) == 3
Exemplo n.º 9
0
from pyapp import checks
from pyapp import feature_flags
from pyapp.app import CliApplication

import tests.sample_app

app = CliApplication(tests.sample_app)


@app.command
def happy(opts):
    print("=o)")


@app.command
def sad(opts):
    print("=o(")
    return -2


@app.command
def cheeky(opts):
    print("=oD")
    raise KeyboardInterrupt()


@app.command
def angry(opts):
    print(">=o(")
    raise Exception("Grrrr")
Exemplo n.º 10
0
# -*- coding: utf-8 -*-
"""
CLI
~~~

Retort contains a CLI for common functions

"""
from pyapp.app import CliApplication, add_argument

import retort

app = CliApplication(retort, "retort")


@app.command(cli_name='runserver')
@add_argument('HANDLER', help='Module that contains your request handler.')
@add_argument('--host', dest='host', help='Hostname to bind server to.')
@add_argument('--port', type=int, dest='port', help='Port to bind server to.')
@add_argument('--noreload',
              action='store_true',
              dest='no_reload',
              help='Disable automatic reloading.')
@add_argument('--debug',
              action='store_true',
              dest='debug',
              help='Enable debugging.')
def run_server(args):
    import retort.server
    retort.server.run_server(args.HANDLER, args.host, args.port,
                             args.no_reload, args.debug)
Exemplo n.º 11
0
"""
CLI Interface
~~~~~~~~~~~~~

"""
from pyapp.app import Arg
from pyapp.app import CliApplication
from pyapp.app.argument_actions import KeyValueAction
from pyapp.conf import settings

APP = CliApplication(prog="sample", description="Sample pyApp application.")


@APP.command
def foo_do(*, verbose: bool = False):
    """
    Perform a foo operation.
    """
    # Use a command line argument
    if verbose:
        print("Doing foo verbosely!")
    else:
        print("Doing foo.")

    # Print a message from the settings file
    print(settings.FOO_MESSAGE)


class BarGroup:
    group = APP.create_command_group("bar", aliases="b")
Exemplo n.º 12
0
    def test_repr(self):
        target = CliApplication(tests.sample_app, prog="testing")

        assert repr(target) == "CliApplication(<module tests.sample_app>)"
Exemplo n.º 13
0
 def test_summary(self, kwargs, expected):
     target = CliApplication(tests.sample_app, **kwargs)
     assert str(target) == expected
Exemplo n.º 14
0
 def test_env_settings_key(self, kwargs, expected):
     target = CliApplication(tests.sample_app, **kwargs)
     assert target.env_settings_key == expected
Exemplo n.º 15
0
"""
Main CLI
~~~~~~~~

Definition of {{ cookiecutter.project_name }} CLI.

"""

from pyapp.app import CliApplication, argument, CommandOptions


APP = CliApplication()
main = APP.dispatch


@APP.command
@argument("-n", "--name", default="Dave")
def hello(opts: CommandOptions):
    """
    Say hello
    """
    # Do command imports locally to improve startup time!
    print(f"Hello {opts.name}")


@APP.command(name="hello-async")
@argument("-n", "--name", default="Jane")
async def hello_async(opts: CommandOptions):
    """
    Say hello in an AsyncIO run-loop
    """
Exemplo n.º 16
0
"""
Single file sample
"""
from pyapp.app import argument
from pyapp.app import CliApplication
from pyapp.app import CommandOptions
from pyapp.app import KeyValueAction

APP = CliApplication()


@APP.default
def helper(*, bar: dict):
    print(bar)
    # print(opts.bar)


if __name__ == "__main__":
    APP.dispatch()
Exemplo n.º 17
0
from pyapp.app import CliApplication, CommandOptions
from pyapp.injection import inject_into, Args

import sample

app = CliApplication(sample)


def main(args=None):
    app.dispatch(args)


if __name__ == "__main__":
    main()
Exemplo n.º 18
0
from pyapp.app import CliApplication, argument

import sample

app = CliApplication(sample,
                     name="PyApp Sample",
                     description="Sample pyApp application.")


@app.command
def foo(opts):
    print("bar")


if __name__ == "__main__":
    app.dispatch()
Exemplo n.º 19
0
from pyapp.app import CliApplication

app = CliApplication()

if __name__ == "__main__":
    app.dispatch()