Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Menteur
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
Menteur
Commits
f3c9c952
Unverified
Commit
f3c9c952
authored
Apr 14, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(tests): turn_messages
parent
70f333e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
15 deletions
+21
-15
game.py
server/model/game.py
+1
-1
test_lobby.py
server/test/test_lobby.py
+20
-14
No files found.
server/model/game.py
View file @
f3c9c952
...
...
@@ -87,7 +87,7 @@ class Game:
if
loser
is
not
None
:
self
.
players
.
remove
(
loser
)
self
.
players
.
insert
(
0
,
loser
)
self
.
message
(
MessageToPlayer
.
LoseRound
,
loser
)
self
.
message
(
MessageToPlayer
.
LoseRound
,
extra
=
loser
.
name
)
return
loser
last_player
=
current_player
...
...
server/test/test_lobby.py
View file @
f3c9c952
from
typing
import
Optional
,
List
from
typing
import
Optional
,
List
,
Any
,
Tuple
from
unittest
import
TestCase
from
server.game.manager
import
ClientManager
...
...
@@ -23,10 +23,10 @@ class MockPlayer(Player):
if
bets
is
None
:
bets
=
[]
self
.
bets
:
List
[
Optional
[
Hand
]]
=
bets
self
.
messages
:
List
[
MessageToPlayer
]
=
[]
self
.
messages
:
List
[
Tuple
[
MessageToPlayer
,
Any
]
]
=
[]
def
count
(
self
,
msg
:
MessageToPlayer
)
->
int
:
return
len
([
m
for
m
in
self
.
messages
if
m
is
msg
])
return
len
([
m
for
(
m
,
e
)
in
self
.
messages
if
m
is
msg
])
def
announce
(
self
,
current_bet
:
Optional
[
Hand
])
->
Announce
:
if
self
.
bets
:
...
...
@@ -34,11 +34,11 @@ class MockPlayer(Player):
else
:
return
Announce
(
CARRE_ACE
)
def
receive
(
self
,
message
:
MessageToPlayer
):
self
.
messages
.
append
(
message
)
def
receive
(
self
,
message
:
MessageToPlayer
,
extra
:
Optional
[
Any
]
=
None
):
self
.
messages
.
append
(
(
message
,
extra
)
)
def
print_msgs
(
self
)
->
str
:
'|'
.
join
([
str
(
m
)
for
m
in
self
.
messages
])
return
'|'
.
join
([
f
"{m}[{e}]"
if
e
else
str
(
m
)
for
(
m
,
e
)
in
self
.
messages
])
class
MockManager
(
ClientManager
):
...
...
@@ -48,8 +48,8 @@ class MockManager(ClientManager):
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extra
=
None
):
if
isinstance
(
to
,
MockPlayer
):
to
.
receive
(
message
)
print
(
f
"Sent {message}
to {to}.
"
)
to
.
receive
(
message
,
extra
)
print
(
f
"Sent {message}
{'(' + str(extra) + ') ' if extra else ''}to {to}
"
)
class
TestManager
(
TestCase
):
...
...
@@ -67,11 +67,10 @@ class TestManager(TestCase):
def
test_turn_messages
(
self
):
self
.
game
.
new_turn
()
self
.
assertEqual
(
self
.
j1
.
count
(
MessageToPlayer
.
LoseRound
),
6
,
f
"j1 should lose 6 rounds."
)
self
.
assertEqual
(
self
.
j2
.
count
(
MessageToPlayer
.
LoseRound
),
6
,
f
"j2 should lose 6 rounds."
)
self
.
assertGot
(
self
.
j1
,
MessageToPlayer
.
LoseRound
,
extra
=
self
.
j1
.
name
,
msg
=
f
"J1 should hear round lost."
)
self
.
assertGot
(
self
.
j2
,
MessageToPlayer
.
LoseRound
,
extra
=
self
.
j1
.
name
,
msg
=
f
"J2 should hear round lost by j1."
)
for
player
in
[
self
.
j1
,
self
.
j2
]:
self
.
assert
In
(
MessageToPlayer
.
Lose
,
player
.
messages
,
"Loser
not announced"
)
self
.
assert
Got
(
player
,
MessageToPlayer
.
LoseRound
,
msg
=
"End of round
not announced"
)
def
test_game_messages
(
self
):
self
.
game
.
new_game
()
...
...
@@ -89,5 +88,12 @@ class TestManager(TestCase):
for
player
in
[
self
.
j1
,
self
.
j2
]:
self
.
assertEqual
(
player
.
count
(
MessageToPlayer
.
Announce
),
7
,
f
"{player} should see 7 announces: {player.print_msgs()}"
)
self
.
assertIn
(
MessageToPlayer
.
WinnerIs
,
player
.
messages
,
"Winner not announced"
)
self
.
assertIn
(
MessageToPlayer
.
Win
,
player
.
messages
,
"Win not told"
)
self
.
assertGot
(
player
,
MessageToPlayer
.
WinnerIs
,
self
.
j1
,
"Winner J1 not announced"
)
self
.
assertIn
(
MessageToPlayer
.
Win
,
self
.
j1
.
messages
,
"Win not told"
)
self
.
assertIn
(
MessageToPlayer
.
Lose
,
self
.
j2
.
messages
,
"Lose not told"
)
def
assertGot
(
self
,
player
:
MockPlayer
,
type
:
MessageToPlayer
,
extra
=
None
,
msg
:
str
=
"message not received"
):
self
.
assertIn
(
type
,
[
t
for
(
t
,
_
)
in
player
.
messages
],
msg
)
if
extra
:
matching
=
[
m
for
(
m
,
e
)
in
player
.
messages
if
e
==
extra
and
m
==
type
]
self
.
assertTrue
(
matching
,
f
"No message {type} with extra {extra}"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment