Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #236

Merged
merged 10 commits into from
Sep 4, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}

- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
uses: oleksiyrudenko/gha-git-credentials@v2-latest
with:
name: 'reportportal.io'
email: '[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased]
### Added
- `helpers.to_bool` function, by @HardNorth
- Official `Python 3.12` support, by @HardNorth
### Fixed
- SSL context when certificate is provided, by @JLBIZ
- Log Record pathnames are incorrect on python3.11, by @dagansandler

## [5.5.6]
### Added
- `CONTENT_TYPE_TO_EXTENSIONS` constant in `helpers` module, by @HardNorth
### Fixed
- Issue [#228](https://github.com/reportportal/client-Python/issues/228): AttributeError on very large request, by @HardNorth
Expand Down
4 changes: 2 additions & 2 deletions reportportal_client/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ async def session(self) -> RetryingClientSession:
ssl_config = False
else:
if type(self.verify_ssl) is str:
ssl_config = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH, cafile=self.verify_ssl)
ssl_config = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=self.verify_ssl)
else:
ssl_config = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH, cafile=certifi.where())
ssl_config = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=certifi.where())

connection_params = {
'ssl': ssl_config,
Expand Down
16 changes: 16 additions & 0 deletions reportportal_client/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,19 @@ def guess_content_type_from_bytes(data: Union[bytes, bytearray, List[int]]) -> s
return 'application/pdf'

return 'application/octet-stream'


def to_bool(value: Optional[Any]) -> Optional[bool]:
"""Convert value of any type to boolean or raise ValueError.

:param value: value to convert
:return: boolean value
:raises ValueError: if value is not boolean
"""
if value is None:
return None
if value in {'TRUE', 'True', 'true', '1', 'Y', 'y', 1, True}:
return True
if value in {'FALSE', 'False', 'false', '0', 'N', 'n', 0, False}:
return False
raise ValueError(f'Invalid boolean value {value}.')
2 changes: 2 additions & 0 deletions reportportal_client/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _log(self, level, msg, args, exc_info=None, extra=None,
# exception on some versions of IronPython. We trap it here so that
# IronPython can use logging.
try:
if sys.version_info >= (3, 11):
kwargs.setdefault('stacklevel', 2)
if 'stacklevel' in kwargs:
fn, lno, func, sinfo = \
self.findCaller(stack_info, kwargs['stacklevel'])
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import setup, find_packages

__version__ = '5.5.6'
__version__ = '5.5.7'

TYPE_STUBS = ['*.pyi']

Expand Down Expand Up @@ -45,6 +45,7 @@ def read_file(fname):
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
install_requires=read_file('requirements.txt').splitlines(),
)
2 changes: 2 additions & 0 deletions tests/logs/test_rp_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_record_make(logger_handler):
logger.info('test_log')
record = verify_record(logger_handler)
assert not getattr(record, 'attachment')
assert record.pathname == __file__


@mock.patch('reportportal_client.logs.logging.Logger.handle')
Expand Down Expand Up @@ -86,3 +87,4 @@ def test_stacklevel_record_make(logger_handler):
stack_info=inspect.stack(), stacklevel=2)
record = verify_record(logger_handler)
assert record.stack_info.endswith("logger.error('test_log', exc_info=RuntimeError('test'),")
assert record.pathname == __file__
36 changes: 34 additions & 2 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import pytest

from reportportal_client.helpers import (
gen_attributes,
get_launch_sys_attrs,
gen_attributes, get_launch_sys_attrs, to_bool,
verify_value_length, ATTRIBUTE_LENGTH_LIMIT, TRUNCATE_REPLACEMENT, guess_content_type_from_bytes, is_binary
)

Expand Down Expand Up @@ -134,3 +133,36 @@ def test_binary_content_type_detection(file, expected_type):
with open(file, 'rb') as f:
content = f.read()
assert guess_content_type_from_bytes(content) == expected_type


@pytest.mark.parametrize(
'value, expected_result',
[
('TRUE', True),
('True', True),
('true', True),
('Y', True),
('y', True),
(True, True),
(1, True),
('1', True),
('FALSE', False),
('False', False),
('false', False),
('N', False),
('n', False),
(False, False),
(0, False),
('0', False),
(None, None),
]
)
def test_to_bool(value, expected_result):
"""Test for validate to_bool() function."""
assert to_bool(value) == expected_result


def test_to_bool_invalid_value():
"""Test for validate to_bool() function exception case."""
with pytest.raises(ValueError):
to_bool('invalid_value')
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ envlist =
py39
py310
py311
py312

[testenv]
deps =
Expand All @@ -30,3 +31,4 @@ python =
3.9: py39
3.10: py310
3.11: py311
3.12: py312