Skip to content

Commit afc2ed4

Browse files
refactored import statements to 'import axelrod as axl' axelrod/tests/unit/*
1 parent 9fff017 commit afc2ed4

24 files changed

+710
-670
lines changed

axelrod/tests/unit/test_actions.py

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

3-
from axelrod import Action
3+
import axelrod as axl
44
from axelrod.action import UnknownActionError, actions_to_str, str_to_actions
55

6-
C, D = Action.C, Action.D
6+
C, D = axl.Action.C, axl.Action.D
77

88

99
class TestAction(unittest.TestCase):
@@ -34,8 +34,8 @@ def test_flip(self):
3434
self.assertEqual(D.flip(), C)
3535

3636
def test_from_char(self):
37-
self.assertEqual(Action.from_char("C"), C)
38-
self.assertEqual(Action.from_char("D"), D)
37+
self.assertEqual(axl.Action.from_char("C"), C)
38+
self.assertEqual(axl.Action.from_char("D"), D)
3939

4040
def test_from_char_error(self):
4141
self.assertRaises(UnknownActionError, Action.from_char, "")

axelrod/tests/unit/test_compute_finite_state_machine_memory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Tests for Compute FSM Memory."""
2-
import axelrod
2+
33
import unittest
44

5+
import axelrod as axl
56
from axelrod.compute_finite_state_machine_memory import *
67

7-
C, D = axelrod.Action.C, axelrod.Action.D
8+
C, D = axl.Action.C, axl.Action.D
89

910

1011
class TestOrderedMemitTuple(unittest.TestCase):

axelrod/tests/unit/test_deterministic_cache.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import unittest
2+
13
import os
4+
25
import pickle
3-
import unittest
46

5-
from axelrod import Action, Defector, DeterministicCache, Random, TitForTat
7+
import axelrod as axl
68

7-
C, D = Action.C, Action.D
9+
C, D = axl.Action.C, axl.Action.D
810

911

1012
class TestDeterministicCache(unittest.TestCase):
1113
@classmethod
1214
def setUpClass(cls):
13-
cls.test_key = (TitForTat(), Defector())
15+
cls.test_key = (axl.TitForTat(), axl.Defector())
1416
cls.test_value = [(C, D), (D, D), (D, D)]
1517
cls.test_save_file = "test_cache_save.txt"
1618
cls.test_load_file = "test_cache_load.txt"
@@ -26,13 +28,13 @@ def tearDownClass(cls):
2628
os.remove(cls.test_load_file)
2729

2830
def setUp(self):
29-
self.cache = DeterministicCache()
31+
self.cache = axl.DeterministicCache()
3032

3133
def test_basic_init(self):
3234
self.assertTrue(self.cache.mutable)
3335

3436
def test_init_from_file(self):
35-
loaded_cache = DeterministicCache(file_name=self.test_load_file)
37+
loaded_cache = axl.DeterministicCache(file_name=self.test_load_file)
3638
self.assertEqual(loaded_cache[self.test_key], self.test_value)
3739

3840
def test_setitem(self):
@@ -49,25 +51,25 @@ def test_setitem_invalid_key_first_two_elements_not_player(self):
4951
with self.assertRaises(ValueError):
5052
self.cache[invalid_key] = self.test_value
5153

52-
invalid_key = (TitForTat(), "test")
54+
invalid_key = (axl.TitForTat(), "test")
5355
with self.assertRaises(ValueError):
5456
self.cache[invalid_key] = self.test_value
5557

56-
invalid_key = ("test", TitForTat())
58+
invalid_key = ("test", axl.TitForTat())
5759
with self.assertRaises(ValueError):
5860
self.cache[invalid_key] = self.test_value
5961

6062
def test_setitem_invalid_key_too_many_players(self):
61-
invalid_key = (TitForTat(), TitForTat(), TitForTat())
63+
invalid_key = (axl.TitForTat(), axl.TitForTat(), axl.TitForTat())
6264
with self.assertRaises(ValueError):
6365
self.cache[invalid_key] = self.test_value
6466

6567
def test_setitem_invalid_key_stochastic_player(self):
66-
invalid_key = (Random(), TitForTat())
68+
invalid_key = (axl.Random(), axl.TitForTat())
6769
with self.assertRaises(ValueError):
6870
self.cache[invalid_key] = self.test_value
6971

70-
invalid_key = (TitForTat(), Random())
72+
invalid_key = (axl.TitForTat(), axl.Random())
7173
with self.assertRaises(ValueError):
7274
self.cache[invalid_key] = self.test_value
7375

axelrod/tests/unit/test_ecosystem.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
import unittest
44

5-
import axelrod
5+
import axelrod as axl
66

77

88
class TestEcosystem(unittest.TestCase):
99
@classmethod
1010
def setUpClass(cls):
11-
cooperators = axelrod.Tournament(
11+
cooperators = axl.Tournament(
1212
players=[
13-
axelrod.Cooperator(),
14-
axelrod.Cooperator(),
15-
axelrod.Cooperator(),
16-
axelrod.Cooperator(),
13+
axl.Cooperator(),
14+
axl.Cooperator(),
15+
axl.Cooperator(),
16+
axl.Cooperator(),
1717
]
1818
)
19-
defector_wins = axelrod.Tournament(
19+
defector_wins = axl.Tournament(
2020
players=[
21-
axelrod.Cooperator(),
22-
axelrod.Cooperator(),
23-
axelrod.Cooperator(),
24-
axelrod.Defector(),
21+
axl.Cooperator(),
22+
axl.Cooperator(),
23+
axl.Cooperator(),
24+
axl.Defector(),
2525
]
2626
)
2727
cls.res_cooperators = cooperators.play()
2828
cls.res_defector_wins = defector_wins.play()
2929

3030
def test_default_population_sizes(self):
31-
eco = axelrod.Ecosystem(self.res_cooperators)
31+
eco = axl.Ecosystem(self.res_cooperators)
3232
pops = eco.population_sizes
3333
self.assertEqual(eco.num_players, 4)
3434
self.assertEqual(len(pops), 1)
@@ -37,7 +37,7 @@ def test_default_population_sizes(self):
3737
self.assertEqual(list(set(pops[0])), [0.25])
3838

3939
def test_non_default_population_sizes(self):
40-
eco = axelrod.Ecosystem(
40+
eco = axl.Ecosystem(
4141
self.res_cooperators, population=[0.7, 0.25, 0.03, 0.02]
4242
)
4343
pops = eco.population_sizes
@@ -48,7 +48,7 @@ def test_non_default_population_sizes(self):
4848
self.assertEqual(pops[0], [0.7, 0.25, 0.03, 0.02])
4949

5050
def test_population_normalization(self):
51-
eco = axelrod.Ecosystem(self.res_cooperators, population=[70, 25, 3, 2])
51+
eco = axl.Ecosystem(self.res_cooperators, population=[70, 25, 3, 2])
5252
pops = eco.population_sizes
5353
self.assertEqual(eco.num_players, 4)
5454
self.assertEqual(len(pops), 1)
@@ -59,26 +59,26 @@ def test_population_normalization(self):
5959
def test_results_and_population_of_different_sizes(self):
6060
self.assertRaises(
6161
TypeError,
62-
axelrod.Ecosystem,
62+
axl.Ecosystem,
6363
self.res_cooperators,
6464
population=[0.7, 0.2, 0.03, 0.1, 0.1],
6565
)
6666

6767
def test_negative_populations(self):
6868
self.assertRaises(
6969
TypeError,
70-
axelrod.Ecosystem,
70+
axl.Ecosystem,
7171
self.res_cooperators,
7272
population=[0.7, -0.2, 0.03, 0.2],
7373
)
7474

7575
def test_fitness_function(self):
7676
fitness = lambda p: 2 * p
77-
eco = axelrod.Ecosystem(self.res_cooperators, fitness=fitness)
77+
eco = axl.Ecosystem(self.res_cooperators, fitness=fitness)
7878
self.assertTrue(eco.fitness(10), 20)
7979

8080
def test_cooperators_are_stable_over_time(self):
81-
eco = axelrod.Ecosystem(self.res_cooperators)
81+
eco = axl.Ecosystem(self.res_cooperators)
8282
eco.reproduce(100)
8383
pops = eco.population_sizes
8484
self.assertEqual(len(pops), 101)
@@ -88,7 +88,7 @@ def test_cooperators_are_stable_over_time(self):
8888
self.assertEqual(list(set(p)), [0.25])
8989

9090
def test_defector_wins_with_only_cooperators(self):
91-
eco = axelrod.Ecosystem(self.res_defector_wins)
91+
eco = axl.Ecosystem(self.res_defector_wins)
9292
eco.reproduce(1000)
9393
pops = eco.population_sizes
9494
self.assertEqual(len(pops), 1001)

axelrod/tests/unit/test_eigen.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import unittest
44

55
import numpy
6-
from axelrod.eigen import _normalise, principal_eigenvector
76
from numpy.testing import assert_array_almost_equal
87

8+
from axelrod.eigen import _normalise, principal_eigenvector
9+
10+
911

1012
class FunctionCases(unittest.TestCase):
1113
def test_identity_matrices(self):

axelrod/tests/unit/test_filters.py

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

3-
from axelrod import filtered_strategies
3+
import axelrod as axl
44
from axelrod.strategies._filters import *
55

66
from hypothesis import example, given, settings
@@ -156,14 +156,14 @@ class UsesLengthTestStrategy(object):
156156
uses_length_filterset = {"stochastic": True, "makes_use_of": ["length"]}
157157

158158
self.assertEqual(
159-
filtered_strategies(stochastic_filterset, strategies),
159+
axl.filtered_strategies(stochastic_filterset, strategies),
160160
[StochasticTestStrategy, UsesLengthTestStrategy],
161161
)
162162
self.assertEqual(
163-
filtered_strategies(deterministic_filterset, strategies),
163+
axl.filtered_strategies(deterministic_filterset, strategies),
164164
[MemoryDepth2TestStrategy],
165165
)
166166
self.assertEqual(
167-
filtered_strategies(uses_length_filterset, strategies),
167+
axl.filtered_strategies(uses_length_filterset, strategies),
168168
[UsesLengthTestStrategy],
169169
)

axelrod/tests/unit/test_fingerprint.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import os
21
import unittest
3-
from tempfile import mkstemp
42
from unittest.mock import patch
53

4+
import os
5+
6+
from tempfile import mkstemp
7+
68
import matplotlib.pyplot
9+
710
import numpy as np
8-
from hypothesis import given, settings
911

1012
import axelrod as axl
1113
from axelrod.fingerprint import AshlockFingerprint, Point, TransitiveFingerprint
1214
from axelrod.strategy_transformers import DualTransformer, JossAnnTransformer
1315
from axelrod.tests.property import strategy_lists
1416

17+
from hypothesis import given, settings
18+
19+
1520
C, D = axl.Action.C, axl.Action.D
1621

1722

axelrod/tests/unit/test_game.py

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

3-
from axelrod import Action, Game
3+
import axelrod as axl
44
from axelrod.tests.property import games
55

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

9-
C, D = Action.C, Action.D
9+
C, D = axl.Action.C, axl.Action.D
1010

1111

1212
class TestGame(unittest.TestCase):
@@ -17,29 +17,29 @@ def test_default_scores(self):
1717
(D, D): (1, 1),
1818
(C, C): (3, 3),
1919
}
20-
self.assertEqual(Game().scores, expected_scores)
20+
self.assertEqual(axl.Game().scores, expected_scores)
2121

2222
def test_default_RPST(self):
2323
expected_values = (3, 1, 0, 5)
24-
self.assertEqual(Game().RPST(), expected_values)
24+
self.assertEqual(axl.Game().RPST(), expected_values)
2525

2626
def test_default_score(self):
27-
game = Game()
27+
game = axl.Game()
2828
self.assertEqual(game.score((C, C)), (3, 3))
2929
self.assertEqual(game.score((D, D)), (1, 1))
3030
self.assertEqual(game.score((C, D)), (0, 5))
3131
self.assertEqual(game.score((D, C)), (5, 0))
3232

3333
def test_default_equality(self):
34-
self.assertEqual(Game(), Game())
34+
self.assertEqual(axl.Game(), axl.Game())
3535

3636
def test_not_default_equality(self):
37-
self.assertEqual(Game(1, 2, 3, 4), Game(1, 2, 3, 4))
38-
self.assertNotEqual(Game(1, 2, 3, 4), Game(1, 2, 3, 5))
39-
self.assertNotEqual(Game(1, 2, 3, 4), Game())
37+
self.assertEqual(axl.Game(1, 2, 3, 4), axl.Game(1, 2, 3, 4))
38+
self.assertNotEqual(axl.Game(1, 2, 3, 4), axl.Game(1, 2, 3, 5))
39+
self.assertNotEqual(axl.Game(1, 2, 3, 4), axl.Game())
4040

4141
def test_wrong_class_equality(self):
42-
self.assertNotEqual(Game(), "wrong class")
42+
self.assertNotEqual(axl.Game(), "wrong class")
4343

4444
@given(r=integers(), p=integers(), s=integers(), t=integers())
4545
@settings(max_examples=5)
@@ -51,21 +51,21 @@ def test_random_init(self, r, p, s, t):
5151
(D, D): (p, p),
5252
(C, C): (r, r),
5353
}
54-
game = Game(r, s, t, p)
54+
game = axl.Game(r, s, t, p)
5555
self.assertEqual(game.scores, expected_scores)
5656

5757
@given(r=integers(), p=integers(), s=integers(), t=integers())
5858
@settings(max_examples=5)
5959
def test_random_RPST(self, r, p, s, t):
6060
"""Test RPST method with random scores using the hypothesis library."""
61-
game = Game(r, s, t, p)
61+
game = axl.Game(r, s, t, p)
6262
self.assertEqual(game.RPST(), (r, p, s, t))
6363

6464
@given(r=integers(), p=integers(), s=integers(), t=integers())
6565
@settings(max_examples=5)
6666
def test_random_score(self, r, p, s, t):
6767
"""Test score method with random scores using the hypothesis library."""
68-
game = Game(r, s, t, p)
68+
game = axl.Game(r, s, t, p)
6969
self.assertEqual(game.score((C, C)), (r, r))
7070
self.assertEqual(game.score((D, D)), (p, p))
7171
self.assertEqual(game.score((C, D)), (s, t))

0 commit comments

Comments
 (0)