1313 get_proc_cmdline ,
1414 get_py_source ,
1515 get_runtime_env_info ,
16+ is_ppc64 ,
17+ is_s390x ,
18+ is_windows ,
1619 log_runtime_env_info ,
1720)
1821
@@ -40,7 +43,7 @@ def test_get_py_source(tmp_path) -> None:
4043 [
4144 (
4245 "non_existent_file.py" ,
43- {"error" : "[Errno 2] No such file or directory: 'non_existent_file.py'" }
46+ {"error" : "[Errno 2] No such file or directory: 'non_existent_file.py'" },
4447 ),
4548 ("temp_file.txt" , {"error" : "Only Python source files are allowed. (*.py)" }),
4649 ],
@@ -60,9 +63,9 @@ def test_get_py_source_exception(mocker) -> None:
6063
6164 with pytest .raises (Exception ) as exc_info :
6265 get_py_source ("/path/to/non_readable_file.py" )
63- assert str ( exc_info . value ) == exception_message , (
64- f"Expected { exception_message } , but got { exc_info .value } "
65- )
66+ assert (
67+ str ( exc_info .value ) == exception_message
68+ ), f"Expected { exception_message } , but got { exc_info . value } "
6669
6770
6871@pytest .fixture ()
@@ -142,7 +145,7 @@ def test_determine_service_name_via_cli_args(
142145) -> None :
143146 mocker .patch ("instana.util.runtime.get_proc_cmdline" , return_value = "python" )
144147 sys .argv = argv
145- # We check "python" in the return of determine_service_name() because this
148+ # We check "python" in the return of determine_service_name() because this
146149 # can be the value "python3"
147150 assert "python" in determine_service_name ()
148151
@@ -173,14 +176,18 @@ def test_determine_service_name_via_tty(
173176 (True , "python script.py arg1 arg2" ),
174177 ],
175178)
176- def test_get_proc_cmdline (as_string : bool , expected : Union [List [str ], str ], mocker : "MockerFixture" ) -> None :
179+ def test_get_proc_cmdline (
180+ as_string : bool , expected : Union [List [str ], str ], mocker : "MockerFixture"
181+ ) -> None :
177182 # Mock the proc filesystem presence
178183 mocker .patch ("os.path.isfile" , return_value = "/proc/self/cmdline" )
179184 # Mock the content of /proc/self/cmdline
180185 mocked_data = mocker .mock_open (read_data = "python\0 script.py\0 arg1\0 arg2\0 " )
181186 mocker .patch ("builtins.open" , mocked_data )
182187
183- assert get_proc_cmdline (as_string ) == expected , f"Expected { expected } , but got { get_proc_cmdline (as_string )} "
188+ assert (
189+ get_proc_cmdline (as_string ) == expected
190+ ), f"Expected { expected } , but got { get_proc_cmdline (as_string )} "
184191
185192
186193@pytest .mark .parametrize (
@@ -198,29 +205,88 @@ def test_get_proc_cmdline_no_proc_fs(
198205 assert get_proc_cmdline (as_string ) == expected
199206
200207
201-
202208def test_get_runtime_env_info (mocker : "MockerFixture" ) -> None :
203209 """Test the get_runtime_env_info function."""
204- expected_output = ("x86_64" , "3.13.5" )
210+ expected_output = ("x86_64" , "Linux" , " 3.13.5" )
205211
206212 mocker .patch ("platform.machine" , return_value = expected_output [0 ])
207- mocker .patch ("platform.python_version" , return_value = expected_output [1 ])
213+ mocker .patch ("platform.system" , return_value = expected_output [1 ])
214+ mocker .patch ("platform.python_version" , return_value = expected_output [2 ])
208215
209- machine , py_version = get_runtime_env_info ()
216+ machine , system , py_version = get_runtime_env_info ()
210217 assert machine == expected_output [0 ]
211- assert py_version == expected_output [1 ]
218+ assert system == expected_output [1 ]
219+ assert py_version == expected_output [2 ]
212220
213221
214- def test_log_runtime_env_info (mocker : "MockerFixture" , caplog : "LogCaptureFixture" ) -> None :
222+ def test_log_runtime_env_info (
223+ mocker : "MockerFixture" , caplog : "LogCaptureFixture"
224+ ) -> None :
215225 """Test the log_runtime_env_info function."""
216- expected_output = ("x86_64" , "3.13.5" )
226+ expected_output = ("x86_64" , "Linux" , " 3.13.5" )
217227 caplog .set_level (logging .DEBUG , logger = "instana" )
218228
219229 mocker .patch ("platform.machine" , return_value = expected_output [0 ])
220- mocker .patch ("platform.python_version" , return_value = expected_output [1 ])
230+ mocker .patch ("platform.system" , return_value = expected_output [1 ])
231+ mocker .patch ("platform.python_version" , return_value = expected_output [2 ])
221232
222233 log_runtime_env_info ()
223- assert (
224- f"Runtime environment: Machine: { expected_output [0 ]} , Python version: { expected_output [1 ]} "
225- in caplog .messages
234+
235+ expected_log_message = f"Runtime environment: Machine: { expected_output [0 ]} , System: { expected_output [1 ]} , Python version: { expected_output [2 ]} "
236+ assert expected_log_message in caplog .messages
237+
238+
239+ @pytest .mark .parametrize (
240+ "system, expected" ,
241+ [
242+ ("Windows" , True ),
243+ ("windows" , True ), # Test case insensitivity
244+ ("WINDOWS" , True ), # Test case insensitivity
245+ ("Linux" , False ),
246+ ("Darwin" , False ),
247+ ],
248+ )
249+ def test_is_windows (system : str , expected : bool , mocker : "MockerFixture" ) -> None :
250+ """Test the is_windows function."""
251+ mocker .patch (
252+ "instana.util.runtime.get_runtime_env_info" ,
253+ return_value = ("x86_64" , system , "3.13.5" ),
254+ )
255+ assert is_windows () == expected
256+
257+
258+ @pytest .mark .parametrize (
259+ "machine, expected" ,
260+ [
261+ ("ppc64le" , True ),
262+ ("ppc64" , True ),
263+ ("PPC64" , True ), # Test case insensitivity
264+ ("x86_64" , False ),
265+ ("arm64" , False ),
266+ ],
267+ )
268+ def test_is_ppc64 (machine : str , expected : bool , mocker : "MockerFixture" ) -> None :
269+ """Test the is_ppc64 function."""
270+ mocker .patch (
271+ "instana.util.runtime.get_runtime_env_info" ,
272+ return_value = (machine , "Linux" , "3.13.5" ),
273+ )
274+ assert is_ppc64 () == expected
275+
276+
277+ @pytest .mark .parametrize (
278+ "machine, expected" ,
279+ [
280+ ("s390x" , True ),
281+ ("S390X" , True ), # Test case insensitivity
282+ ("x86_64" , False ),
283+ ("arm64" , False ),
284+ ],
285+ )
286+ def test_is_s390x (machine : str , expected : bool , mocker : "MockerFixture" ) -> None :
287+ """Test the is_s390x function."""
288+ mocker .patch (
289+ "instana.util.runtime.get_runtime_env_info" ,
290+ return_value = (machine , "Linux" , "3.13.5" ),
226291 )
292+ assert is_s390x () == expected
0 commit comments