@@ -213,7 +213,7 @@ def test_console_size(mock_terminal_size):
213213)
214214def test_get_args_no_spaces (monkeypatch , argv , find_args , expected_args_dict ):
215215 monkeypatch .setattr (sys , "argv" , argv )
216- args_result = Console .get_args (find_args , allow_spaces = False )
216+ args_result = Console .get_args (allow_spaces = False , ** find_args )
217217 assert isinstance (args_result , Args )
218218 assert args_result .dict () == expected_args_dict
219219 for key , expected in expected_args_dict .items ():
@@ -336,7 +336,7 @@ def test_get_args_no_spaces(monkeypatch, argv, find_args, expected_args_dict):
336336)
337337def test_get_args_with_spaces (monkeypatch , argv , find_args , expected_args_dict ):
338338 monkeypatch .setattr (sys , "argv" , argv )
339- args_result = Console .get_args (find_args , allow_spaces = True )
339+ args_result = Console .get_args (allow_spaces = True , ** find_args )
340340 assert isinstance (args_result , Args )
341341 assert args_result .dict () == expected_args_dict
342342
@@ -345,63 +345,37 @@ def test_get_args_flag_without_value(monkeypatch):
345345 """Test that flags without values have None as their value, not True."""
346346 # TEST SINGLE FLAG WITHOUT VALUE AT END OF ARGS
347347 monkeypatch .setattr (sys , "argv" , ["script.py" , "--verbose" ])
348- args_result = Console .get_args ({ " verbose" : {"--verbose" } })
348+ args_result = Console .get_args (verbose = {"--verbose" })
349349 assert args_result .verbose .exists is True
350350 assert args_result .verbose .value is None
351351
352352 # TEST FLAG WITHOUT VALUE FOLLOWED BY ANOTHER FLAG
353353 monkeypatch .setattr (sys , "argv" , ["script.py" , "--verbose" , "--debug" ])
354- args_result = Console .get_args ({ " verbose" : {"--verbose" }, " debug" : {"--debug" } })
354+ args_result = Console .get_args (verbose = {"--verbose" }, debug = {"--debug" })
355355 assert args_result .verbose .exists is True
356356 assert args_result .verbose .value is None
357357 assert args_result .debug .exists is True
358358 assert args_result .debug .value is None
359359
360360 # TEST FLAG WITH DEFAULT VALUE BUT NO PROVIDED VALUE
361361 monkeypatch .setattr (sys , "argv" , ["script.py" , "--mode" ])
362- args_result = Console .get_args ({ " mode" : {"flags" : {"--mode" }, "default" : "production" } })
362+ args_result = Console .get_args (mode = {"flags" : {"--mode" }, "default" : "production" })
363363 assert args_result .mode .exists is True
364364 assert args_result .mode .value is None
365365
366366
367- def test_get_args_invalid_alias ():
368- with pytest .raises (TypeError , match = "Argument alias 'invalid-alias' is invalid." ):
369- Args (** {"invalid-alias" : {"exists" : False , "value" : None }})
370-
371- with pytest .raises (TypeError , match = "Argument alias '123start' is invalid." ):
372- Args (** {"123start" : {"exists" : False , "value" : None }})
373-
374-
375- def test_get_args_invalid_config ():
376- with pytest .raises (TypeError , match = "Invalid configuration type for alias 'bad_config'.\n "
377- "Must be a set, dict, literal 'before' or literal 'after'." ):
378- Console .get_args ({"bad_config" : 123 }) # type: ignore[assignment]
379-
380- with pytest .raises (ValueError ,
381- match = "Invalid configuration for alias 'missing_flags'. Dictionary must contain a 'flags' key." ):
382- Console .get_args ({"missing_flags" : {"default" : "value" }}) # type: ignore[assignment]
383-
384- with pytest .raises (ValueError ,
385- match = "Invalid configuration for alias 'bad_flags'. Dictionary must contain a 'default' key.\n "
386- "Use a simple set of strings if no default value is needed and only flags are to be specified." ):
387- Console .get_args ({"bad_flags" : {"flags" : ["--flag" ]}}) # type: ignore[assignment]
388-
389- with pytest .raises (ValueError , match = "Invalid 'flags' for alias 'bad_flags'. Must be a set of strings." ):
390- Console .get_args ({"bad_flags" : {"flags" : "not-a-set" , "default" : "value" }}) # type: ignore[assignment]
391-
392-
393367def test_get_args_duplicate_flag ():
394368 with pytest .raises (ValueError , match = "Duplicate flag '-f' found. It's assigned to both 'file1' and 'file2'." ):
395- Console .get_args ({ " file1" : {"-f" , "--file1" }, " file2" : {"flags" : {"-f" , "--file2" }, "default" : "..." } })
369+ Console .get_args (file1 = {"-f" , "--file1" }, file2 = {"flags" : {"-f" , "--file2" }, "default" : "..." })
396370
397371 with pytest .raises (ValueError , match = "Duplicate flag '--long' found. It's assigned to both 'arg1' and 'arg2'." ):
398- Console .get_args ({ " arg1" : {"flags" : {"--long" }, "default" : "..." }, " arg2" : {"-a" , "--long" } })
372+ Console .get_args (arg1 = {"flags" : {"--long" }, "default" : "..." }, arg2 = {"-a" , "--long" })
399373
400374
401375def test_get_args_dash_values_not_treated_as_flags (monkeypatch ):
402376 """Test that values starting with dashes are not treated as flags unless explicitly defined"""
403377 monkeypatch .setattr (sys , "argv" , ["script.py" , "-v" , "-42" , "--input" , "-3.14" ])
404- result = Console .get_args ({ " verbose" : {"-v" }, " input" : {"--input" } })
378+ result = Console .get_args (verbose = {"-v" }, input = {"--input" })
405379
406380 assert result .verbose .exists is True
407381 assert result .verbose .value == "-42"
@@ -412,7 +386,7 @@ def test_get_args_dash_values_not_treated_as_flags(monkeypatch):
412386def test_get_args_dash_strings_as_values (monkeypatch ):
413387 """Test that dash-prefixed strings are treated as values when not defined as flags"""
414388 monkeypatch .setattr (sys , "argv" , ["script.py" , "-f" , "--not-a-flag" , "-t" , "-another-value" ])
415- result = Console .get_args ({ " file" : {"-f" }, " text" : {"-t" } })
389+ result = Console .get_args (file = {"-f" }, text = {"-t" })
416390
417391 assert result .file .exists is True
418392 assert result .file .value == "--not-a-flag"
@@ -423,7 +397,7 @@ def test_get_args_dash_strings_as_values(monkeypatch):
423397def test_get_args_positional_with_dashes_before (monkeypatch ):
424398 """Test that positional 'before' arguments include dash-prefixed values"""
425399 monkeypatch .setattr (sys , "argv" , ["script.py" , "-123" , "--some-file" , "normal" , "-v" ])
426- result = Console .get_args ({ " before_args" : " before" , " verbose" : {"-v" } })
400+ result = Console .get_args (before_args = " before" , verbose = {"-v" })
427401
428402 assert result .before_args .exists is True
429403 assert result .before_args .values == ["-123" , "--some-file" , "normal" ]
@@ -434,7 +408,7 @@ def test_get_args_positional_with_dashes_before(monkeypatch):
434408def test_get_args_positional_with_dashes_after (monkeypatch ):
435409 """Test that positional 'after' arguments include dash-prefixed values"""
436410 monkeypatch .setattr (sys , "argv" , ["script.py" , "-v" , "value" , "-123" , "--output-file" , "-negative" ])
437- result = Console .get_args ({ " verbose" : {"-v" }, " after_args" : " after"} )
411+ result = Console .get_args (verbose = {"-v" }, after_args = " after" )
438412
439413 assert result .verbose .exists is True
440414 assert result .verbose .value == "value"
@@ -445,7 +419,7 @@ def test_get_args_positional_with_dashes_after(monkeypatch):
445419def test_get_args_multiword_with_dashes (monkeypatch ):
446420 """Test multiword values with dashes when allow_spaces=True"""
447421 monkeypatch .setattr (sys , "argv" , ["script.py" , "-m" , "start" , "-middle" , "--end" , "-f" , "other" ])
448- result = Console .get_args ({ "message" : {"-m" }, " file" : {"-f" }}, allow_spaces = True )
422+ result = Console .get_args (allow_spaces = True , message = {"-m" }, file = {"-f" })
449423
450424 assert result .message .exists is True
451425 assert result .message .value == "start -middle --end"
@@ -461,13 +435,13 @@ def test_get_args_mixed_dash_scenarios(monkeypatch):
461435 "after1" , "-also-not-flag"
462436 ]
463437 )
464- result = Console .get_args ({
465- " before" : "before" ,
466- " verbose" : {"-v" },
467- " debug" : {"-d" },
468- " file" : {"--file" },
469- " after" : "after" ,
470- } )
438+ result = Console .get_args (
439+ before = "before" ,
440+ verbose = {"-v" },
441+ debug = {"-d" },
442+ file = {"--file" },
443+ after = "after" ,
444+ )
471445
472446 assert result .before .exists is True
473447 assert result .before .values == ["before1" , "-not-flag" , "before2" ]
0 commit comments