Skip to content

Commit d4735cb

Browse files
Merge pull request #1308 from sudarshan-parvatikar/test-cleanup-issue-1287
Test cleanup issue 1287
2 parents 053c4be + c4a19c2 commit d4735cb

File tree

86 files changed

+2471
-2445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2471
-2445
lines changed

axelrod/tests/integration/test_filtering.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import unittest
22

3-
from axelrod import filtered_strategies, seed, short_run_time_strategies
3+
import axelrod as axl
44
from axelrod.tests.property import strategy_lists
5+
56
from hypothesis import example, given, settings
67
from hypothesis.strategies import integers
78

@@ -26,7 +27,7 @@ def test_boolean_filtering(self, strategies):
2627
for classifier in classifiers:
2728
comprehension = set([s for s in strategies if s.classifier[classifier]])
2829
filterset = {classifier: True}
29-
filtered = set(filtered_strategies(filterset, strategies=strategies))
30+
filtered = set(axl.filtered_strategies(filterset, strategies=strategies))
3031
self.assertEqual(comprehension, filtered)
3132

3233
@given(
@@ -39,7 +40,7 @@ def test_boolean_filtering(self, strategies):
3940
min_memory_depth=float("inf"),
4041
max_memory_depth=float("inf"),
4142
memory_depth=float("inf"),
42-
strategies=short_run_time_strategies,
43+
strategies=axl.short_run_time_strategies,
4344
)
4445
@settings(max_examples=5)
4546
def test_memory_depth_filtering(
@@ -55,7 +56,7 @@ def test_memory_depth_filtering(
5556
]
5657
)
5758
min_filterset = {"min_memory_depth": min_memory_depth}
58-
min_filtered = set(filtered_strategies(min_filterset,
59+
min_filtered = set(axl.filtered_strategies(min_filterset,
5960
strategies=strategies))
6061
self.assertEqual(min_comprehension, min_filtered)
6162

@@ -67,7 +68,7 @@ def test_memory_depth_filtering(
6768
]
6869
)
6970
max_filterset = {"max_memory_depth": max_memory_depth}
70-
max_filtered = set(filtered_strategies(max_filterset,
71+
max_filtered = set(axl.filtered_strategies(max_filterset,
7172
strategies=strategies))
7273
self.assertEqual(max_comprehension, max_filtered)
7374

@@ -79,7 +80,7 @@ def test_memory_depth_filtering(
7980
]
8081
)
8182
filterset = {"memory_depth": memory_depth}
82-
filtered = set(filtered_strategies(filterset, strategies=strategies))
83+
filtered = set(axl.filtered_strategies(filterset, strategies=strategies))
8384
self.assertEqual(comprehension, filtered)
8485

8586
@given(seed_=integers(min_value=0, max_value=4294967295),
@@ -95,7 +96,7 @@ def test_makes_use_of_filtering(self, seed_, strategies):
9596
classifiers = [["game"], ["length"], ["game", "length"]]
9697

9798
for classifier in classifiers:
98-
seed(seed_)
99+
axl.seed(seed_)
99100
comprehension = set(
100101
[
101102
s
@@ -104,9 +105,9 @@ def test_makes_use_of_filtering(self, seed_, strategies):
104105
]
105106
)
106107

107-
seed(seed_)
108+
axl.seed(seed_)
108109
filterset = {"makes_use_of": classifier}
109-
filtered = set(filtered_strategies(filterset, strategies=strategies))
110+
filtered = set(axl.filtered_strategies(filterset, strategies=strategies))
110111

111112
self.assertEqual(
112113
comprehension, filtered, msg="classifier: {}".format(classifier)

axelrod/tests/integration/test_matches.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
"""Tests for some expected match behaviours"""
22
import unittest
33

4-
import axelrod
4+
import axelrod as axl
55
from axelrod.tests.property import strategy_lists
66

77
from hypothesis import given, settings
88
from hypothesis.strategies import integers
99

10-
C, D = axelrod.Action.C, axelrod.Action.D
10+
C, D = axl.Action.C, axl.Action.D
1111

1212
deterministic_strategies = [
13-
s for s in axelrod.short_run_time_strategies if not s().classifier["stochastic"]
13+
s for s in axl.short_run_time_strategies if not s().classifier["stochastic"]
1414
]
1515
stochastic_strategies = [
16-
s for s in axelrod.short_run_time_strategies if s().classifier["stochastic"]
16+
s for s in axl.short_run_time_strategies if s().classifier["stochastic"]
1717
]
1818

1919

@@ -29,7 +29,7 @@ def test_outcome_repeats(self, strategies, turns):
2929
"""A test that if we repeat 3 matches with deterministic and well
3030
behaved strategies then we get the same result"""
3131
players = [s() for s in strategies]
32-
matches = [axelrod.Match(players, turns) for _ in range(3)]
32+
matches = [axl.Match(players, turns) for _ in range(3)]
3333
self.assertEqual(matches[0].play(), matches[1].play())
3434
self.assertEqual(matches[1].play(), matches[2].play())
3535

@@ -46,9 +46,9 @@ def test_outcome_repeats_stochastic(self, strategies, turns, seed):
4646
same result"""
4747
results = []
4848
for _ in range(3):
49-
axelrod.seed(seed)
49+
axl.seed(seed)
5050
players = [s() for s in strategies]
51-
results.append(axelrod.Match(players, turns).play())
51+
results.append(axl.Match(players, turns).play())
5252

5353
self.assertEqual(results[0], results[1])
5454
self.assertEqual(results[1], results[2])
@@ -57,15 +57,15 @@ def test_matches_with_det_player_for_stochastic_classes(self):
5757
"""A test based on a bug found in the cache.
5858
5959
See: https://github.com/Axelrod-Python/Axelrod/issues/779"""
60-
p1 = axelrod.MemoryOnePlayer(four_vector=(0, 0, 0, 0))
61-
p2 = axelrod.MemoryOnePlayer(four_vector=(1, 0, 1, 0))
62-
p3 = axelrod.MemoryOnePlayer(four_vector=(1, 1, 1, 0))
60+
p1 = axl.MemoryOnePlayer(four_vector=(0, 0, 0, 0))
61+
p2 = axl.MemoryOnePlayer(four_vector=(1, 0, 1, 0))
62+
p3 = axl.MemoryOnePlayer(four_vector=(1, 1, 1, 0))
6363

64-
m = axelrod.Match((p1, p2), turns=3)
64+
m = axl.Match((p1, p2), turns=3)
6565
self.assertEqual(m.play(), [(C, C), (D, C), (D, D)])
6666

67-
m = axelrod.Match((p2, p3), turns=3)
67+
m = axl.Match((p2, p3), turns=3)
6868
self.assertEqual(m.play(), [(C, C), (C, C), (C, C)])
6969

70-
m = axelrod.Match((p1, p3), turns=3)
70+
m = axl.Match((p1, p3), turns=3)
7171
self.assertEqual(m.play(), [(C, C), (D, C), (D, C)])
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import unittest
22

3-
from axelrod import all_strategies
3+
import axelrod as axl
44

55

66
class TestNames(unittest.TestCase):
77
def test_all_strategies_have_names(self):
8-
names = [s.name for s in all_strategies if s.name]
9-
self.assertEqual(len(names), len(all_strategies))
8+
names = [s.name for s in axl.all_strategies if s.name]
9+
self.assertEqual(len(names), len(axl.all_strategies))
1010

1111
def test_all_names_are_unique(self):
12-
names = set(s.name for s in all_strategies)
13-
self.assertEqual(len(names), len(all_strategies))
12+
names = set(s.name for s in axl.all_strategies)
13+
self.assertEqual(len(names), len(axl.all_strategies))

axelrod/tests/integration/test_sample_tournaments.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import unittest
22

3-
import axelrod
3+
import axelrod as axl
44

5-
C, D = axelrod.Action.C, axelrod.Action.D
5+
C, D = axl.Action.C, axl.Action.D
66

77

88
class TestSampleTournaments(unittest.TestCase):
99
@classmethod
1010
def setUpClass(cls):
11-
cls.game = axelrod.Game()
11+
cls.game = axl.Game()
1212

1313
@classmethod
1414
def get_test_outcome(cls, outcome, turns=10):
1515

1616
# Extract the name of players from the outcome tuples,
1717
# and initiate the players by getting the classes from axelrod.
1818
names = [out[0] for out in outcome]
19-
players = [getattr(axelrod, n)() for n in names]
19+
players = [getattr(axl, n)() for n in names]
2020

2121
# Play the tournament and build the actual outcome tuples.
22-
tournament = axelrod.Tournament(
22+
tournament = axl.Tournament(
2323
players=players, game=cls.game, turns=turns, repetitions=1
2424
)
2525
results = tournament.play(progress_bar=False)

axelrod/tests/integration/test_tournament.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import filecmp
21
import unittest
32

4-
from hypothesis import given, settings
3+
import filecmp
54

6-
import axelrod
5+
import axelrod as axl
76
from axelrod.strategy_transformers import FinalTransformer
87
from axelrod.tests.property import tournaments
98

9+
from hypothesis import given, settings
1010

1111
class TestTournament(unittest.TestCase):
1212
@classmethod
1313
def setUpClass(cls):
14-
cls.game = axelrod.Game()
14+
cls.game = axl.Game()
1515
cls.players = [
16-
axelrod.Cooperator(),
17-
axelrod.TitForTat(),
18-
axelrod.Defector(),
19-
axelrod.Grudger(),
20-
axelrod.GoByMajority(),
16+
axl.Cooperator(),
17+
axl.TitForTat(),
18+
axl.Defector(),
19+
axl.Grudger(),
20+
axl.GoByMajority(),
2121
]
2222
cls.player_names = [str(p) for p in cls.players]
2323
cls.test_name = "test"
@@ -33,7 +33,7 @@ def setUpClass(cls):
3333
cls.expected_outcome.sort()
3434

3535
@given(tournaments(
36-
strategies=axelrod.short_run_time_strategies,
36+
strategies=axl.short_run_time_strategies,
3737
min_size=10,
3838
max_size=30,
3939
min_turns=2,
@@ -51,7 +51,7 @@ def test_big_tournaments(self, tournament):
5151
)
5252

5353
def test_serial_play(self):
54-
tournament = axelrod.Tournament(
54+
tournament = axl.Tournament(
5555
name=self.test_name,
5656
players=self.players,
5757
game=self.game,
@@ -63,7 +63,7 @@ def test_serial_play(self):
6363
self.assertEqual(actual_outcome, self.expected_outcome)
6464

6565
def test_parallel_play(self):
66-
tournament = axelrod.Tournament(
66+
tournament = axl.Tournament(
6767
name=self.test_name,
6868
players=self.players,
6969
game=self.game,
@@ -78,12 +78,12 @@ def test_repeat_tournament_deterministic(self):
7878
"""A test to check that tournament gives same results."""
7979
deterministic_players = [
8080
s()
81-
for s in axelrod.short_run_time_strategies
81+
for s in axl.short_run_time_strategies
8282
if not s().classifier["stochastic"]
8383
]
8484
files = []
8585
for _ in range(2):
86-
tournament = axelrod.Tournament(
86+
tournament = axl.Tournament(
8787
name="test",
8888
players=deterministic_players,
8989
game=self.game,
@@ -100,13 +100,13 @@ def test_repeat_tournament_stochastic(self):
100100
"""
101101
files = []
102102
for _ in range(2):
103-
axelrod.seed(0)
103+
axl.seed(0)
104104
stochastic_players = [
105105
s()
106-
for s in axelrod.short_run_time_strategies
106+
for s in axl.short_run_time_strategies
107107
if s().classifier["stochastic"]
108108
]
109-
tournament = axelrod.Tournament(
109+
tournament = axl.Tournament(
110110
name="test",
111111
players=stochastic_players,
112112
game=self.game,
@@ -121,14 +121,14 @@ def test_repeat_tournament_stochastic(self):
121121
class TestNoisyTournament(unittest.TestCase):
122122
def test_noisy_tournament(self):
123123
# Defector should win for low noise
124-
players = [axelrod.Cooperator(), axelrod.Defector()]
125-
tournament = axelrod.Tournament(players, turns=5, repetitions=3, noise=0.0)
124+
players = [axl.Cooperator(), axl.Defector()]
125+
tournament = axl.Tournament(players, turns=5, repetitions=3, noise=0.0)
126126
results = tournament.play(progress_bar=False)
127127
self.assertEqual(results.ranked_names[0], "Defector")
128128

129129
# If the noise is large enough, cooperator should win
130-
players = [axelrod.Cooperator(), axelrod.Defector()]
131-
tournament = axelrod.Tournament(players, turns=5, repetitions=3, noise=0.75)
130+
players = [axl.Cooperator(), axl.Defector()]
131+
tournament = axl.Tournament(players, turns=5, repetitions=3, noise=0.75)
132132
results = tournament.play(progress_bar=False)
133133
self.assertEqual(results.ranked_names[0], "Cooperator")
134134

@@ -138,10 +138,10 @@ def test_players_do_not_know_match_length(self):
138138
"""Create two players who should cooperate on last two turns if they
139139
don't know when those last two turns are.
140140
"""
141-
p1 = FinalTransformer(["D", "D"])(axelrod.Cooperator)()
142-
p2 = FinalTransformer(["D", "D"])(axelrod.Cooperator)()
141+
p1 = FinalTransformer(["D", "D"])(axl.Cooperator)()
142+
p2 = FinalTransformer(["D", "D"])(axl.Cooperator)()
143143
players = [p1, p2]
144-
tournament = axelrod.Tournament(players, prob_end=0.5, repetitions=1)
144+
tournament = axl.Tournament(players, prob_end=0.5, repetitions=1)
145145
results = tournament.play(progress_bar=False)
146146
# Check that both plays always cooperated
147147
for rating in results.cooperating_rating:
@@ -152,12 +152,12 @@ def test_matches_have_different_length(self):
152152
A match between two players should have variable length across the
153153
repetitions
154154
"""
155-
p1 = axelrod.Cooperator()
156-
p2 = axelrod.Cooperator()
157-
p3 = axelrod.Cooperator()
155+
p1 = axl.Cooperator()
156+
p2 = axl.Cooperator()
157+
p3 = axl.Cooperator()
158158
players = [p1, p2, p3]
159-
axelrod.seed(0)
160-
tournament = axelrod.Tournament(players, prob_end=0.5, repetitions=2)
159+
axl.seed(0)
160+
tournament = axl.Tournament(players, prob_end=0.5, repetitions=2)
161161
results = tournament.play(progress_bar=False)
162162
# Check that match length are different across the repetitions
163163
self.assertNotEqual(results.match_lengths[0], results.match_lengths[1])

0 commit comments

Comments
 (0)