-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sessions.py
61 lines (40 loc) · 1.31 KB
/
test_sessions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pytest,asyncio,sys
from htagweb.session import Session,FileDict,FilePersistentDict,ShmDict
def session_test(factory):
session = factory("uid")
try:
# good way to clone
dict(session.items())
assert "nb" not in session
session["nb"]=session.get("nb",0) + 1
assert "nb" in session
assert session
assert len(session)==1
# ensure persistance is present
session = factory("uid")
assert session["nb"]==1
session["x"]=42
assert len(session)==2
del session["x"]
assert len(session)==1
session.clear()
assert len(session)==0
session = factory("uid")
assert len(session.items())==0
session["k"]=42
assert session.pop("k",12)==42
assert session.pop("k",12)==12
finally:
session.clear()
def test_sessions_file():
session_test( Session )
def test_sessions_file():
session_test( FileDict )
def test_sessions_filepersitent():
session_test( FilePersistentDict )
def test_sessions_ShmDict():
session_test( ShmDict )
if __name__=="__main__":
import logging,multiprocessing,threading
logging.basicConfig(format='[%(levelname)-5s] %(name)s: %(message)s',level=logging.DEBUG)
# asyncio.run( test_sessions_basics() )