Skip to content

Commit 60d77f3

Browse files
committed
Add comment and another test that invokes multiprocessing
1 parent 401acaf commit 60d77f3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/axelrod_fortran/player.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def strategy(self, opponent):
114114
return actions[original_action]
115115

116116
def _release_shared_library(self):
117+
# While this looks like we're checking that the shared library file
118+
# isn't deleted, the exception is actually thrown in the manager
119+
# thread closes before the player class is garbage collected, which
120+
# tends to happen at the end of a script.
117121
try:
118122
shared_library_manager.release(self.original_name, self.index)
119123
except FileNotFoundError:

tests/test_player.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from ctypes import c_int, c_float, POINTER, CDLL
22
import itertools
3+
import random
34

45
import pytest
56

67
from axelrod_fortran import Player, characteristics, all_strategies
78
from axelrod import (Alternator, Cooperator, Defector, Match, MoranProcess,
8-
Game, basic_strategies, seed)
9+
Game, basic_strategies, seed, Tournament)
910
from axelrod.action import Action
1011

1112

@@ -180,8 +181,17 @@ def test_no_warning_for_normal_interaction(recwarn):
180181

181182

182183
def test_multiple_copies(recwarn):
184+
"""Test that multiple copies of a strategy doesn't cause any errors."""
183185
players = [Player('ktitfortatc') for _ in range(5)] + [
184186
Player('k42r') for _ in range(5)]
185187
mp = MoranProcess(players)
186188
mp.play()
187-
mp.populations_plot()
189+
assert len(recwarn) == 0
190+
191+
192+
def test_small_tournament(recwarn):
193+
players = [Player(name) for name in all_strategies]
194+
players = random.sample(players, 20)
195+
tournament = Tournament(players, repetitions=1)
196+
results = tournament.play(processes=2)
197+
assert len(recwarn) == 0

0 commit comments

Comments
 (0)