Skip to content

Commit 532452f

Browse files
authored
Merge pull request #12 from Axelrod-Python/add-tests
Add tests
2 parents 586f5cd + 4f3eef5 commit 532452f

9 files changed

+122
-877
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: python
2+
python:
3+
- 3.5
4+
- 3.6
5+
before_install:
6+
- export DISPLAY=:99.0
7+
- sh -e /etc/init.d/xvfb start
8+
install:
9+
- pip install -r requirements.txt
10+
script:
11+
- python nbtests.py

Cooperation vs score.ipynb

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

Moran Process.ipynb renamed to Moran-Process.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@
188188
}
189189
],
190190
"metadata": {
191+
"anaconda-cloud": {},
191192
"kernelspec": {
192-
"display_name": "Python 3",
193+
"display_name": "Python [default]",
193194
"language": "python",
194195
"name": "python3"
195196
},
@@ -203,7 +204,7 @@
203204
"name": "python",
204205
"nbconvert_exporter": "python",
205206
"pygments_lexer": "ipython3",
206-
"version": "3.5.3"
207+
"version": "3.5.2"
207208
}
208209
},
209210
"nbformat": 4,

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
A repository of Jupyter notebooks using the Axelrod project. Download, modify, and contribute your own notebooks!
1+
A repository of Jupyter notebooks using the Axelrod project.
2+
Download, modify, and contribute your own notebooks!
23

34
Currently we have notebooks for the following:
45

56
* [Basic Example Tournaments](basic-tournament.ipynb)
67
* [Noisy Tournaments](basic-noisy-tournament.ipynb)
78
* [Using Axelrod matches](Matches.ipynb)
8-
* [The Moran Process](Moran Process.ipynb)
9+
* [The Moran Process](Moran-Process.ipynb)
10+
* [Spatial tournaments on a lattice](Spatia-Lattice-Structured-Example.ipynb)
11+
* [Spatial tournaments on a cycle](Spatia-Circle-Structured-Example.ipynb)
12+
* [Code to recreate the Axelrod logo](Logo.ipynb)
13+
14+
The `./untested/` dir contains notebooks that are not tested by the
15+
`./nbtests.py` script.

Spatia-Circle-Structured-Example.ipynb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"cell_type": "code",
5858
"execution_count": 15,
5959
"metadata": {
60-
"collapsed": false
60+
"collapsed": true
6161
},
6262
"outputs": [],
6363
"source": [
@@ -68,7 +68,6 @@
6868
"cell_type": "code",
6969
"execution_count": 16,
7070
"metadata": {
71-
"collapsed": false,
7271
"scrolled": true
7372
},
7473
"outputs": [
@@ -105,9 +104,7 @@
105104
{
106105
"cell_type": "code",
107106
"execution_count": 17,
108-
"metadata": {
109-
"collapsed": false
110-
},
107+
"metadata": {},
111108
"outputs": [
112109
{
113110
"name": "stderr",
@@ -117,16 +114,14 @@
117114
],
118115
"source": [
119116
"edges = G.edges()\n",
120-
"tournament = axl.SpatialTournament(players, edges=G.edges(), repetitions=1)\n",
117+
"tournament = axl.Tournament(players, edges=G.edges(), repetitions=1)\n",
121118
"results = tournament.play(processes=1)"
122119
]
123120
},
124121
{
125122
"cell_type": "code",
126123
"execution_count": 18,
127-
"metadata": {
128-
"collapsed": false
129-
},
124+
"metadata": {},
130125
"outputs": [
131126
{
132127
"data": {
@@ -155,9 +150,7 @@
155150
{
156151
"cell_type": "code",
157152
"execution_count": 19,
158-
"metadata": {
159-
"collapsed": false
160-
},
153+
"metadata": {},
161154
"outputs": [
162155
{
163156
"data": {
@@ -177,8 +170,9 @@
177170
}
178171
],
179172
"metadata": {
173+
"anaconda-cloud": {},
180174
"kernelspec": {
181-
"display_name": "Python 3",
175+
"display_name": "Python [default]",
182176
"language": "python",
183177
"name": "python3"
184178
},
@@ -192,9 +186,9 @@
192186
"name": "python",
193187
"nbconvert_exporter": "python",
194188
"pygments_lexer": "ipython3",
195-
"version": "3.5.1+"
189+
"version": "3.5.2"
196190
}
197191
},
198192
"nbformat": 4,
199-
"nbformat_minor": 0
193+
"nbformat_minor": 1
200194
}

Spatia-Lattice-Structured-Example.ipynb

Lines changed: 49 additions & 43 deletions
Large diffs are not rendered by default.

nbtests.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Script to test all notebooks execute without errors
3+
"""
4+
import nbformat
5+
import pathlib
6+
from nbconvert.preprocessors import ExecutePreprocessor
7+
8+
def retrieve_errors(nb_path):
9+
"""
10+
Find all errors that occur when running a nb
11+
"""
12+
13+
with nb_path.open() as f:
14+
nb = nbformat.read(f, as_version=4)
15+
16+
ep = ExecutePreprocessor(timeout=600, kernel_name='python3',
17+
allow_errors=True)
18+
out, _ = ep.preprocess(nb, {'metadata': {'path': '.'}})
19+
errors = []
20+
for cell in out.cells:
21+
if "outputs" in cell:
22+
for output in cell["outputs"]:
23+
if output.output_type == "error":
24+
errors.append(output.evalue)
25+
return errors
26+
27+
if __name__ == "__main__":
28+
29+
nb_dir = pathlib.Path('.')
30+
nbs = nb_dir.glob("*.ipynb")
31+
32+
for path in nbs:
33+
print("Testing: {}".format(path.stem))
34+
errors = retrieve_errors(path)
35+
assert errors == [], errors

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
axelrod
2+
networkx
3+
jupyter
4+
pillow
5+
pandas
6+
seaborn
File renamed without changes.

0 commit comments

Comments
 (0)