Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ jobs:
fail-fast: false
matrix:
python-version:
- "pypy-3.9"
- "pypy-3.10"
- "3.9"
- "pypy-3.11"
- "pypy-3.12"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
- "3.15"
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -92,13 +95,13 @@ jobs:
fail-fast: false
matrix:
python-version:
# disabled due to librt is not available on this pypy version
# - "pypy-3.9"
# - "pypy-3.10"
# - "3.9"
# - "3.10"
# CPython only: mypy depends on librt, which publishes no PyPy wheels
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
- "3.15"
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Version `4.0+`: Python 3.7+, PyPy 3.7+

Version `3.0+`: Python 2.7+, PyPy 3.4+

Dropping support for an end-of-life Python version doesn't change the SDK's public API, so it ships in a minor release rather than a major one. Each release declares its minimum Python (`python_requires`), so pip on an older Python installs the last compatible release instead. For example, Python 3.8 and 3.9 stay on 5.8.x.

### Install the SDK

The SDK is available through [PyPi](https://pypi.python.org/pypi?name=optimizely-sdk&:action=display).
Expand Down
8 changes: 1 addition & 7 deletions optimizely/event/event_id_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@
"""


from sys import version_info
from typing import Any, Optional

if version_info < (3, 10):
from typing_extensions import TypeGuard
else:
from typing import TypeGuard
from typing import Any, Optional, TypeGuard


def is_non_empty_string(value: Any) -> TypeGuard[str]:
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://docs.astral.sh/ruff/configuration/

line-length = 120
target-version = "py39"
target-version = "py310"

exclude = [
".git",
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3.14',
'Programming Language :: Python :: 3.15',
],
packages=find_packages(exclude=['docs', 'tests']),
extras_require={'test': TEST_REQUIREMENTS},
python_requires='>=3.10',
install_requires=REQUIREMENTS,
tests_require=TEST_REQUIREMENTS,
test_suite='tests',
Expand Down
36 changes: 14 additions & 22 deletions tests/test_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,32 +556,24 @@ def test_fetch_datafile__request_exception_raised(self, _):

def test_fetch_datafile__exception_polling_thread_failed(self, _):
""" Test that exception is raised when polling thread stops. """
sdk_key = 'some_key'
mock_logger = mock.Mock()
thread_exceptions = []

test_headers = {'Last-Modified': 'New Time'}
test_datafile = json.dumps(self.config_dict_with_features)
test_response = requests.Response()
test_response.status_code = 200
test_response.headers = test_headers
test_response._content = test_datafile

with mock.patch('requests.Session.get', return_value=test_response):
project_config_manager = config_manager.PollingConfigManager(sdk_key=sdk_key,
logger=mock_logger,
update_interval=12345678912345)
with (
mock.patch('optimizely.config_manager.PollingConfigManager.fetch_datafile',
side_effect=Exception('boom')),
mock.patch('threading.excepthook', side_effect=thread_exceptions.append),
):
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key', logger=mock_logger)
project_config_manager._polling_thread.join(timeout=2)

project_config_manager.stop()
# the exception is raised out of the polling thread, which stops
self.assertFalse(project_config_manager.is_running)
self.assertEqual(1, len(thread_exceptions))
self.assertEqual('boom', str(thread_exceptions[0].exc_value))

# verify the error log message
log_messages = [args[0] for args, _ in mock_logger.error.call_args_list]
for message in log_messages:
print(message)
# Check for key parts of the error message (version-agnostic for Python 3.11+)
if not ("Thread for background datafile polling failed" in message and
"timestamp too large to convert to C" in message and
"PyTime_t" in message):
assert False
# and it is logged before being raised
mock_logger.error.assert_called_once_with('Thread for background datafile polling failed. Error: boom')

def test_is_running(self, _):
""" Test that polling thread is running after instance of PollingConfigManager is created. """
Expand Down
Loading