Skip to content

Commit 7dd2f26

Browse files
refactored import statements as 'import axelrod as axl' in axelrod/tests/integration/* and axelrod/tests/property.py
1 parent 4e351f1 commit 7dd2f26

File tree

6 files changed

+76
-73
lines changed

6 files changed

+76
-73
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 & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import filecmp
21
import unittest
32

3+
import filecmp
4+
45
from hypothesis import given, settings
56

6-
import axelrod
7+
import axelrod as axl
78
from axelrod.strategy_transformers import FinalTransformer
89
from axelrod.tests.property import tournaments
910

1011

1112
class TestTournament(unittest.TestCase):
1213
@classmethod
1314
def setUpClass(cls):
14-
cls.game = axelrod.Game()
15+
cls.game = axl.Game()
1516
cls.players = [
16-
axelrod.Cooperator(),
17-
axelrod.TitForTat(),
18-
axelrod.Defector(),
19-
axelrod.Grudger(),
20-
axelrod.GoByMajority(),
17+
axl.Cooperator(),
18+
axl.TitForTat(),
19+
axl.Defector(),
20+
axl.Grudger(),
21+
axl.GoByMajority(),
2122
]
2223
cls.player_names = [str(p) for p in cls.players]
2324
cls.test_name = "test"
@@ -33,7 +34,7 @@ def setUpClass(cls):
3334
cls.expected_outcome.sort()
3435

3536
@given(tournaments(
36-
strategies=axelrod.short_run_time_strategies,
37+
strategies=axl.short_run_time_strategies,
3738
min_size=10,
3839
max_size=30,
3940
min_turns=2,
@@ -51,7 +52,7 @@ def test_big_tournaments(self, tournament):
5152
)
5253

5354
def test_serial_play(self):
54-
tournament = axelrod.Tournament(
55+
tournament = axl.Tournament(
5556
name=self.test_name,
5657
players=self.players,
5758
game=self.game,
@@ -63,7 +64,7 @@ def test_serial_play(self):
6364
self.assertEqual(actual_outcome, self.expected_outcome)
6465

6566
def test_parallel_play(self):
66-
tournament = axelrod.Tournament(
67+
tournament = axl.Tournament(
6768
name=self.test_name,
6869
players=self.players,
6970
game=self.game,
@@ -78,12 +79,12 @@ def test_repeat_tournament_deterministic(self):
7879
"""A test to check that tournament gives same results."""
7980
deterministic_players = [
8081
s()
81-
for s in axelrod.short_run_time_strategies
82+
for s in axl.short_run_time_strategies
8283
if not s().classifier["stochastic"]
8384
]
8485
files = []
8586
for _ in range(2):
86-
tournament = axelrod.Tournament(
87+
tournament = axl.Tournament(
8788
name="test",
8889
players=deterministic_players,
8990
game=self.game,
@@ -100,13 +101,13 @@ def test_repeat_tournament_stochastic(self):
100101
"""
101102
files = []
102103
for _ in range(2):
103-
axelrod.seed(0)
104+
axl.seed(0)
104105
stochastic_players = [
105106
s()
106-
for s in axelrod.short_run_time_strategies
107+
for s in axl.short_run_time_strategies
107108
if s().classifier["stochastic"]
108109
]
109-
tournament = axelrod.Tournament(
110+
tournament = axl.Tournament(
110111
name="test",
111112
players=stochastic_players,
112113
game=self.game,
@@ -121,14 +122,14 @@ def test_repeat_tournament_stochastic(self):
121122
class TestNoisyTournament(unittest.TestCase):
122123
def test_noisy_tournament(self):
123124
# Defector should win for low noise
124-
players = [axelrod.Cooperator(), axelrod.Defector()]
125-
tournament = axelrod.Tournament(players, turns=5, repetitions=3, noise=0.0)
125+
players = [axl.Cooperator(), axl.Defector()]
126+
tournament = axl.Tournament(players, turns=5, repetitions=3, noise=0.0)
126127
results = tournament.play(progress_bar=False)
127128
self.assertEqual(results.ranked_names[0], "Defector")
128129

129130
# 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)
131+
players = [axl.Cooperator(), axl.Defector()]
132+
tournament = axl.Tournament(players, turns=5, repetitions=3, noise=0.75)
132133
results = tournament.play(progress_bar=False)
133134
self.assertEqual(results.ranked_names[0], "Cooperator")
134135

@@ -138,10 +139,10 @@ def test_players_do_not_know_match_length(self):
138139
"""Create two players who should cooperate on last two turns if they
139140
don't know when those last two turns are.
140141
"""
141-
p1 = FinalTransformer(["D", "D"])(axelrod.Cooperator)()
142-
p2 = FinalTransformer(["D", "D"])(axelrod.Cooperator)()
142+
p1 = FinalTransformer(["D", "D"])(axl.Cooperator)()
143+
p2 = FinalTransformer(["D", "D"])(axl.Cooperator)()
143144
players = [p1, p2]
144-
tournament = axelrod.Tournament(players, prob_end=0.5, repetitions=1)
145+
tournament = axl.Tournament(players, prob_end=0.5, repetitions=1)
145146
results = tournament.play(progress_bar=False)
146147
# Check that both plays always cooperated
147148
for rating in results.cooperating_rating:
@@ -152,12 +153,12 @@ def test_matches_have_different_length(self):
152153
A match between two players should have variable length across the
153154
repetitions
154155
"""
155-
p1 = axelrod.Cooperator()
156-
p2 = axelrod.Cooperator()
157-
p3 = axelrod.Cooperator()
156+
p1 = axl.Cooperator()
157+
p2 = axl.Cooperator()
158+
p3 = axl.Cooperator()
158159
players = [p1, p2, p3]
159-
axelrod.seed(0)
160-
tournament = axelrod.Tournament(players, prob_end=0.5, repetitions=2)
160+
axl.seed(0)
161+
tournament = axl.Tournament(players, prob_end=0.5, repetitions=2)
161162
results = tournament.play(progress_bar=False)
162163
# Check that match length are different across the repetitions
163164
self.assertNotEqual(results.match_lengths[0], results.match_lengths[1])

0 commit comments

Comments
 (0)