@@ -27,6 +27,13 @@ def test_invalid_items(self):
2727 for item in items :
2828 pytest .raises (argparse .ArgumentTypeError , self .key_value_arg , item )
2929
30+ def test_invalid_item_without_separator_provides_helpful_error (self ):
31+ """Test that items without separators show a helpful error message."""
32+ with pytest .raises (argparse .ArgumentTypeError ) as exc_info :
33+ self .key_value_arg ('Bar' )
34+ assert 'Did you mean to quote it' in str (exc_info .value )
35+ assert 'field="value Bar"' in str (exc_info .value )
36+
3037 def test_escape_separator (self ):
3138 items = RequestItems .from_args ([
3239 # headers
@@ -63,6 +70,16 @@ def test_backslash_before_non_special_character_does_not_escape(
6370 actual = self .key_value_arg (string )
6471 assert actual == expected
6572
73+ @pytest .mark .parametrize ('item_string, expected_value' , [
74+ ('field=value with spaces' , 'value with spaces' ),
75+ ('field_name="Foo Bar"' , '"Foo Bar"' ),
76+ ('data=Hello World Test' , 'Hello World Test' ),
77+ ])
78+ def test_values_with_spaces_when_properly_quoted (self , item_string , expected_value ):
79+ """Test that values with spaces work correctly when properly quoted."""
80+ result = self .key_value_arg (item_string )
81+ assert result .value == expected_value
82+
6683 def test_escape_longsep (self ):
6784 items = RequestItems .from_args ([
6885 self .key_value_arg (r'bob\:==foo' ),
0 commit comments