Skip to content

Commit 8a2e6cf

Browse files
committed
Examples update
1 parent a587381 commit 8a2e6cf

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*** Settings ***
2+
Documentation Example of logging on binary file read
3+
Library library/Log.py
4+
Library OperatingSystem
5+
6+
*** Variables ***
7+
${PUG_IMAGE} res/pug/lucky.jpg
8+
9+
*** Keywords ***
10+
Read Binary File
11+
[Tags] binary
12+
[Arguments] ${file}
13+
${data} Get Binary File ${file}
14+
Binary Log INFO image pug.jpg ${data}
15+
16+
*** Test Cases ***
17+
Read Pug Image
18+
Read Binary File ${PUG_IMAGE}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ${PUG_IMAGE} res/pug/lucky.jpg
77

88
*** Keywords ***
99
Read Binary File
10+
[Tags] binary
1011
[Arguments] ${file}
1112
${data} Get Binary File ${file}
1213
Log ${data}

examples/library/Log.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Logging library for Robot Framework."""
2-
31
# Copyright 2024 EPAM Systems
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,6 +12,10 @@
1412
# See the License for the specific language governing permissions and
1513
# limitations under the License.
1614

15+
"""Logging library for Robot Framework."""
16+
17+
from reportportal_client.helpers import guess_content_type_from_bytes
18+
1719
from robotframework_reportportal import logger
1820

1921

@@ -38,3 +40,24 @@ def launch_log(level, message, attachment=None):
3840
:param attachment: path to attachment file
3941
"""
4042
logger.write(message, level, attachment=attachment, launch_log=True)
43+
44+
45+
def binary_log(level: str, message: str, file_name: str, attachment: bytes):
46+
"""
47+
Post a log entry with binary attachment.
48+
49+
:param level: log entry level
50+
:param message: message to post
51+
:param file_name: name of the attachment file
52+
:param attachment: binary data to attach
53+
"""
54+
logger.write(
55+
message,
56+
level,
57+
attachment={
58+
"name": file_name,
59+
"data": attachment,
60+
"mime": guess_content_type_from_bytes(attachment),
61+
},
62+
launch_log=False,
63+
)

tests/integration/test_logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_launch_log(mock_client_init):
3333

3434
@mock.patch(REPORT_PORTAL_SERVICE)
3535
def test_binary_file_log(mock_client_init):
36-
result = utils.run_robot_tests(["examples/binary_file_read.robot"])
36+
result = utils.run_robot_tests(["examples/binary_file_log_as_text.robot"])
3737
assert result == 0 # the test successfully passed
3838

3939
mock_client = mock_client_init.return_value

0 commit comments

Comments
 (0)