-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
75 lines (54 loc) · 1.57 KB
/
test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from osu import Game
import logging
logging.basicConfig(
level=logging.DEBUG, format="[%(asctime)s] - <%(name)s> %(levelname)s: %(message)s"
)
logger = logging.getLogger("tests")
logger.info("Performing tests...")
game = Game(
username="testuser",
password="testpass",
version=1337,
server="ppy.sh",
stream="stable40",
)
async_task_success = False
task_success = False
def tasks():
logger.info("Testing tasks...")
@game.tasks.register(seconds=0)
def test_task():
global task_success
task_success = True
@game.tasks.register(seconds=0, threaded=True)
def test_task_async():
global async_task_success
async_task_success = True
# Bancho needs to be connected for tasks to run
game.bancho.connected = True
# Execute test_task
game.tasks.execute()
if not task_success:
logger.error("Syncronous task failed.")
exit(1)
# Execute test_task_async
game.tasks.execute()
# Wait for thread
for thread in game.tasks.executor._threads:
thread.join(timeout=1)
if not async_task_success:
logger.error("Asyncronous task failed.")
exit(1)
logger.info("Tasks were executed successfully.")
game.bancho.connected = False
def packets():
logger.info("Simulating login reply packet...")
game.packets.data_received(
data=b"\x05\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00", game=game
)
if game.bancho.player.id != 1:
logger.error("Login reply packet failed.")
exit(1)
# TODO: More packets?
tasks()
packets()