Skip to content

Commit 38f063e

Browse files
committed
tests/extmod: Add very basic feature test for ussl module.
This test just tests that the basic functions/methods can be called with the appropriate arguments. There is no real test of underlying functionality. Thanks to @hosaka for the initial implementation of this test.
1 parent a0cbc10 commit 38f063e

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/extmod/ussl_basic.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# very basic test of ssl module, just to test the methods exist
2+
3+
try:
4+
import uio as io
5+
import ussl as ssl
6+
except ImportError:
7+
print("SKIP")
8+
import sys
9+
sys.exit()
10+
11+
# create in client mode
12+
try:
13+
ss = ssl.wrap_socket(io.BytesIO())
14+
except OSError as er:
15+
print('wrap_socket:', repr(er))
16+
17+
# create in server mode (can use this object for further tests)
18+
socket = io.BytesIO()
19+
ss = ssl.wrap_socket(socket, server_side=1)
20+
21+
# print
22+
print(repr(ss)[:12])
23+
24+
# setblocking
25+
try:
26+
ss.setblocking(False)
27+
except NotImplementedError:
28+
print('setblocking: NotImplementedError')
29+
ss.setblocking(True)
30+
31+
# write
32+
print(ss.write(b'aaaa'))
33+
34+
# read (underlying socket has no data)
35+
print(ss.read(8))
36+
37+
# read (underlying socket has data, but it's bad data)
38+
socket.write(b'aaaaaaaaaaaaaaaa')
39+
socket.seek(0)
40+
try:
41+
ss.read(8)
42+
except OSError as er:
43+
print('read:', repr(er))
44+
45+
# close
46+
ss.close()
47+
48+
# write on closed socket
49+
try:
50+
ss.write(b'aaaa')
51+
except OSError as er:
52+
print('write:', repr(er))

tests/extmod/ussl_basic.py.exp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ssl_handshake_status: -256
2+
wrap_socket: OSError(5,)
3+
<_SSLSocket
4+
setblocking: NotImplementedError
5+
4
6+
b''
7+
read: OSError(-261,)
8+
write: OSError(-256,)

0 commit comments

Comments
 (0)