Skip to content

Commit bd3eca6

Browse files
committed
Tweak settings and random seed
- Limit size of strategies tested. - Limit max examples to 10 - Remove timeout Also: including random seed as a given parameter (so as to make tests reproducible).
1 parent a07dd1a commit bd3eca6

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

axelrod/tests/unit/test_tournament.py

+31-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""Tests for the main tournament class."""
22

3-
import unittest
43
import axelrod
54
import logging
65
import multiprocessing
6+
import random
7+
import unittest
78

89
from hypothesis import given
9-
from hypothesis.strategies import lists, sampled_from, Settings
10+
from hypothesis.strategies import integers, lists, sampled_from, Settings
1011

1112
try:
1213
# Python 3
@@ -104,23 +105,36 @@ def test_serial_play(self):
104105

105106
@given(s=lists(sampled_from(axelrod.strategies),
106107
min_size=2, # Errors are returned is less than 2 strategies
107-
max_size=10, unique=True), settings=Settings(max_examples=5))
108-
def test_property_serial_play(self, s):
108+
max_size=5, unique=True),
109+
seed=integers(),
110+
settings=Settings(max_examples=10,
111+
timeout=0))
112+
def test_property_serial_play(self, s, seed):
109113
"""Test serial play using hypothesis"""
110114
# Test that we get an instance of ResultSet
111-
players = [strat() for strat in s]
112-
113-
tournament = axelrod.Tournament(
114-
name=self.test_name,
115-
players=players,
116-
game=self.game,
117-
turns=200,
118-
repetitions=self.test_repetitions)
119-
results = tournament.play()
120-
self.assertIsInstance(results, axelrod.ResultSet)
121-
self.assertEqual(len(results.cooperation), len(players))
122-
self.assertEqual(results.nplayers, len(players))
123-
self.assertEqual(results.players, players)
115+
try:
116+
# Make test use a seed
117+
# Because of the given, if the test failed, Hypothesis would tell us
118+
# what seed it failed on...
119+
state = random.getstate()
120+
random.seed(seed)
121+
122+
# The actual test
123+
players = [strat() for strat in s]
124+
125+
tournament = axelrod.Tournament(
126+
name=self.test_name,
127+
players=players,
128+
game=self.game,
129+
turns=200,
130+
repetitions=self.test_repetitions)
131+
results = tournament.play()
132+
self.assertIsInstance(results, axelrod.ResultSet)
133+
self.assertEqual(len(results.cooperation), len(players))
134+
self.assertEqual(results.nplayers, len(players))
135+
self.assertEqual(results.players, players)
136+
finally:
137+
random.setstate(state)
124138

125139
def test_parallel_play(self):
126140
# Test that we get an instance of ResultSet

0 commit comments

Comments
 (0)