Skip to content

Commit f587405

Browse files
drvinceknightmarcharper
authored andcommitted
Fix bug in fingerprint with filename.
This wasn't working correctly and had been missed as we were not covering a line.
1 parent 9457413 commit f587405

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

axelrod/fingerprint.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,13 @@ def fingerprint(self, turns=50, repetitions=10, step=0.01, processes=None,
258258

259259
if on_windows and (filename is None): # pragma: no cover
260260
in_memory = True
261-
elif filename is not None:
262-
outputfile = open(filename, 'w')
263-
filename = outputfile.name
264-
else:
261+
elif filename is None:
265262
outputfile = NamedTemporaryFile(mode='w')
266263
filename = outputfile.name
267264

268265
edges, tourn_players = self.construct_tournament_elements(
269266
step, progress_bar=progress_bar)
267+
270268
self.step = step
271269
self.spatial_tournament = axl.SpatialTournament(
272270
tourn_players,

axelrod/tests/unit/test_fingerprint.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def test_progress_bar_fingerprint(self):
110110
progress_bar=True)
111111
self.assertEqual(sorted(data.keys()), self.expected_points)
112112

113+
def test_fingerprint_with_filename(self):
114+
filename = "test_outputs/test_fingerprint.csv"
115+
af = AshlockFingerprint(self.strategy, self.probe)
116+
af.fingerprint(turns=1, repetitions=1, step=0.5, progress_bar=False,
117+
filename=filename)
118+
with open(filename, 'r') as out:
119+
data = out.read()
120+
self.assertEqual(len(data.split("\n")), 10)
121+
113122
def test_in_memory_fingerprint(self):
114123
af = AshlockFingerprint(self.strategy, self.probe)
115124
af.fingerprint(turns=10, repetitions=2, step=0.5, progress_bar=False,

axelrod/tests/unit/test_tournament.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_warning(self):
8989
repetitions=1)
9090
with warnings.catch_warnings(record=True) as w:
9191
# Check that a warning is raised if no results set is built and no
92-
# filename given
92+
# filename not given
9393
results = tournament.play(build_results=False, progress_bar=False)
9494
self.assertEqual(len(w), 1)
9595

0 commit comments

Comments
 (0)