@@ -117,6 +117,25 @@ def test_version_info(
117117 "MockAdaptor Data Interface Version" : "1.5" ,
118118 }
119119
120+ def test_logs_versions_at_startup (self ):
121+ """Verifies that both the runtime and adaptor versions are logged during start()."""
122+ # GIVEN
123+ entrypoint = EntryPoint (FakeAdaptor )
124+
125+ with (
126+ patch .object (entrypoint , "_get_adaptor_package_version" , return_value = "1.2.3" ),
127+ patch .object (runtime_entrypoint .sys , "argv" , ["Adaptor" , "run" ]),
128+ patch .object (runtime_entrypoint , "_logger" ) as mock_logger ,
129+ ):
130+ # WHEN
131+ entrypoint .start ()
132+
133+ # THEN
134+ mock_logger .info .assert_any_call (
135+ f"openjd-adaptor-runtime version: { runtime_entrypoint ._RUNTIME_VERSION } "
136+ )
137+ mock_logger .info .assert_any_call ("FakeAdaptor version: 1.2.3" )
138+
120139 @pytest .mark .parametrize ("integration_version" , ["1.4" , "1.5" ])
121140 def test_is_compatible (
122141 self ,
@@ -904,3 +923,105 @@ def test_raises_on_nonvalid_parsed_data_type(self):
904923
905924 # THEN
906925 assert raised_err .match (f"Expected loaded data to be a dict, but got { type (input )} " )
926+
927+
928+ class TestGetAdaptorPackageVersion :
929+ """
930+ Tests for the EntryPoint._get_adaptor_package_version method
931+ """
932+
933+ def test_returns_version_from_importlib_metadata (self , mock_adaptor_cls : MagicMock ):
934+ """When importlib.metadata can resolve the distribution, return its version."""
935+ # GIVEN
936+ mock_adaptor_cls .__module__ = "deadline.adaptor_for_maya.MayaAdaptor"
937+ entrypoint = EntryPoint (mock_adaptor_cls )
938+
939+ mock_dist = MagicMock ()
940+ mock_dist .version = "1.2.3"
941+
942+ def fake_distribution (name ):
943+ if name == "deadline.adaptor_for_maya.MayaAdaptor" :
944+ return mock_dist
945+ raise runtime_entrypoint .importlib .metadata .PackageNotFoundError (name )
946+
947+ with patch (
948+ "openjd.adaptor_runtime._entrypoint.importlib.metadata.distribution" ,
949+ side_effect = fake_distribution ,
950+ ):
951+ # WHEN
952+ result = entrypoint ._get_adaptor_package_version ()
953+
954+ # THEN
955+ assert result == "1.2.3"
956+
957+ def test_walks_up_module_path (self , mock_adaptor_cls : MagicMock ):
958+ """When the full module path isn't a distribution, walk up until one is found."""
959+ # GIVEN
960+ mock_adaptor_cls .__module__ = "deadline.adaptor_for_maya.adaptor"
961+ entrypoint = EntryPoint (mock_adaptor_cls )
962+
963+ mock_dist = MagicMock ()
964+ mock_dist .version = "2.0.0"
965+
966+ def fake_distribution (name ):
967+ if name == "deadline.adaptor_for_maya" :
968+ return mock_dist
969+ raise runtime_entrypoint .importlib .metadata .PackageNotFoundError (name )
970+
971+ with patch (
972+ "openjd.adaptor_runtime._entrypoint.importlib.metadata.distribution" ,
973+ side_effect = fake_distribution ,
974+ ):
975+ # WHEN
976+ result = entrypoint ._get_adaptor_package_version ()
977+
978+ # THEN
979+ assert result == "2.0.0"
980+
981+ def test_falls_back_to_version_module (self , mock_adaptor_cls : MagicMock ):
982+ """When importlib.metadata can't find the distribution, fall back to _version module."""
983+ # GIVEN
984+ mock_adaptor_cls .__module__ = "deadline.adaptor_for_maya.adaptor"
985+ entrypoint = EntryPoint (mock_adaptor_cls )
986+
987+ mock_version_module = MagicMock ()
988+ mock_version_module .version = "3.5.1"
989+
990+ with (
991+ patch (
992+ "openjd.adaptor_runtime._entrypoint.importlib.metadata.distribution" ,
993+ side_effect = runtime_entrypoint .importlib .metadata .PackageNotFoundError ("x" ),
994+ ),
995+ patch .dict (
996+ runtime_entrypoint .sys .modules ,
997+ {"deadline.adaptor_for_maya._version" : mock_version_module },
998+ ),
999+ ):
1000+ # WHEN
1001+ result = entrypoint ._get_adaptor_package_version ()
1002+
1003+ # THEN
1004+ assert result == "3.5.1"
1005+
1006+ def test_returns_unknown_when_version_not_found (self , mock_adaptor_cls : MagicMock ):
1007+ """When no version can be determined, return 'UNKNOWN' and log a warning."""
1008+ # GIVEN
1009+ mock_adaptor_cls .__module__ = "deadline.adaptor_for_maya.adaptor"
1010+ mock_adaptor_cls .__name__ = "MayaAdaptor"
1011+ entrypoint = EntryPoint (mock_adaptor_cls )
1012+
1013+ with (
1014+ patch (
1015+ "openjd.adaptor_runtime._entrypoint.importlib.metadata.distribution" ,
1016+ side_effect = runtime_entrypoint .importlib .metadata .PackageNotFoundError ("x" ),
1017+ ),
1018+ patch .dict (runtime_entrypoint .sys .modules , {}, clear = False ),
1019+ ):
1020+ # Ensure the _version module is NOT in sys.modules
1021+ runtime_entrypoint .sys .modules .pop ("deadline.adaptor_for_maya._version" , None )
1022+
1023+ # WHEN
1024+ result = entrypoint ._get_adaptor_package_version ()
1025+
1026+ # THEN
1027+ assert result == "UNKNOWN"
0 commit comments