@@ -342,15 +342,15 @@ def test_log_no_title(mock_formatcodes_print):
342342 Console .log (title = None , prompt = "Just a message" )
343343
344344 mock_formatcodes_print .assert_called_once ()
345- args , kwargs = mock_formatcodes_print .call_args
345+ args , _ = mock_formatcodes_print .call_args
346346 assert "Just a message" in args [0 ]
347347
348348
349349def test_debug_active (mock_formatcodes_print ):
350350 Console .debug ("Debug message" , active = True )
351351
352352 assert mock_formatcodes_print .call_count == 2
353- args , kwargs = mock_formatcodes_print .call_args_list [0 ]
353+ args , _ = mock_formatcodes_print .call_args_list [0 ]
354354 assert "DEBUG" in args [0 ]
355355 assert "Debug message" in args [0 ]
356356
@@ -365,7 +365,7 @@ def test_info(mock_formatcodes_print):
365365 Console .info ("Info message" )
366366
367367 assert mock_formatcodes_print .call_count == 2
368- args , kwargs = mock_formatcodes_print .call_args_list [0 ]
368+ args , _ = mock_formatcodes_print .call_args_list [0 ]
369369 assert "INFO" in args [0 ]
370370 assert "Info message" in args [0 ]
371371
@@ -374,7 +374,7 @@ def test_done(mock_formatcodes_print):
374374 Console .done ("Task completed" )
375375
376376 assert mock_formatcodes_print .call_count == 2
377- args , kwargs = mock_formatcodes_print .call_args_list [0 ]
377+ args , _ = mock_formatcodes_print .call_args_list [0 ]
378378 assert "DONE" in args [0 ]
379379 assert "Task completed" in args [0 ]
380380
@@ -383,7 +383,7 @@ def test_warn(mock_formatcodes_print):
383383 Console .warn ("Warning message" )
384384
385385 assert mock_formatcodes_print .call_count == 2
386- args , kwargs = mock_formatcodes_print .call_args_list [0 ]
386+ args , _ = mock_formatcodes_print .call_args_list [0 ]
387387 assert "WARN" in args [0 ]
388388 assert "Warning message" in args [0 ]
389389
@@ -395,7 +395,7 @@ def test_fail(mock_formatcodes_print, monkeypatch):
395395 Console .fail ("Error occurred" )
396396
397397 assert mock_formatcodes_print .call_count >= 2
398- args , kwargs = mock_formatcodes_print .call_args_list [0 ]
398+ args , _ = mock_formatcodes_print .call_args_list [0 ]
399399 assert "FAIL" in args [0 ]
400400 assert "Error occurred" in args [0 ]
401401
@@ -409,7 +409,7 @@ def test_exit_method(mock_formatcodes_print, monkeypatch):
409409 Console .exit ("Program ending" )
410410
411411 assert mock_formatcodes_print .call_count >= 2
412- args , kwargs = mock_formatcodes_print .call_args_list [0 ]
412+ args , _ = mock_formatcodes_print .call_args_list [0 ]
413413 assert "EXIT" in args [0 ]
414414 assert "Program ending" in args [0 ]
415415
@@ -420,7 +420,7 @@ def test_log_box_filled(mock_formatcodes_print):
420420 Console .log_box_filled ("Line 1" , "Line 2" , box_bg_color = "green" )
421421
422422 mock_formatcodes_print .assert_called_once ()
423- args , kwargs = mock_formatcodes_print .call_args
423+ args , _ = mock_formatcodes_print .call_args
424424 assert "Line 1" in args [0 ]
425425 assert "Line 2" in args [0 ]
426426
@@ -429,7 +429,7 @@ def test_log_box_bordered(mock_formatcodes_print):
429429 Console .log_box_bordered ("Content line" , border_type = "rounded" )
430430
431431 mock_formatcodes_print .assert_called_once ()
432- args , kwargs = mock_formatcodes_print .call_args
432+ args , _ = mock_formatcodes_print .call_args
433433 assert "Content line" in args [0 ]
434434
435435
@@ -457,6 +457,245 @@ def test_confirm_default_no(mock_builtin_input):
457457 assert result is False
458458
459459
460+ @pytest .fixture
461+ def mock_prompt_session (monkeypatch ):
462+ mock_session = MagicMock ()
463+ mock_session_class = MagicMock (return_value = mock_session )
464+ mock_session .prompt .return_value = None
465+ monkeypatch .setattr (console ._pt , "PromptSession" , mock_session_class )
466+ return mock_session_class , mock_session
467+
468+
469+ def test_input_creates_prompt_session (mock_prompt_session , mock_formatcodes_print ):
470+ """Test that Console.input creates a PromptSession with correct parameters."""
471+ mock_session_class , mock_session = mock_prompt_session
472+
473+ Console .input ("Enter text: " )
474+
475+ assert mock_session_class .called
476+ call_kwargs = mock_session_class .call_args [1 ]
477+ assert 'message' in call_kwargs
478+ assert 'validator' in call_kwargs
479+ assert 'validate_while_typing' in call_kwargs
480+ assert 'key_bindings' in call_kwargs
481+ assert 'bottom_toolbar' in call_kwargs
482+ assert 'style' in call_kwargs
483+ mock_session .prompt .assert_called_once ()
484+
485+
486+ def test_input_with_placeholder (mock_prompt_session , mock_formatcodes_print ):
487+ """Test that placeholder is correctly passed to PromptSession."""
488+ mock_session_class , _ = mock_prompt_session
489+
490+ Console .input ("Enter text: " , placeholder = "Type here..." )
491+
492+ assert mock_session_class .called
493+ call_kwargs = mock_session_class .call_args [1 ]
494+ assert 'placeholder' in call_kwargs
495+ assert call_kwargs ['placeholder' ] != ""
496+
497+
498+ def test_input_without_placeholder (mock_prompt_session , mock_formatcodes_print ):
499+ """Test that placeholder is empty when not provided."""
500+ mock_session_class , _ = mock_prompt_session
501+
502+ Console .input ("Enter text: " )
503+
504+ assert mock_session_class .called
505+ call_kwargs = mock_session_class .call_args [1 ]
506+ assert 'placeholder' in call_kwargs
507+ assert call_kwargs ['placeholder' ] == ""
508+
509+
510+ def test_input_with_validator_function (mock_prompt_session , mock_formatcodes_print ):
511+ """Test that a custom validator function is properly handled."""
512+ mock_session_class , _ = mock_prompt_session
513+
514+ def email_validator (text ):
515+ if "@" not in text :
516+ return "Invalid email"
517+ return None
518+
519+ Console .input ("Enter email: " , validator = email_validator )
520+
521+ assert mock_session_class .called
522+ call_kwargs = mock_session_class .call_args [1 ]
523+ assert 'validator' in call_kwargs
524+ validator_instance = call_kwargs ['validator' ]
525+ assert hasattr (validator_instance , 'validate' )
526+
527+
528+ def test_input_with_length_constraints (mock_prompt_session , mock_formatcodes_print ):
529+ """Test that min_len and max_len are properly handled."""
530+ mock_session_class , _ = mock_prompt_session
531+
532+ Console .input ("Enter text: " , min_len = 3 , max_len = 10 )
533+
534+ assert mock_session_class .called
535+ call_kwargs = mock_session_class .call_args [1 ]
536+ assert 'validator' in call_kwargs
537+ validator_instance = call_kwargs ['validator' ]
538+ assert hasattr (validator_instance , 'validate' )
539+
540+
541+ def test_input_with_allowed_chars (mock_prompt_session , mock_formatcodes_print ):
542+ """Test that allowed_chars parameter is handled."""
543+ mock_session_class , _ = mock_prompt_session
544+
545+ Console .input ("Enter digits only: " , allowed_chars = "0123456789" )
546+
547+ assert mock_session_class .called
548+ call_kwargs = mock_session_class .call_args [1 ]
549+ assert 'key_bindings' in call_kwargs
550+ assert call_kwargs ['key_bindings' ] is not None
551+
552+
553+ def test_input_disable_paste (mock_prompt_session , mock_formatcodes_print ):
554+ """Test that allow_paste=False is handled."""
555+ mock_session_class , _ = mock_prompt_session
556+
557+ Console .input ("Enter text: " , allow_paste = False )
558+
559+ assert mock_session_class .called
560+ call_kwargs = mock_session_class .call_args [1 ]
561+ assert 'key_bindings' in call_kwargs
562+ assert call_kwargs ['key_bindings' ] is not None
563+
564+
565+ def test_input_with_start_end_formatting (mock_prompt_session , mock_formatcodes_print ):
566+ """Test that start and end parameters trigger FormatCodes.print calls."""
567+ mock_session_class , _ = mock_prompt_session
568+
569+ Console .input ("Enter text: " , start = "[green]" , end = "[_c]" )
570+
571+ assert mock_session_class .called
572+ assert mock_formatcodes_print .call_count >= 2
573+
574+
575+ def test_input_message_formatting (mock_prompt_session , mock_formatcodes_print ):
576+ """Test that the prompt message is properly formatted."""
577+ mock_session_class , _ = mock_prompt_session
578+
579+ Console .input ("[b]Bold prompt:[_b] " , default_color = "#ABC" )
580+
581+ assert mock_session_class .called
582+ call_kwargs = mock_session_class .call_args [1 ]
583+ assert 'message' in call_kwargs
584+ assert call_kwargs ['message' ] is not None
585+
586+
587+ def test_input_bottom_toolbar_function (mock_prompt_session , mock_formatcodes_print ):
588+ """Test that bottom toolbar function is set up."""
589+ mock_session_class , _ = mock_prompt_session
590+
591+ Console .input ("Enter text: " )
592+
593+ assert mock_session_class .called
594+ call_kwargs = mock_session_class .call_args [1 ]
595+ assert 'bottom_toolbar' in call_kwargs
596+ toolbar_func = call_kwargs ['bottom_toolbar' ]
597+ assert callable (toolbar_func )
598+
599+ try :
600+ result = toolbar_func ()
601+ assert result is not None
602+ except Exception :
603+ pass
604+
605+
606+ def test_input_style_configuration (mock_prompt_session , mock_formatcodes_print ):
607+ """Test that custom style is applied."""
608+ mock_session_class , _ = mock_prompt_session
609+
610+ Console .input ("Enter text: " )
611+
612+ assert mock_session_class .called
613+ call_kwargs = mock_session_class .call_args [1 ]
614+ assert 'style' in call_kwargs
615+ assert call_kwargs ['style' ] is not None
616+
617+
618+ def test_input_validate_while_typing_enabled (mock_prompt_session , mock_formatcodes_print ):
619+ """Test that validate_while_typing is enabled."""
620+ mock_session_class , _ = mock_prompt_session
621+
622+ Console .input ("Enter text: " )
623+
624+ assert mock_session_class .called
625+ call_kwargs = mock_session_class .call_args [1 ]
626+ assert 'validate_while_typing' in call_kwargs
627+ assert call_kwargs ['validate_while_typing' ] is True
628+
629+
630+ def test_input_validator_class_creation (mock_prompt_session , mock_formatcodes_print ):
631+ """Test that InputValidator class is properly instantiated."""
632+ mock_session_class , _ = mock_prompt_session
633+
634+ Console .input ("Enter text: " , min_len = 5 )
635+
636+ assert mock_session_class .called
637+ call_kwargs = mock_session_class .call_args [1 ]
638+ assert 'validator' in call_kwargs
639+ validator_instance = call_kwargs ['validator' ]
640+ assert hasattr (validator_instance , 'validate' )
641+ assert callable (getattr (validator_instance , 'validate' , None ))
642+
643+
644+ def test_input_key_bindings_setup (mock_prompt_session , mock_formatcodes_print ):
645+ """Test that key bindings are properly set up."""
646+ mock_session_class , _ = mock_prompt_session
647+
648+ Console .input ("Enter text: " )
649+
650+ assert mock_session_class .called
651+ call_kwargs = mock_session_class .call_args [1 ]
652+ assert 'key_bindings' in call_kwargs
653+ kb = call_kwargs ['key_bindings' ]
654+ assert kb is not None
655+ assert hasattr (kb , 'bindings' )
656+
657+
658+ def test_input_mask_char_single_character (mock_prompt_session , mock_formatcodes_print ):
659+ """Test that mask_char works with single characters."""
660+ mock_session_class , _ = mock_prompt_session
661+
662+ Console .input ("Enter password: " , mask_char = "*" )
663+
664+ assert mock_session_class .called
665+
666+
667+ def test_input_output_type_int (mock_prompt_session , mock_formatcodes_print ):
668+ """Test that output_type parameter is handled for int conversion."""
669+ mock_session_class , _ = mock_prompt_session
670+
671+ Console .input ("Enter number: " , output_type = int , default_val = 42 )
672+
673+ assert mock_session_class .called
674+
675+
676+ def test_input_default_val_handling (mock_prompt_session , mock_formatcodes_print ):
677+ """Test that default_val parameter is properly handled."""
678+ mock_session_class , _ = mock_prompt_session
679+
680+ Console .input ("Enter text: " , default_val = "default_value" )
681+
682+ assert mock_session_class .called
683+
684+
685+ def test_input_custom_style_object (mock_prompt_session , mock_formatcodes_print ):
686+ """Test that a custom Style object is created."""
687+ mock_session_class , _ = mock_prompt_session
688+
689+ Console .input ("Enter text: " )
690+
691+ assert mock_session_class .called
692+ call_kwargs = mock_session_class .call_args [1 ]
693+ assert 'style' in call_kwargs
694+ style = call_kwargs ['style' ]
695+ assert style is not None
696+ assert hasattr (style , 'style_rules' ) or hasattr (style , '_style' )
697+
698+
460699################################################## PROGRESSBAR TESTS ##################################################
461700
462701
@@ -559,7 +798,7 @@ def test_progressbar_progress_context():
559798
560799def test_progressbar_progress_context_exception ():
561800 pb = ProgressBar ()
562- with (patch .object (pb , 'show_progress' ) as mock_show , patch .object (pb , 'hide_progress' ) as
801+ with (patch .object (pb , 'show_progress' ) as _ , patch .object (pb , 'hide_progress' ) as
563802 mock_hide , patch .object (pb , '_emergency_cleanup' ) as mock_cleanup ):
564803 with pytest .raises (ValueError ):
565804 with pb .progress_context (100 , "Testing" ) as update_progress :
0 commit comments