diff --git a/tests/test_parse_args.py b/tests/test_parse_args.py new file mode 100644 index 0000000..d0b9ebe --- /dev/null +++ b/tests/test_parse_args.py @@ -0,0 +1,60 @@ +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)