Skip to content

Commit d9ee722

Browse files
authored
Merge pull request #980 from Axelrod-Python/957
Add strategy index test to travis.
2 parents dc72d0e + d415f1a commit d9ee722

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ script:
3030
- python doctests.py
3131
# Run the type checker
3232
- python run_mypy.py
33+
# Check that all strategies are in the index
34+
- python run_strategy_indexer.py
3335
after_success:
3436
- coveralls
3537
notifications:

docs/reference/all_strategies.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Here are the docstrings of all the strategies in the library.
8181
.. automodule:: axelrod.strategies.handshake
8282
:members:
8383
:undoc-members:
84+
.. automodule:: axelrod.strategies.hmm
85+
:members:
86+
:undoc-members:
8487
.. automodule:: axelrod.strategies.hunter
8588
:members:
8689
:undoc-members:
@@ -93,6 +96,9 @@ Here are the docstrings of all the strategies in the library.
9396
.. automodule:: axelrod.strategies.mathematicalconstants
9497
:members:
9598
:undoc-members:
99+
.. automodule:: axelrod.strategies.memorytwo
100+
:members:
101+
:undoc-members:
96102
.. automodule:: axelrod.strategies.memoryone
97103
:members:
98104
:undoc-members:

run_mypy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import subprocess
22
import sys
3-
modules = ["axelrod/actions.py",
3+
modules = ["run_strategy_indexer.py",
4+
"axelrod/actions.py",
45
"axelrod/deterministic_cache.py",
56
"axelrod/ecosystem.py",
67
"axelrod/game.py",

run_strategy_indexer.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
A script to check that all strategy modules have been included in
3+
`./docs/reference/all_strategies.rst`
4+
"""
5+
import sys
6+
import pathlib
7+
8+
default_index_path = pathlib.Path("./docs/reference/all_strategies.rst")
9+
excluded_modules = ("_strategies", "__init__", "_filters", "human")
10+
11+
def check_module(module_path: pathlib.Path,
12+
index_path: pathlib.Path=default_index_path,
13+
excluded: tuple=excluded_modules) -> bool:
14+
"""
15+
Check if a module name is written in the index of strategies.
16+
17+
Parameters
18+
----------
19+
module_path :
20+
A file path for a module file.
21+
index_path :
22+
A file path for the index file where all strategies are auto documented
23+
excluded :
24+
A collection of module names to be ignored
25+
26+
Returns
27+
-------
28+
boolean :
29+
True/False if module is referenced.
30+
31+
"""
32+
strategies_index = index_path.read_text()
33+
module_name = module_path.stem
34+
if module_name not in excluded and module_name not in strategies_index:
35+
print("{} not in index".format(module_name))
36+
return False
37+
return True
38+
39+
40+
if __name__ == "__main__":
41+
42+
p = pathlib.Path('.')
43+
modules = p.glob("./axelrod/strategies/*.py")
44+
exit_codes = []
45+
46+
for module_path in modules:
47+
exit_codes.append(int(not check_module(module_path)))
48+
49+
sys.exit(max(exit_codes))

0 commit comments

Comments
 (0)