# Coverage for tests/e2e/test_room.py : 100%

## 56 statements 56 run 0 missing 0 excluded 0 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1# -*- coding: utf-8 -*-

2 from __future__ import annotations

3

4# -- stdlib --

5# -- third party --

6 import gevent

7

8# -- own --

9 from .mock import Environ, EventTap

10

11

12# -- code --

13 class GameEnded(Exception):

14 pass

15

16

17 def wait():

18 gevent.idle(-100)

19 gevent.sleep(0.01)

20 gevent.idle(-100)

21

22

23 class TestRoom(object):

24 def testRoom(self):

25 env = Environ()

26 t = EventTap()

27

28 s = env.server_core()

29 a = env.client_core()

30 b = env.client_core()

31 t.tap(a, b)

32

33 a.auth.login("Alice")

34 b.auth.login("Bob")

35 wait()

36

37 # Can cancel ready

38 a.room.create('Boom', 'THBattle2v2', {})

39 a.room.get_ready()

40 wait()

41 assert a.events.game_joined in t

42 assert s.lobby.state_of(s.lobby.get(a.auth.uid)) == 'ready'

43 a.room.cancel_ready(); wait()

44 assert s.lobby.state_of(s.lobby.get(a.auth.uid)) == 'room'

45

46 # Changing location won't crash

47 a.room.change_location(-1)

48 a.room.change_location(0)

49 a.room.change_location(1)

50 a.room.change_location(2)

51 a.room.change_location(3)

52 a.room.change_location(4)

53 a.room.change_location(5)

54 wait()

55 assert s.lobby.state_of(s.lobby.get(a.auth.uid)) == 'room'

56

57 # Can set param

58 gid = a.game.gid_of(t[a.events.game_joined])

59 a.room.set_game_param(gid, "whatever", "meh")

60 a.room.set_game_param(gid, "random_force", "foo")

61 wait()

62 assert s.game.params_of(s.room.get(gid))['random_force'] == True # noqa

63 a.room.set_game_param(gid, "random_force", False); wait()

64 assert s.game.params_of(s.room.get(gid))['random_force'] == False # noqa

65

66 # Send room users

67 t.clear()

68 a.room.get_room_users(gid); wait()

69 assert a.events.room_users in t

70 a.room.leave()

71

72 # Can handle crashed game

73 t.clear()

74 s.runner._paranoid = False

75 a.runner._paranoid = False

76 a.room.create('meh', 'THBattleCrash', {}); wait()

77 gid = a.game.gid_of(t[a.events.game_joined])

78 g = s.room.get(gid)

79 a.room.get_ready(); wait()

80 wait()

81 assert s.game.is_crashed(g), g._