Пример #1
0
def test_no_version():
    args = ['-h']
    try:
        SkalApp(command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert 'no version set' in capture.stderr.getvalue(), (
        'there should be a warning about no version set')
Пример #2
0
def test_no_description():
    args = ['-h']
    try:
        SkalApp(command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert 'no main documentation' in capture.stderr.getvalue(), (
        'there should be a warning about missing main documentation')
Пример #3
0
def test_missing_module():
    args = ['-h']
    try:
        SkalApp(command_modules=['missing_module']).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert 'does not exist' in capture.stderr.getvalue(), (
        'there should be a warning about module not existing')
Пример #4
0
def test_subcommand_command_no_doc():
    args = [module, 'no_doc']
    try:
        SkalApp(subcommand_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert 'no_doc' in capture.stderr.getvalue(), (
        'there should be a warning about missing documentation')
Пример #5
0
def test_command_syntax_error():
    args = ['-h']
    try:
        SkalApp(command_modules=['skalmodule_syntaxerror']).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert 'SyntaxError' in capture.stderr.getvalue(), (
        'output should contain SyntaxError')
Пример #6
0
def test_subcommand_name_error():
    args = ['-h']
    try:
        SkalApp(subcommand_modules=['skalmodule_nameerror']).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert 'NameError' in capture.stderr.getvalue(), (
        'output should contain NameError')
Пример #7
0
def test_command_non_existing():
    args = ['other']
    try:
        SkalApp(command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code != 0, 'exit code should not be 0'
    assert 'ImportError' not in capture.stderr.getvalue(), (
        'output should not contain ImportError')
Пример #8
0
def test_version():
    args = ['--version']
    version = '0.5.2'
    try:
        SkalApp(command_modules=[module], version=version).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert version in capture.stderr.getvalue(), ('version should be "%s"' %
                                                  version)
Пример #9
0
def test_subcommand_command_doc():
    args = [module, 'first', '-h']
    try:
        SkalApp(subcommand_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    import skalmodule
    doc = inspect.getdoc(skalmodule.first)
    assert doc in capture.stdout.getvalue(), ('help string should be "%s"' %
                                              doc)
Пример #10
0
def test_command_duplicate():
    args = ['-h']
    try:
        SkalApp(command_modules=[module, 'skalmodule_nodoc']).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert 'duplicate' in capture.stderr.getvalue(), (
        'duplicate commands should print warning and be skipped')
    assert 'first command, second instance' not in capture.stdout.getvalue(), (
        'duplicate commands should not be added')
Пример #11
0
def test_description():
    args = ['-h']
    doc = """main help string

    more help here
    """
    try:
        SkalApp(command_modules=[module], description=doc).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    doc = inspect.cleandoc(doc)
    assert doc in capture.stdout.getvalue(), ('help string should be "%s"' %
                                              doc)
Пример #12
0
def test_argument_value_string():
    value = 'test'
    args = ['--string=' + value, 'first']
    try:
        SkalApp(args={
            '-b': {
                'help': 'bool argument',
                'action': 'store_true'
            },
            ('-s', '--string'): {
                'help': 'string argument with long name'
            }
        },
                command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    assert value in capture.stdout.getvalue(), ('output should contain "%s"' %
                                                value)
Пример #13
0
def test_argument_existing():
    args = ['-h']
    try:
        SkalApp(args={
            '-b': {
                'help': 'bool argument',
                'action': 'store_true'
            },
            ('-s', '--string'): {
                'help': 'string argument with long name'
            }
        },
                command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    arg = '-b'
    assert arg in capture.stdout.getvalue(), (
        'help should list argument "%s"' % arg)
Пример #14
0
def test_argument_doc():
    # TODO: fix this test
    args = ['-h']
    try:
        SkalApp(args={
            '-b': {
                'help': 'bool argument',
                'action': 'store_true'
            },
            ('-s', '--string'): {
                'help': 'string argument with long name'
            }
        },
                command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code == 0, 'exit code should be 0'
    arg = '-b'
    doc = 'bool argument'
    assert doc in capture.stdout.getvalue(), (
        'help string for "%s" should be "%s"' % (arg, doc))
Пример #15
0
def test_subcommand_command_existing():
    value = 'first'
    args = [module, value]
    SkalApp(subcommand_modules=[module]).run(args)
    assert value in capture.stdout.getvalue(), ('output should contain "%s"' %
                                                value)
Пример #16
0
def test_subcommand_command_non_existing():
    args = [module, 'other']
    try:
        SkalApp(command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code != 0, 'exit code should not be 0'
Пример #17
0
def test_subcommand_command_without_decorator():
    args = [module, 'second']
    try:
        SkalApp(command_modules=[module]).run(args)
    except SystemExit as e:
        assert e.code != 0, 'exit code should not be 0'