@@ -508,3 +508,102 @@ 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 VersionDeprecationFixture (t .NamedTuple ):
514+ """Test fixture for version deprecation warning."""
515+
516+ test_id : str
517+ version : str
518+ suppress_env : bool
519+ expected_warning : bool
520+
521+
522+ VERSION_DEPRECATION_FIXTURES : list [VersionDeprecationFixture ] = [
523+ VersionDeprecationFixture (
524+ test_id = "deprecated_version_warns" ,
525+ version = "3.1" ,
526+ suppress_env = False ,
527+ expected_warning = True ,
528+ ),
529+ VersionDeprecationFixture (
530+ test_id = "old_deprecated_version_warns" ,
531+ version = "2.9" ,
532+ suppress_env = False ,
533+ expected_warning = True ,
534+ ),
535+ VersionDeprecationFixture (
536+ test_id = "current_version_no_warning" ,
537+ version = "3.2a" ,
538+ suppress_env = False ,
539+ expected_warning = False ,
540+ ),
541+ VersionDeprecationFixture (
542+ test_id = "newer_version_no_warning" ,
543+ version = "3.5" ,
544+ suppress_env = False ,
545+ expected_warning = False ,
546+ ),
547+ VersionDeprecationFixture (
548+ test_id = "env_var_suppresses_warning" ,
549+ version = "3.0" ,
550+ suppress_env = True ,
551+ expected_warning = False ,
552+ ),
553+ ]
554+
555+
556+ @pytest .mark .parametrize (
557+ list (VersionDeprecationFixture ._fields ),
558+ VERSION_DEPRECATION_FIXTURES ,
559+ ids = [test .test_id for test in VERSION_DEPRECATION_FIXTURES ],
560+ )
561+ def test_version_deprecation_warning (
562+ test_id : str ,
563+ version : str ,
564+ suppress_env : bool ,
565+ expected_warning : bool ,
566+ monkeypatch : pytest .MonkeyPatch ,
567+ ) -> None :
568+ """Test version deprecation warning behavior."""
569+ import warnings
570+
571+ import libtmux .common
572+
573+ # Reset the warning flag for each test
574+ monkeypatch .setattr (libtmux .common , "_version_deprecation_checked" , False )
575+
576+ # Set or clear the suppress env var
577+ if suppress_env :
578+ monkeypatch .setenv ("LIBTMUX_SUPPRESS_VERSION_WARNING" , "1" )
579+ else :
580+ monkeypatch .delenv ("LIBTMUX_SUPPRESS_VERSION_WARNING" , raising = False )
581+
582+ with warnings .catch_warnings (record = True ) as w :
583+ warnings .simplefilter ("always" )
584+ libtmux .common ._check_deprecated_version (LooseVersion (version ))
585+
586+ if expected_warning :
587+ assert len (w ) == 1
588+ assert issubclass (w [0 ].category , DeprecationWarning )
589+ assert version in str (w [0 ].message )
590+ assert "3.2a" in str (w [0 ].message )
591+ else :
592+ assert len (w ) == 0
593+
594+
595+ def test_version_deprecation_warns_once (monkeypatch : pytest .MonkeyPatch ) -> None :
596+ """Test that deprecation warning only fires once per process."""
597+ import warnings
598+
599+ import libtmux .common
600+
601+ monkeypatch .setattr (libtmux .common , "_version_deprecation_checked" , False )
602+ monkeypatch .delenv ("LIBTMUX_SUPPRESS_VERSION_WARNING" , raising = False )
603+
604+ with warnings .catch_warnings (record = True ) as w :
605+ warnings .simplefilter ("always" )
606+ libtmux .common ._check_deprecated_version (LooseVersion ("3.1" ))
607+ libtmux .common ._check_deprecated_version (LooseVersion ("3.1" ))
608+
609+ assert len (w ) == 1
0 commit comments