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')
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')
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')
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')
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')
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')
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')
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)
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)
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')
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)
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)
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)
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))
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)
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'
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'