|
21 | 21 | class TestPythonVersionCheck(unittest.TestCase): |
22 | 22 |
|
23 | 23 | def test_python_version_mismatch_warning_for_runtime_30(self): |
24 | | - """Test that warning is shown when client Python doesn't match runtime 3.0 (Python 3.11)""" |
25 | | - with mock.patch("sys.version_info", (3, 12, 0)): |
| 24 | + """Test that warning is shown when client Python doesn't match runtime 3.0 (Python 3.12)""" |
| 25 | + runtime_version = "3.0" |
| 26 | + server_py_major, server_py_minor = 3, 12 |
| 27 | + client_py_major, client_py_minor = 3, 11 |
| 28 | + |
| 29 | + with mock.patch( |
| 30 | + "sys.version_info", (client_py_major, client_py_minor, 0) |
| 31 | + ): |
26 | 32 | with mock.patch("warnings.warn") as mock_warn: |
27 | 33 | session_builder = DataprocSparkSession.Builder() |
28 | | - session_builder._check_python_version_compatibility("3.0") |
| 34 | + session_builder._check_python_version_compatibility( |
| 35 | + runtime_version |
| 36 | + ) |
29 | 37 |
|
30 | 38 | expected_warning = ( |
31 | | - "Python version mismatch detected: Client is using Python 3.12, " |
32 | | - "but Dataproc runtime 3.0 uses Python 3.11. " |
| 39 | + f"Python version mismatch detected: Client is using Python {client_py_major}.{client_py_minor}, " |
| 40 | + f"but Dataproc runtime {runtime_version} uses Python {server_py_major}.{server_py_minor}. " |
33 | 41 | "This mismatch may cause issues with Python UDF (User Defined Function) compatibility. " |
34 | | - "Consider using Python 3.11 for optimal UDF execution." |
| 42 | + f"Consider using Python {server_py_major}.{server_py_minor} for optimal UDF execution." |
35 | 43 | ) |
36 | 44 | mock_warn.assert_called_once_with( |
37 | 45 | expected_warning, stacklevel=3 |
38 | 46 | ) |
39 | 47 |
|
40 | 48 | def test_no_warning_when_python_versions_match_runtime_30(self): |
41 | | - """Test that no warning is shown when client Python matches runtime 3.0 (Python 3.11)""" |
42 | | - with mock.patch("sys.version_info", (3, 11, 0)): |
| 49 | + """Test that no warning is shown when client Python matches runtime 3.0 (Python 3.12)""" |
| 50 | + runtime_version = "3.0" |
| 51 | + client_py_major, client_py_minor = 3, 12 |
| 52 | + with mock.patch( |
| 53 | + "sys.version_info", (client_py_major, client_py_minor, 0) |
| 54 | + ): |
43 | 55 | with mock.patch("warnings.warn") as mock_warn: |
44 | 56 | session_builder = DataprocSparkSession.Builder() |
45 | | - session_builder._check_python_version_compatibility("3.0") |
| 57 | + session_builder._check_python_version_compatibility( |
| 58 | + runtime_version |
| 59 | + ) |
46 | 60 |
|
47 | 61 | mock_warn.assert_not_called() |
48 | 62 |
|
|
0 commit comments