Skip to content

Commit fa5ec39

Browse files
Add test coverage
1 parent f8c56d3 commit fa5ec39

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

opentelemetry-sdk/tests/logs/test_log_record.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@
4040

4141

4242
class TestLogRecord(unittest.TestCase):
43+
def test_serialized_context_none(self):
44+
record = LogRecord(context=None)
45+
self.assertEqual(None, record.serialized_context())
46+
47+
def test_serialized_context_serializable(self):
48+
context = {
49+
"test-string": "value",
50+
"test-number": 42,
51+
"test-list": [1, 2, 3],
52+
"test-dict": {"key": "value"},
53+
"test-null": None,
54+
"test-bool": True,
55+
}
56+
record = LogRecord(context=context)
57+
self.assertEqual(context, record.serialized_context())
58+
59+
def test_serialized_context_non_serializable(self):
60+
class MyTestObject:
61+
def __str__(self):
62+
return "foo-bar"
63+
64+
context = {"test-string": "value", "test-object": MyTestObject()}
65+
record = LogRecord(context=context)
66+
expected = {"test-string": "value", "test-object": "foo-bar"}
67+
self.assertEqual(expected, record.serialized_context())
68+
4369
def test_log_record_to_json(self):
4470
expected = json.dumps(
4571
{

0 commit comments

Comments
 (0)