@@ -508,3 +508,68 @@ def mock_get_version() -> LooseVersion:
508508 elif check_type == "type_check" :
509509 assert mock_version is not None # For type checker
510510 assert isinstance (has_version (mock_version ), bool )
511+
512+
513+ class TestVersionDeprecationWarning :
514+ """Tests for tmux version deprecation warnings."""
515+
516+ def test_deprecated_version_warns_once (
517+ self ,
518+ monkeypatch : pytest .MonkeyPatch ,
519+ ) -> None :
520+ """Warn once when tmux version is below TMUX_SOFT_MIN_VERSION."""
521+ import warnings
522+
523+ import libtmux .common
524+
525+ # Reset the warning flag
526+ monkeypatch .setattr (libtmux .common , "_version_deprecation_checked" , False )
527+
528+ # Clear any env var that might suppress
529+ monkeypatch .delenv ("LIBTMUX_SUPPRESS_VERSION_WARNING" , raising = False )
530+
531+ with warnings .catch_warnings (record = True ) as w :
532+ warnings .simplefilter ("always" )
533+ libtmux .common ._check_deprecated_version (LooseVersion ("3.1" ))
534+ libtmux .common ._check_deprecated_version (LooseVersion ("3.1" ))
535+
536+ assert len (w ) == 1
537+ assert issubclass (w [0 ].category , DeprecationWarning )
538+ assert "3.1" in str (w [0 ].message )
539+ assert "3.2a" in str (w [0 ].message )
540+
541+ def test_current_version_no_warning (
542+ self ,
543+ monkeypatch : pytest .MonkeyPatch ,
544+ ) -> None :
545+ """No warning when tmux version meets minimum."""
546+ import warnings
547+
548+ import libtmux .common
549+
550+ monkeypatch .setattr (libtmux .common , "_version_deprecation_checked" , False )
551+ monkeypatch .delenv ("LIBTMUX_SUPPRESS_VERSION_WARNING" , raising = False )
552+
553+ with warnings .catch_warnings (record = True ) as w :
554+ warnings .simplefilter ("always" )
555+ libtmux .common ._check_deprecated_version (LooseVersion ("3.2a" ))
556+
557+ assert len (w ) == 0
558+
559+ def test_env_var_suppresses_warning (
560+ self ,
561+ monkeypatch : pytest .MonkeyPatch ,
562+ ) -> None :
563+ """LIBTMUX_SUPPRESS_VERSION_WARNING suppresses deprecation warning."""
564+ import warnings
565+
566+ import libtmux .common
567+
568+ monkeypatch .setattr (libtmux .common , "_version_deprecation_checked" , False )
569+ monkeypatch .setenv ("LIBTMUX_SUPPRESS_VERSION_WARNING" , "1" )
570+
571+ with warnings .catch_warnings (record = True ) as w :
572+ warnings .simplefilter ("always" )
573+ libtmux .common ._check_deprecated_version (LooseVersion ("3.0" ))
574+
575+ assert len (w ) == 0
0 commit comments