def test_default_cmd(): conf = """\ clg: default_cmd: run subparsers: run: help: 'run as: $prog run' install: help: 'run as: $prog install | sudo bash'""" c = Config(conf, args=['netapplet.py']) assert 'run' == c.command0 with exc(SystemExit) as e: c = Config(conf, args=['netapplet.py', '-help']) assert e().code.startswith('usage:') conf = """\ clg: default_cmd: uninstall subparsers: run: help: 'run as: $prog run'""" with exc(SystemExit) as e: c = Config(conf, args=['netapplet.py']) assert e().code.startswith('usage:')
def test_main_usage(c): '''loadconfig main usage unittest''' conf_option = '-E="{}"'.format(c.conf) exp = '{} {}'.format(c.prog, c.test_version) with exc(SystemExit) as e: main([c.prog, conf_option, '-v']) assert exp == e().args[0]
def test_verprog_from_options(f): with tempfile() as fh, exc(SystemExit) as e: fh.write(f.conf) fh.flush() Config(types={basename}, args=[f.prog, '-v', '-E="prog: {}"'.format(f.prog), '-C="{}"'.format(fh.name), '-E="version: {}"'.format(f.version)]) assert '{} {}'.format(f.prog, f.version) == e().args[0]
def test_help(f): '''Test version and program show properly.''' with exc(SystemExit) as e: Config(args=[f.prog, '-h', '-E="{}"'.format(f.conf)], version=f.version, types={basename}) exp = dedent('''\ usage: dbuild [-h] [-v] [-e EXTRA_CONFIG] host [args [args ...]] Build a full system positional arguments: host Host to build args extra arguments optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit -e EXTRA_CONFIG, --extra-config EXTRA_CONFIG''') assert exp == e().args[0]
def test_exc(): with exc() as e: 0 / 0 assert isinstance(e(), ZeroDivisionError)
def test_Run_unicode(): '''Test unicode is handled properly''' with exc(UnicodeDecodeError) as e: Run("echo -e '\xe2'") assert not e()
def test_verprog(f): '''Test version and program show properly.''' with exc(SystemExit) as e: Config(args=[f.prog, '-v', '-E="{}"'.format(f.conf)], version=f.version, types={basename}) assert '{} {}'.format(f.prog, f.version) == e().args[0]