from pargv import parse_args import pytest def test_io(): for (argv, args, kwargs) in ( # Arguments ('name', ['name'], {}), ('name command', ['name', 'command'], {}), # Hyphens ('a-b', ['a_b'], {}), ('---a', [], {'_a': True}), ('-a-', [], {'a': True, '_': True}), # Options ('--option', [], {'option': True}), ('--option=2', [], {'option': '2'}), ('--option=2 4', [], {'option': ['2', '4']}), ('--option 2', [], {'option': '2'}), ('--option 2 4', [], {'option': ['2', '4']}), # Short options ('-o', [], {'o': True}), ('-o=2', [], {'o': '2'}), ('-o=2 4', [], {'o': ['2', '4']}), ('-o 2', [], {'o': '2'}), ('-o 2 4', [], {'o': ['2', '4']}), # Multiple short options ('-ox', [], {'o': True, 'x': True}), ('-ox=2', [], {'o': True, 'x': '2'}), ('-ox=2 4', [], {'o': True, 'x': ['2', '4']}), ('-ox 2', [], {'o': True, 'x': '2'}), ('-ox 2 4', [], {'o': True, 'x': ['2', '4']}), ): assert parse_args(argv.split()) == (args, kwargs) def test_empty_input(): for argv in ( '', [], {}, None, False, ): args, kwargs = parse_args(argv) assert (len(args), len(kwargs)) == (1, 0) def test_type_errors(): for argv in ( 1, True, {'a': 1}, ): with pytest.raises(TypeError): parse_args(argv) def test_attribute_errors(): for argv in ( [1], ): with pytest.raises(AttributeError): parse_args(argv)