Skip to content

Commit a28ed1e

Browse files
committed
Add on_windows property
1 parent e10adb0 commit a28ed1e

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

axelrod/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import absolute_import
2+
import sys
23

34
# The order of imports matters!
45
from .actions import Actions, flip_action
@@ -15,3 +16,5 @@
1516
from .tournament import Tournament, ProbEndTournament, SpatialTournament, ProbEndSpatialTournament
1617
from .result_set import ResultSet, ResultSetFromFile
1718
from .ecosystem import Ecosystem
19+
20+
on_windows = sys.platform.startswith("win")

axelrod/tests/integration/test_tournament.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import unittest
22
import axelrod
33
import filecmp
4-
import sys
54

65
from axelrod.strategy_transformers import FinalTransformer
76

@@ -50,7 +49,7 @@ def test_serial_play(self):
5049
actual_outcome = sorted(zip(self.player_names, scores))
5150
self.assertEqual(actual_outcome, self.expected_outcome)
5251

53-
@unittest.skipIf(sys.platform.startswith("win"),
52+
@unittest.skipIf(axelrod.on_windows,
5453
"Parallel processing not supported on Windows")
5554
def test_parallel_play(self):
5655
tournament = axelrod.Tournament(

axelrod/tests/unit/test_tournament.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from multiprocessing import Queue, cpu_count
66
import unittest
77
import warnings
8-
import sys
98

109
from hypothesis import given, example, settings
1110
from hypothesis.strategies import integers, floats
@@ -190,7 +189,7 @@ def test_progress_bar_play(self):
190189
self.assertIsInstance(results, axelrod.ResultSet)
191190
self.assertEqual(tournament.progress_bar.total, 15)
192191

193-
@unittest.skipIf(sys.platform.startswith("win"),
192+
@unittest.skipIf(axelrod.on_windows,
194193
"Parallel processing not supported on Windows")
195194
def test_progress_bar_play_parallel(self):
196195
"""Test that tournament plays when asking for progress bar for parallel
@@ -237,7 +236,7 @@ def test_property_serial_play(self, tournament):
237236
self.assertEqual(results.nplayers, len(tournament.players))
238237
self.assertEqual(results.players, [str(p) for p in tournament.players])
239238

240-
@unittest.skipIf(sys.platform.startswith("win"),
239+
@unittest.skipIf(axelrod.on_windows,
241240
"Parallel processing not supported on Windows")
242241
def test_parallel_play(self):
243242
# Test that we get an instance of ResultSet
@@ -279,7 +278,7 @@ def test_run_serial(self):
279278
calls = tournament._write_interactions.call_args_list
280279
self.assertEqual(len(calls), 15)
281280

282-
@unittest.skipIf(sys.platform.startswith("win"),
281+
@unittest.skipIf(axelrod.on_windows,
283282
"Parallel processing not supported on Windows")
284283
def test_run_parallel(self):
285284
tournament = axelrod.Tournament(
@@ -296,7 +295,7 @@ def test_run_parallel(self):
296295
calls = tournament._write_interactions.call_args_list
297296
self.assertEqual(len(calls), 15)
298297

299-
@unittest.skipIf(sys.platform.startswith("win"),
298+
@unittest.skipIf(axelrod.on_windows,
300299
"Parallel processing not supported on Windows")
301300
def test_n_workers(self):
302301
max_processes = cpu_count()
@@ -318,7 +317,7 @@ def test_n_workers(self):
318317
self.assertEqual(tournament._n_workers(processes=max_processes+2),
319318
max_processes)
320319

321-
@unittest.skipIf(sys.platform.startswith("win"),
320+
@unittest.skipIf(axelrod.on_windows,
322321
"Parallel processing not supported on Windows")
323322
@unittest.skipIf(
324323
cpu_count() < 2,
@@ -335,7 +334,7 @@ def test_2_workers(self):
335334
repetitions=self.test_repetitions,)
336335
self.assertEqual(tournament._n_workers(processes=2), 2)
337336

338-
@unittest.skipIf(sys.platform.startswith("win"),
337+
@unittest.skipIf(axelrod.on_windows,
339338
"Parallel processing not supported on Windows")
340339
def test_start_workers(self):
341340
workers = 2
@@ -359,7 +358,7 @@ def test_start_workers(self):
359358
stops += 1
360359
self.assertEqual(stops, workers)
361360

362-
@unittest.skipIf(sys.platform.startswith("win"),
361+
@unittest.skipIf(axelrod.on_windows,
363362
"Parallel processing not supported on Windows")
364363
def test_worker(self):
365364
tournament = axelrod.Tournament(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import unittest
2+
import sys
3+
import axelrod
4+
5+
class TestWindowsDetection(unittest.TestCase):
6+
7+
@unittest.skipIf(sys.platform.startswith("win"),
8+
"Skip this test if on windows")
9+
def test_detection_on_not_windows(self):
10+
"""Test when not on windows"""
11+
self.assertFalse(axelrod.on_windows)
12+
13+
@unittest.skipIf(not sys.platform.startswith("win"),
14+
"Skip this test if not on windows")
15+
def test_detection_on_not_windows(self):
16+
"""Test when on windows"""
17+
self.assertTrue(axelrod.on_windows)

0 commit comments

Comments
 (0)