Skip to content

Commit b83e4d4

Browse files
committed
Temporary commit: Fix tests, update requirements, and tox configuration
1 parent a700314 commit b83e4d4

File tree

7 files changed

+112
-60
lines changed

7 files changed

+112
-60
lines changed

CHANGES.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@ Mainly internal changes: fix for `TestOpponent` class and updates to various fil
44

55
- Fixed `TestOpponent` class in `axelrod/tests/strategies/test_player.py` to remove the `__init__` constructor and replaced it with a static `strategy` method to resolve PytestCollectionWarning.
66
- The class now defines a `strategy` method that returns `C`, as required for it to be collectable by pytest.
7-
8-
```python
9-
class OpponentTest(axl.Player):
10-
"""A player who only exists so we have something to test against"""
11-
12-
name = "OpponentTest"
13-
classifier = _test_classifier
14-
15-
@staticmethod
16-
def strategy(opponent):
17-
return C
187

8+
- Renamed `TestMakesUseOfLengthAndGamePlayer` class to `MakesUseOfLengthAndGamePlayer` in axelrod/tests/unit/test_makes_use_of.py to resolve PytestCollectionWarning.
9+
- Renamed `TestMakesUseOfNothingPlayer` class to `MakesUseOfNothingPlayer` in axelrod/tests/unit/test_makes_use_of.py to resolve PytestCollectionWarning.
1910
- **Updated docs/Makefile**.
2011
- **Updated setup.py**.
2112

MG_test/MG_test.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

axelrod/tests/strategies/test_player.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def test_init_kwargs(self):
349349
TypeError, ParameterisedTestPlayer, "other", "other", "other"
350350
)
351351

352+
352353
# TestPlayer class for testing against a known opponent
353354
# class TestOpponent(axl.Player):
354355
# """A player who only exists so we have something to test against"""
@@ -360,6 +361,7 @@ def test_init_kwargs(self):
360361
# def strategy(opponent):
361362
# return C
362363

364+
363365
class OpponentTest(axl.Player):
364366
"""A player who only exists so we have something to test against"""
365367

@@ -370,6 +372,7 @@ class OpponentTest(axl.Player):
370372
def strategy(opponent):
371373
return C
372374

375+
373376
class TestPlayer(unittest.TestCase):
374377
"""A Test class from which other player test classes are inherited."""
375378

@@ -642,7 +645,7 @@ def classifier_test(self, expected_class_classifier=None):
642645
"stochastic" in player.classifier,
643646
msg="stochastic not in classifier",
644647
)
645-
# OpponentTest
648+
# OpponentTest
646649
for key in OpponentTest.classifier:
647650
self.assertEqual(
648651
axl.Classifiers[key](player),

axelrod/tests/unit/test_game.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_invalid_matrices(self, A, B):
113113
self.assertEqual(error_raised, (A.shape != B.transpose().shape))
114114

115115
@given(asymgame=asymmetric_games())
116-
@settings(max_examples=5)
116+
@settings(max_examples=5, deadline=3000)
117117
def test_random_repr(self, asymgame):
118118
"""Test repr with random scores."""
119119
expected_repr = "Axelrod game with matrices: {}".format(

axelrod/tests/unit/test_property.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020

2121
class TestStrategyList(unittest.TestCase):
22-
def test_call(self):
23-
strategies = strategy_lists().example()
22+
# MG: Replaced .example() with @given for generating strategies
23+
@given(strategies=strategy_lists())
24+
@settings(max_examples=3)
25+
def test_call(self, strategies):
2426
self.assertIsInstance(strategies, list)
2527
for p in strategies:
2628
self.assertIsInstance(p(), axl.Player)
2729

2830
@given(strategies=strategy_lists(min_size=1, max_size=50))
29-
@settings(max_examples=5)
31+
@settings(max_examples=3)
3032
def test_decorator(self, strategies):
3133
self.assertIsInstance(strategies, list)
3234
self.assertGreaterEqual(len(strategies), 1)
@@ -35,7 +37,7 @@ def test_decorator(self, strategies):
3537
self.assertIsInstance(strategy(), axl.Player)
3638

3739
@given(strategies=strategy_lists(strategies=axl.basic_strategies))
38-
@settings(max_examples=5)
40+
@settings(max_examples=3)
3941
def test_decorator_with_given_strategies(self, strategies):
4042
self.assertIsInstance(strategies, list)
4143
basic_player_names = [str(s()) for s in axl.basic_strategies]
@@ -50,12 +52,14 @@ class TestMatch(unittest.TestCase):
5052
Test that the composite method works
5153
"""
5254

53-
def test_call(self):
54-
match = matches().example()
55+
# MG: Replaced .example() with @given for match generation
56+
@given(match=matches())
57+
@settings(max_examples=3)
58+
def test_call(self, match):
5559
self.assertIsInstance(match, axl.Match)
5660

5761
@given(match=matches(min_turns=10, max_turns=50, min_noise=0, max_noise=1))
58-
@settings(max_examples=5)
62+
@settings(max_examples=3)
5963
def test_decorator(self, match):
6064
self.assertIsInstance(match, axl.Match)
6165
self.assertGreaterEqual(len(match), 10)
@@ -64,7 +68,7 @@ def test_decorator(self, match):
6468
self.assertLessEqual(match.noise, 1)
6569

6670
@given(match=matches(min_turns=10, max_turns=50, min_noise=0, max_noise=0))
67-
@settings(max_examples=5)
71+
@settings(max_examples=3)
6872
def test_decorator_with_no_noise(self, match):
6973
self.assertIsInstance(match, axl.Match)
7074
self.assertGreaterEqual(len(match), 10)
@@ -73,8 +77,10 @@ def test_decorator_with_no_noise(self, match):
7377

7478

7579
class TestTournament(unittest.TestCase):
76-
def test_call(self):
77-
tournament = tournaments().example()
80+
# MG: Replaced .example() with @given for tournament generation
81+
@given(tournament=tournaments())
82+
@settings(max_examples=3)
83+
def test_call(self, tournament):
7884
self.assertIsInstance(tournament, axl.Tournament)
7985

8086
@given(
@@ -88,7 +94,7 @@ def test_call(self):
8894
max_size=3,
8995
)
9096
)
91-
@settings(max_examples=5)
97+
@settings(max_examples=3)
9298
def test_decorator(self, tournament):
9399
self.assertIsInstance(tournament, axl.Tournament)
94100
self.assertLessEqual(tournament.turns, 50)
@@ -99,7 +105,7 @@ def test_decorator(self, tournament):
99105
self.assertGreaterEqual(tournament.repetitions, 2)
100106

101107
@given(tournament=tournaments(strategies=axl.basic_strategies, max_size=3))
102-
@settings(max_examples=5)
108+
@settings(max_examples=3)
103109
def test_decorator_with_given_strategies(self, tournament):
104110
self.assertIsInstance(tournament, axl.Tournament)
105111
basic_player_names = [str(s()) for s in axl.basic_strategies]
@@ -108,8 +114,9 @@ def test_decorator_with_given_strategies(self, tournament):
108114

109115

110116
class TestProbEndTournament(unittest.TestCase):
111-
def test_call(self):
112-
tournament = tournaments().example()
117+
@given(tournament=prob_end_tournaments())
118+
@settings(max_examples=3)
119+
def test_call(self, tournament):
113120
self.assertIsInstance(tournament, axl.Tournament)
114121

115122
@given(
@@ -123,7 +130,7 @@ def test_call(self):
123130
max_size=3,
124131
)
125132
)
126-
@settings(max_examples=5)
133+
@settings(max_examples=3)
127134
def test_decorator(self, tournament):
128135
self.assertIsInstance(tournament, axl.Tournament)
129136
self.assertLessEqual(tournament.prob_end, 1)
@@ -138,7 +145,7 @@ def test_decorator(self, tournament):
138145
strategies=axl.basic_strategies, max_size=3
139146
)
140147
)
141-
@settings(max_examples=5)
148+
@settings(max_examples=3)
142149
def test_decorator_with_given_strategies(self, tournament):
143150
self.assertIsInstance(tournament, axl.Tournament)
144151
basic_player_names = [str(s()) for s in axl.basic_strategies]
@@ -147,8 +154,9 @@ def test_decorator_with_given_strategies(self, tournament):
147154

148155

149156
class TestSpatialTournament(unittest.TestCase):
150-
def test_call(self):
151-
tournament = spatial_tournaments().example()
157+
@given(tournament=spatial_tournaments())
158+
@settings(max_examples=3)
159+
def test_call(self, tournament):
152160
self.assertIsInstance(tournament, axl.Tournament)
153161

154162
@given(
@@ -162,7 +170,7 @@ def test_call(self):
162170
max_size=3,
163171
)
164172
)
165-
@settings(max_examples=5)
173+
@settings(max_examples=3)
166174
def test_decorator(self, tournament):
167175
self.assertIsInstance(tournament, axl.Tournament)
168176
self.assertLessEqual(tournament.turns, 50)
@@ -177,7 +185,7 @@ def test_decorator(self, tournament):
177185
strategies=axl.basic_strategies, max_size=3
178186
)
179187
)
180-
@settings(max_examples=5)
188+
@settings(max_examples=3)
181189
def test_decorator_with_given_strategies(self, tournament):
182190
self.assertIsInstance(tournament, axl.Tournament)
183191
basic_player_names = [str(s()) for s in axl.basic_strategies]
@@ -186,8 +194,9 @@ def test_decorator_with_given_strategies(self, tournament):
186194

187195

188196
class TestProbEndSpatialTournament(unittest.TestCase):
189-
def test_call(self):
190-
tournament = prob_end_spatial_tournaments().example()
197+
@given(tournament=prob_end_spatial_tournaments())
198+
@settings(max_examples=3)
199+
def test_call(self, tournament):
191200
self.assertIsInstance(tournament, axl.Tournament)
192201

193202
@given(
@@ -201,7 +210,7 @@ def test_call(self):
201210
max_size=3,
202211
)
203212
)
204-
@settings(max_examples=5)
213+
@settings(max_examples=3)
205214
def test_decorator(self, tournament):
206215
self.assertIsInstance(tournament, axl.Tournament)
207216
self.assertLessEqual(tournament.prob_end, 1)
@@ -216,7 +225,7 @@ def test_decorator(self, tournament):
216225
strategies=axl.basic_strategies, max_size=3
217226
)
218227
)
219-
@settings(max_examples=5)
228+
@settings(max_examples=3)
220229
def test_decorator_with_given_strategies(self, tournament):
221230
self.assertIsInstance(tournament, axl.Tournament)
222231
basic_player_names = [str(s()) for s in axl.basic_strategies]
@@ -225,18 +234,19 @@ def test_decorator_with_given_strategies(self, tournament):
225234

226235

227236
class TestGame(unittest.TestCase):
228-
def test_call(self):
229-
game = games().example()
237+
@given(game=games())
238+
@settings(max_examples=3)
239+
def test_call(self, game):
230240
self.assertIsInstance(game, axl.Game)
231241

232242
@given(game=games())
233-
@settings(max_examples=5)
243+
@settings(max_examples=3)
234244
def test_decorator(self, game):
235245
self.assertIsInstance(game, axl.Game)
236246
r, p, s, t = game.RPST()
237247
self.assertTrue((2 * r) > (t + s) and (t > r > p > s))
238248

239249
@given(game=games(prisoners_dilemma=False))
240-
@settings(max_examples=5)
250+
@settings(max_examples=3)
241251
def test_decorator_unconstrained(self, game):
242252
self.assertIsInstance(game, axl.Game)

docs/requirements.txt

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1-
docutils>=0.18.1
2-
numpy==1.24.3 # numpy isn't mocked due to complex use in doctests
3-
mock>=5.1.0
1+
attrs==24.3.0
2+
cachetools==5.5.0
3+
chardet==5.2.0
4+
click==8.1.8
5+
cloudpickle==3.1.0
6+
colorama==0.4.6
7+
contourpy==1.3.1
8+
cycler==0.12.1
9+
dask==2024.12.1
10+
dask-expr==1.1.21
11+
distlib==0.3.9
12+
docutils==0.21.2
13+
filelock==3.16.1
14+
fonttools==4.55.3
15+
fsspec==2024.12.0
16+
hypothesis==6.123.4
17+
importlib_metadata==8.5.0
18+
iniconfig==2.0.0
19+
kiwisolver==1.4.8
20+
locket==1.0.0
21+
matplotlib==3.10.0
22+
mock==5.1.0
23+
numpy==1.24.3
24+
packaging==24.2
25+
pandas==2.2.3
26+
partd==1.4.2
27+
pillow==11.1.0
28+
platformdirs==4.3.6
29+
pluggy==1.5.0
30+
pyarrow==18.1.0
31+
pyparsing==3.2.1
32+
pyproject-api==1.8.0
33+
pytest==8.3.4
34+
python-dateutil==2.9.0.post0
35+
pytz==2024.2
36+
PyYAML==6.0.2
37+
scipy==1.15.0
38+
six==1.17.0
39+
sortedcontainers==2.4.0
40+
toolz==1.0.0
41+
tox==4.23.2
42+
tqdm==4.67.1
43+
tzdata==2024.2
44+
virtualenv==20.28.1
45+
zipp==3.21.0

tox.ini

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
11
[tox]
2+
# Enable isolated build to ensure compatibility
23
isolated_build = True
34
envlist = py311, py312
45

56
[gh-actions]
7+
# Map GitHub Actions Python versions to tox environments
68
python =
79
3.11: py311
810
3.12: py312
911

1012
[flake8]
13+
# Ignore specific rules for certain files
1114
per-file-ignores =
12-
setup.py: F821
13-
docs/_build/*: ALL
14-
docs/conf.py: E402
15-
**/__init__.py: F401 F403
15+
setup.py: F821 # Ignore undefined names in setup.py
16+
docs/_build/*: ALL # Ignore all issues in built documentation
17+
docs/conf.py: E402 # Allow imports not at the top of the file
18+
**/__init__.py: F401 F403 # Ignore unused imports and wildcard imports in __init__.py
19+
# Global ignores for flake8
1620
ignore =
17-
E203
18-
E501
19-
W291
20-
W503
21+
E203 # Whitespace before ':'
22+
E501 # Line length > 80
23+
W291 # Trailing whitespace
24+
W503 # Line break before binary operator
2125

2226
[testenv]
2327
deps =
2428
hypothesis
2529
pytest-cov
2630
pytest-randomly
2731
pytest-sugar
32+
pytest-xdist # Added for parallelizing tests
2833
isort
2934
black
3035
numpy==1.26.4
3136
commands =
32-
python -m pytest --cov-report term-missing --cov=axelrod --cov-fail-under=100 . --doctest-glob="*.md" --doctest-glob="*.rst"
37+
# Run tests in parallel using all available CPU cores
38+
python -m pytest -n auto --cov-report term-missing --cov=axelrod --cov-fail-under=100 . --doctest-glob="*.md" --doctest-glob="*.rst"
39+
40+
# Check code formatting with Black (no changes are made)
3341
python -m black -l 80 . --check
42+
43+
# Verify import sorting with isort
3444
python -m isort --check-only axelrod/.
45+
46+
# Run the strategy indexer script
3547
python run_strategy_indexer.py
48+

0 commit comments

Comments
 (0)