Skip to content

Commit 9abafd2

Browse files
authored
Merge pull request #342 from chrysn-pull-requests/python-test-logging
python/tests: Add basic test for logging
2 parents 747368a + c1035ac commit 9abafd2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lakers-python/test/test_lakers.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import io
2+
import logging
13
import lakers
24
import cbor2
35
import pytest
46
from lakers import CredentialTransfer, EdhocInitiator, EdhocResponder
57

8+
# This needs to be early, thus top-level: Once Lakers objects are created, the
9+
# log level is fixed.
10+
LOGSTREAM = io.StringIO()
11+
logging.basicConfig(stream=LOGSTREAM, level=0, force=True)
12+
613
# values from RFC9529, but CRED_I shortened so that passing by value is possible in a 256 byte message
714
CRED_I = bytes.fromhex("A202617808A101A5010202412B2001215820AC75E9ECE3E50BFC8ED60399889522405C47BF16DF96660A41298CB4307F7EB62258206E5DE611388A4B8A8211334AC7D37ECB52A387D257E6DB3C2A93DF21FF3AFFC8")
815
I = bytes.fromhex("fb13adeb6518cee5f88417660841142e830a81fe334380a953406a1305e8706b")
@@ -98,6 +105,15 @@ def test_buffer_error():
98105
_ = initiator.parse_message_2(cbor2.dumps(bytes([1] * 10000)))
99106
assert str(err.value) == "MessageBufferError::SliceTooLong"
100107

108+
def test_logging():
109+
LOGSTREAM.truncate(0)
110+
LOGSTREAM.seek(0)
111+
112+
test_handshake_credential_transfer_by(CredentialTransfer.ByValue, CredentialTransfer.ByValue)
113+
114+
# So far we don't test much, but that is currently in it an shows that log messages get through.
115+
assert 'Initializing EdhocInitiator' in LOGSTREAM.getvalue()
116+
101117
@pytest.mark.parametrize("cred_r_transfer", [CredentialTransfer.ByReference, CredentialTransfer.ByValue])
102118
@pytest.mark.parametrize("cred_i_transfer", [CredentialTransfer.ByReference, CredentialTransfer.ByValue])
103119
def test_handshake_credential_transfer_by(cred_r_transfer, cred_i_transfer):

0 commit comments

Comments
 (0)