Skip to content

Commit

Permalink
handle 'was removed from table' action close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
kakty3 committed Jul 13, 2016
1 parent 45c2974 commit 7fbe4b4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions poker/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Action(PokerEnum):
THINK = 'seconds left to act',
CONNECTED = 'connected',
DISCONNECTED = 'disconnected',
REMOVED = 'removed', 'was removed'


class Position(PokerEnum):
Expand Down
18 changes: 16 additions & 2 deletions poker/room/pokerstars.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def parse(self, action_str):
action = self._parse_connected(action_str)
elif 'is disconnected' in action_str:
action = self._parse_disconnected(action_str)
elif 'was removed' in action_str:
action = self._parse_removed(action_str)
else:
raise RuntimeError("Unknown action: " + action_str)

Expand All @@ -151,6 +153,11 @@ def _parse_uncalled(self, line):
amount = match.group('amount')
return name, Action.RETURN, Decimal(amount)

def _parse_removed(self, line):
i = line.index('was removed')
name = line[:i].strip()
return name, Action.REMOVED, None

def _parse_collected(self, line):
match = self._collected_re.match(line)
name = match.group('name')
Expand Down Expand Up @@ -373,8 +380,15 @@ def _parse_street(self, street):
start = self._splitted.index(street.upper()) + 2
stop = self._splitted.index('', start)
ap = ActionParser()
street_actions = [ap.parse(action_str) for action_str in self._splitted[start:stop]]
setattr(self, street_attr, tuple(street_actions) if street_actions else None)

action_lines = self._splitted[start:stop]
if action_lines:
street_actions = tuple(ap.parse(action_str)
for action_str
in action_lines)
else:
street_actions = None
setattr(self, street_attr, street_actions)
except ValueError:
setattr(self, street, None)
setattr(self, street_attr, None)
Expand Down
1 change: 1 addition & 0 deletions tests/handhistory/stars_hands.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
pjo80: folds
Brimill: folds
XZ18: folds
GenGen was removed from the table for failing to post
*** FLOP *** [Kd Qc Ad]
.prestige.U$: checks
daoudi007708: bets 20
Expand Down
15 changes: 10 additions & 5 deletions tests/handhistory/test_stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,16 @@ def test_flop_pot(self, hand):

class TestHeroMissing:
hand_text = stars_hands.HAND6
@pytest.mark.parametrize(('attribute', 'expected_value'), [
('hero', None),
])
def test_body(self, hand, attribute, expected_value):
assert getattr(hand, attribute) == expected_value

def test_body(self, hand):
assert getattr(hand, 'hero') is None


class TestEvents:
hand_text = stars_hands.HAND6

def test_player_removed(self, hand):
assert hand.preflop_actions[-1] == _PlayerAction('GenGen', Action.REMOVED, None)


class TestBodyMissingPlayerNoBoard:
Expand Down

0 comments on commit 7fbe4b4

Please sign in to comment.