Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cleanup issue 1287 #1308

Merged
merged 17 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7dd2f26
refactored import statements as 'import axelrod as axl' in axelrod/te…
sudarshan-parvatikar Mar 31, 2020
d74975a
refactored import statements to 'import axelrod as axel' axelrod/test…
sudarshan-parvatikar Mar 31, 2020
0715624
refactored import statements to 'import axelrod as axl' axelrod/tests…
sudarshan-parvatikar Mar 31, 2020
977ed05
refactored import statement for axel.strategies in axelrod/tests/prop…
sudarshan-parvatikar Mar 31, 2020
1f6b434
fixed non-updated 'axelrod.*' calls to axl.*'
sudarshan-parvatikar Mar 31, 2020
9416fd2
fixed un-updated import statements in tests/unit/test_actions.py and …
sudarshan-parvatikar Apr 2, 2020
92702ac
refactored import statements as 'import axelrod as axl' in axelrod/te…
sudarshan-parvatikar Mar 31, 2020
9fff017
refactored import statements to 'import axelrod as axel' axelrod/test…
sudarshan-parvatikar Mar 31, 2020
afc2ed4
refactored import statements to 'import axelrod as axl' axelrod/tests…
sudarshan-parvatikar Mar 31, 2020
f967b58
refactored import statement for axel.strategies in axelrod/tests/prop…
sudarshan-parvatikar Mar 31, 2020
2288674
fixed non-updated 'axelrod.*' calls to axl.*'
sudarshan-parvatikar Mar 31, 2020
ed437bf
fixed un-updated import statements in tests/unit/test_actions.py and …
sudarshan-parvatikar Apr 2, 2020
25acbd5
Merge remote-tracking branch 'refs/remotes/origin/test-cleanup-issue-…
sudarshan-parvatikar Apr 3, 2020
9ef4dde
rebased master and fixed merge conflict
sudarshan-parvatikar Apr 3, 2020
8947e69
reordered import statements in tests/integration/test_tournament.py &…
sudarshan-parvatikar Apr 3, 2020
0ae2a01
removed blank line bw import stmts, fixed import issues
sudarshan-parvatikar Apr 5, 2020
c4a19c2
fixed import statements
sudarshan-parvatikar Apr 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions axelrod/tests/integration/test_filtering.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest

from axelrod import filtered_strategies, seed, short_run_time_strategies
import axelrod as axl
from axelrod.tests.property import strategy_lists

from hypothesis import example, given, settings
from hypothesis.strategies import integers

Expand All @@ -26,7 +27,7 @@ def test_boolean_filtering(self, strategies):
for classifier in classifiers:
comprehension = set([s for s in strategies if s.classifier[classifier]])
filterset = {classifier: True}
filtered = set(filtered_strategies(filterset, strategies=strategies))
filtered = set(axl.filtered_strategies(filterset, strategies=strategies))
self.assertEqual(comprehension, filtered)

@given(
Expand All @@ -39,7 +40,7 @@ def test_boolean_filtering(self, strategies):
min_memory_depth=float("inf"),
max_memory_depth=float("inf"),
memory_depth=float("inf"),
strategies=short_run_time_strategies,
strategies=axl.short_run_time_strategies,
)
@settings(max_examples=5)
def test_memory_depth_filtering(
Expand All @@ -55,7 +56,7 @@ def test_memory_depth_filtering(
]
)
min_filterset = {"min_memory_depth": min_memory_depth}
min_filtered = set(filtered_strategies(min_filterset,
min_filtered = set(axl.filtered_strategies(min_filterset,
strategies=strategies))
self.assertEqual(min_comprehension, min_filtered)

Expand All @@ -67,7 +68,7 @@ def test_memory_depth_filtering(
]
)
max_filterset = {"max_memory_depth": max_memory_depth}
max_filtered = set(filtered_strategies(max_filterset,
max_filtered = set(axl.filtered_strategies(max_filterset,
strategies=strategies))
self.assertEqual(max_comprehension, max_filtered)

Expand All @@ -79,7 +80,7 @@ def test_memory_depth_filtering(
]
)
filterset = {"memory_depth": memory_depth}
filtered = set(filtered_strategies(filterset, strategies=strategies))
filtered = set(axl.filtered_strategies(filterset, strategies=strategies))
self.assertEqual(comprehension, filtered)

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

for classifier in classifiers:
seed(seed_)
axl.seed(seed_)
comprehension = set(
[
s
Expand All @@ -104,9 +105,9 @@ def test_makes_use_of_filtering(self, seed_, strategies):
]
)

seed(seed_)
axl.seed(seed_)
filterset = {"makes_use_of": classifier}
filtered = set(filtered_strategies(filterset, strategies=strategies))
filtered = set(axl.filtered_strategies(filterset, strategies=strategies))

self.assertEqual(
comprehension, filtered, msg="classifier: {}".format(classifier)
Expand Down
26 changes: 13 additions & 13 deletions axelrod/tests/integration/test_matches.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Tests for some expected match behaviours"""
import unittest

import axelrod
import axelrod as axl
from axelrod.tests.property import strategy_lists

from hypothesis import given, settings
from hypothesis.strategies import integers

C, D = axelrod.Action.C, axelrod.Action.D
C, D = axl.Action.C, axl.Action.D

deterministic_strategies = [
s for s in axelrod.short_run_time_strategies if not s().classifier["stochastic"]
s for s in axl.short_run_time_strategies if not s().classifier["stochastic"]
]
stochastic_strategies = [
s for s in axelrod.short_run_time_strategies if s().classifier["stochastic"]
s for s in axl.short_run_time_strategies if s().classifier["stochastic"]
]


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

Expand All @@ -46,9 +46,9 @@ def test_outcome_repeats_stochastic(self, strategies, turns, seed):
same result"""
results = []
for _ in range(3):
axelrod.seed(seed)
axl.seed(seed)
players = [s() for s in strategies]
results.append(axelrod.Match(players, turns).play())
results.append(axl.Match(players, turns).play())

self.assertEqual(results[0], results[1])
self.assertEqual(results[1], results[2])
Expand All @@ -57,15 +57,15 @@ def test_matches_with_det_player_for_stochastic_classes(self):
"""A test based on a bug found in the cache.

See: https://github.com/Axelrod-Python/Axelrod/issues/779"""
p1 = axelrod.MemoryOnePlayer(four_vector=(0, 0, 0, 0))
p2 = axelrod.MemoryOnePlayer(four_vector=(1, 0, 1, 0))
p3 = axelrod.MemoryOnePlayer(four_vector=(1, 1, 1, 0))
p1 = axl.MemoryOnePlayer(four_vector=(0, 0, 0, 0))
p2 = axl.MemoryOnePlayer(four_vector=(1, 0, 1, 0))
p3 = axl.MemoryOnePlayer(four_vector=(1, 1, 1, 0))

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

m = axelrod.Match((p2, p3), turns=3)
m = axl.Match((p2, p3), turns=3)
self.assertEqual(m.play(), [(C, C), (C, C), (C, C)])

m = axelrod.Match((p1, p3), turns=3)
m = axl.Match((p1, p3), turns=3)
self.assertEqual(m.play(), [(C, C), (D, C), (D, C)])
10 changes: 5 additions & 5 deletions axelrod/tests/integration/test_names.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest

from axelrod import all_strategies
import axelrod as axl


class TestNames(unittest.TestCase):
def test_all_strategies_have_names(self):
names = [s.name for s in all_strategies if s.name]
self.assertEqual(len(names), len(all_strategies))
names = [s.name for s in axl.all_strategies if s.name]
self.assertEqual(len(names), len(axl.all_strategies))

def test_all_names_are_unique(self):
names = set(s.name for s in all_strategies)
self.assertEqual(len(names), len(all_strategies))
names = set(s.name for s in axl.all_strategies)
self.assertEqual(len(names), len(axl.all_strategies))
10 changes: 5 additions & 5 deletions axelrod/tests/integration/test_sample_tournaments.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import unittest

import axelrod
import axelrod as axl

C, D = axelrod.Action.C, axelrod.Action.D
C, D = axl.Action.C, axl.Action.D


class TestSampleTournaments(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.game = axelrod.Game()
cls.game = axl.Game()

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

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

# Play the tournament and build the actual outcome tuples.
tournament = axelrod.Tournament(
tournament = axl.Tournament(
players=players, game=cls.game, turns=turns, repetitions=1
)
results = tournament.play(progress_bar=False)
Expand Down
58 changes: 29 additions & 29 deletions axelrod/tests/integration/test_tournament.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import filecmp
import unittest

from hypothesis import given, settings
import filecmp

import axelrod
import axelrod as axl
from axelrod.strategy_transformers import FinalTransformer
from axelrod.tests.property import tournaments

from hypothesis import given, settings

class TestTournament(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.game = axelrod.Game()
cls.game = axl.Game()
cls.players = [
axelrod.Cooperator(),
axelrod.TitForTat(),
axelrod.Defector(),
axelrod.Grudger(),
axelrod.GoByMajority(),
axl.Cooperator(),
axl.TitForTat(),
axl.Defector(),
axl.Grudger(),
axl.GoByMajority(),
]
cls.player_names = [str(p) for p in cls.players]
cls.test_name = "test"
Expand All @@ -33,7 +33,7 @@ def setUpClass(cls):
cls.expected_outcome.sort()

@given(tournaments(
strategies=axelrod.short_run_time_strategies,
strategies=axl.short_run_time_strategies,
min_size=10,
max_size=30,
min_turns=2,
Expand All @@ -51,7 +51,7 @@ def test_big_tournaments(self, tournament):
)

def test_serial_play(self):
tournament = axelrod.Tournament(
tournament = axl.Tournament(
name=self.test_name,
players=self.players,
game=self.game,
Expand All @@ -63,7 +63,7 @@ def test_serial_play(self):
self.assertEqual(actual_outcome, self.expected_outcome)

def test_parallel_play(self):
tournament = axelrod.Tournament(
tournament = axl.Tournament(
name=self.test_name,
players=self.players,
game=self.game,
Expand All @@ -78,12 +78,12 @@ def test_repeat_tournament_deterministic(self):
"""A test to check that tournament gives same results."""
deterministic_players = [
s()
for s in axelrod.short_run_time_strategies
for s in axl.short_run_time_strategies
if not s().classifier["stochastic"]
]
files = []
for _ in range(2):
tournament = axelrod.Tournament(
tournament = axl.Tournament(
name="test",
players=deterministic_players,
game=self.game,
Expand All @@ -100,13 +100,13 @@ def test_repeat_tournament_stochastic(self):
"""
files = []
for _ in range(2):
axelrod.seed(0)
axl.seed(0)
stochastic_players = [
s()
for s in axelrod.short_run_time_strategies
for s in axl.short_run_time_strategies
if s().classifier["stochastic"]
]
tournament = axelrod.Tournament(
tournament = axl.Tournament(
name="test",
players=stochastic_players,
game=self.game,
Expand All @@ -121,14 +121,14 @@ def test_repeat_tournament_stochastic(self):
class TestNoisyTournament(unittest.TestCase):
def test_noisy_tournament(self):
# Defector should win for low noise
players = [axelrod.Cooperator(), axelrod.Defector()]
tournament = axelrod.Tournament(players, turns=5, repetitions=3, noise=0.0)
players = [axl.Cooperator(), axl.Defector()]
tournament = axl.Tournament(players, turns=5, repetitions=3, noise=0.0)
results = tournament.play(progress_bar=False)
self.assertEqual(results.ranked_names[0], "Defector")

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

Expand All @@ -138,10 +138,10 @@ def test_players_do_not_know_match_length(self):
"""Create two players who should cooperate on last two turns if they
don't know when those last two turns are.
"""
p1 = FinalTransformer(["D", "D"])(axelrod.Cooperator)()
p2 = FinalTransformer(["D", "D"])(axelrod.Cooperator)()
p1 = FinalTransformer(["D", "D"])(axl.Cooperator)()
p2 = FinalTransformer(["D", "D"])(axl.Cooperator)()
players = [p1, p2]
tournament = axelrod.Tournament(players, prob_end=0.5, repetitions=1)
tournament = axl.Tournament(players, prob_end=0.5, repetitions=1)
results = tournament.play(progress_bar=False)
# Check that both plays always cooperated
for rating in results.cooperating_rating:
Expand All @@ -152,12 +152,12 @@ def test_matches_have_different_length(self):
A match between two players should have variable length across the
repetitions
"""
p1 = axelrod.Cooperator()
p2 = axelrod.Cooperator()
p3 = axelrod.Cooperator()
p1 = axl.Cooperator()
p2 = axl.Cooperator()
p3 = axl.Cooperator()
players = [p1, p2, p3]
axelrod.seed(0)
tournament = axelrod.Tournament(players, prob_end=0.5, repetitions=2)
axl.seed(0)
tournament = axl.Tournament(players, prob_end=0.5, repetitions=2)
results = tournament.play(progress_bar=False)
# Check that match length are different across the repetitions
self.assertNotEqual(results.match_lengths[0], results.match_lengths[1])
Loading