Skip to content

Commit

Permalink
python 3.7 runtime check
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Orlovsky committed Sep 2, 2024
1 parent a8d59d0 commit 04c8995
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/lumigo_opentelemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ def auto_load(_: Any) -> None:
def init() -> Dict[str, Any]:
"""Initialize the Lumigo OpenTelemetry distribution."""
python_version = sys.version_info
if not (python_version >= (3, 8) and python_version <= (3, 11)):
print("python_version", python_version)

# Check if the major version is 3 and the minor version is between 8 and 12
if python_version.major != 3 or not (8 <= python_version.minor <= 12):
logger.warning(
f"Unsupported Python version {python_version[0]}.{python_version[1]}; "
"only Python 3.8 to 3.11 are supported."
f"Unsupported Python version {python_version.major}.{python_version.minor}; "
"only Python 3.8 to 3.12 are supported."
)
return {}

Expand Down
28 changes: 22 additions & 6 deletions src/test/unit/test_tracer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import sys
import unittest
import httpretty

from unittest import TestCase
from unittest.mock import patch
from unittest.mock import patch, Mock
from httpretty import HTTPretty

from json import loads
Expand Down Expand Up @@ -106,28 +107,43 @@ def _test_dependency_report_called(self):


class TestPythonVersionCheck(TestCase):
@patch("sys.version_info", (3, 7)) # Set Python version to 3.7
@patch("sys.version_info", Mock())
def test_python_version_too_old(self):
# Mock version_info for Python 3.7
sys.version_info.major = 3
sys.version_info.minor = 7

with self.assertLogs("lumigo-opentelemetry", level="WARNING") as cm:
result = init()

self.assertEqual(result, {})
self.assertIn(
"Unsupported Python version 3.7; only Python 3.8 to 3.11 are supported.",
"Unsupported Python version 3.7; only Python 3.8 to 3.12 are supported.",
cm.output[0],
)

@patch("sys.version_info", (3, 8)) # Set Python version to 3.8
@patch("sys.version_info", Mock())
def test_python_version_supported(self):
# Mock version_info for Python 3.8
sys.version_info.major = 3
sys.version_info.minor = 8

with self.assertLogs("lumigo-opentelemetry", level="WARNING"):
result = init()

self.assertIsInstance(result, dict)

@patch("sys.version_info", (3, 12)) # Set Python version to 3.12
@patch("sys.version_info", Mock())
def test_python_version_too_new(self):
# Mock version_info for Python 3.13
sys.version_info.major = 3
sys.version_info.minor = 13

with self.assertLogs("lumigo-opentelemetry", level="WARNING") as cm:
result = init()

self.assertEqual(result, {})
self.assertIn(
"Unsupported Python version 3.12; only Python 3.8 to 3.11 are supported.",
"Unsupported Python version 3.13; only Python 3.8 to 3.12 are supported.",
cm.output[0],
)

0 comments on commit 04c8995

Please sign in to comment.