@@ -508,134 +508,3 @@ 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 , FutureWarning )
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
610-
611-
612- def test_version_deprecation_via_get_version (monkeypatch : pytest .MonkeyPatch ) -> None :
613- """Test deprecation warning fires through get_version() call.
614-
615- This integration test verifies the warning is emitted when calling
616- get_version() with an old tmux version, testing the full call chain.
617- """
618- import warnings
619-
620- import libtmux .common
621-
622- class MockTmuxOutput :
623- stdout : t .ClassVar = ["tmux 3.1" ]
624- stderr : t .ClassVar [list [str ]] = []
625-
626- def mock_tmux_cmd (* args : t .Any , ** kwargs : t .Any ) -> MockTmuxOutput :
627- return MockTmuxOutput ()
628-
629- monkeypatch .setattr (libtmux .common , "_version_deprecation_checked" , False )
630- monkeypatch .setattr (libtmux .common , "tmux_cmd" , mock_tmux_cmd )
631- monkeypatch .delenv ("LIBTMUX_SUPPRESS_VERSION_WARNING" , raising = False )
632-
633- with warnings .catch_warnings (record = True ) as w :
634- warnings .simplefilter ("always" )
635- version = libtmux .common .get_version ()
636-
637- assert str (version ) == "3.1"
638- assert len (w ) == 1
639- assert issubclass (w [0 ].category , FutureWarning )
640- assert "3.1" in str (w [0 ].message )
641- assert "3.2a" in str (w [0 ].message )
0 commit comments