Skip to content

Commit

Permalink
test: add python bindings signature tests for wanted states
Browse files Browse the repository at this point in the history
  • Loading branch information
dankotov committed Aug 29, 2024
1 parent 44a938e commit 5f0a5c7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/python/tests/signature_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

demo_path = "../parser/test_demo.dem"

class WantedPropState:
def __init__(self, prop, state):
self.prop = prop
self.state = state


class SignatureTest(TestCase):
def test_parse_header_signature(self):
parser = DemoParser(demo_path)
Expand Down Expand Up @@ -60,6 +66,8 @@ def test_parse_event_signature(self):
)
parser.parse_event("player_death", player=None, other=None)
parser.parse_event("player_death", player=[], other=[])
parser.parse_event("player_death", player_states=[WantedPropState("is_defusing", True)])
parser.parse_event("player_death", other_states=[WantedPropState("is_bomb_planted", False)])

with self.assertRaises(TypeError):
parser.parse_event("player_death", player=5, other=None)
Expand All @@ -73,6 +81,12 @@ def test_parse_event_signature(self):
with self.assertRaises(TypeError):
parser.parse_event(5)

with self.assertRaises(AttributeError):
parser.parse_event("player_death", player_states=[{"prop": "is_defusing", "state": True}])

with self.assertRaises(AttributeError):
parser.parse_event("player_death", other_states=[{"prop": "is_bomb_planted", "state": True}])

def test_parse_events_signature(self):
parser = DemoParser(demo_path)

Expand All @@ -95,6 +109,8 @@ def test_parse_events_signature(self):
)
parser.parse_events(["player_death"], player=None, other=None)
parser.parse_events(["player_death"], player=[], other=[])
parser.parse_events(["player_death"], player_states=[WantedPropState("is_defusing", True)])
parser.parse_events(["player_death"], other_states=[WantedPropState("is_bomb_planted", False)])

with self.assertRaises(TypeError):
parser.parse_events(["player_death"], player=5, other=None)
Expand All @@ -111,6 +127,12 @@ def test_parse_events_signature(self):
with self.assertRaises(TypeError):
parser.parse_events(5)

with self.assertRaises(AttributeError):
parser.parse_events(["player_death"], player_states=[{"prop": "is_defusing", "state": True}])

with self.assertRaises(AttributeError):
parser.parse_events(["player_death"], other_states=[{"prop": "is_bomb_planted", "state": True}])

def test_parse_voice_signature(self):
parser = DemoParser(demo_path)
voice = parser.parse_voice()
Expand All @@ -128,6 +150,7 @@ def test_parse_ticks_signature(self):
parser.parse_ticks(["X", "Y"], players=[1, 2, 3], ticks=[1, 2, 3])
parser.parse_ticks(["X", "Y"], players=None, ticks=None)
parser.parse_ticks(["X", "Y"], players=[], ticks=[])
parser.parse_ticks(["X", "Y"], player_states=[WantedPropState("is_alive", True)], other_states=[WantedPropState("is_bomb_planted", True)])

with self.assertRaises(TypeError):
parser.parse_ticks(["X", "Y"], players=5, ticks=None)
Expand All @@ -141,6 +164,12 @@ def test_parse_ticks_signature(self):
with self.assertRaises(TypeError):
parser.parse_ticks(5)

with self.assertRaises(TypeError):
parser.parse_ticks(["X", "Y"], player_states=[1,2])

with self.assertRaises(AttributeError):
parser.parse_ticks(["X", "Y"], player_states=[{"prop": "is_alive", "state": True}])


if __name__ == "__main__":
unittest.main()

0 comments on commit 5f0a5c7

Please sign in to comment.