Skip to content

Commit 2c372c7

Browse files
author
Craig Dennis
authored
Merge pull request #1 from treehouse-projects/challenges
Challenges
2 parents b152b86 + f8befe5 commit 2c372c7

6 files changed

+90
-30
lines changed

binder/environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ dependencies:
55
- numpy=1.15.0
66
- pandas=0.23.4
77
- python=3.7.0
8+
- ipywidgets
89
- faker
910

requirements.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ backcall=0.1.0=py37_0
1010
blas=1.0=mkl
1111
bleach=2.1.3=py37_0
1212
ca-certificates=2018.03.07=0
13-
certifi=2018.8.24=py37_1
13+
certifi=2018.10.15=py37_0
1414
cffi=1.11.5=py37h342bebf_0
1515
constantly=15.1.0=py37h28b3542_0
16-
cryptography=2.3=py37hdbc3d79_0
16+
cryptography=2.3.1=py37ha12b0ac_2
1717
cryptography-vectors=2.3=py37_0
1818
dbus=1.13.2=h760590f_1
1919
decorator=4.3.0=py37_0
@@ -31,7 +31,7 @@ intel-openmp=2018.0.3=0
3131
ipykernel=4.8.2=py37_0
3232
ipython=6.5.0=py37_0
3333
ipython_genutils=0.2.0=py37_0
34-
ipywidgets=7.4.0=py37_0
34+
ipywidgets=7.4.2=py37_0
3535
jedi=0.12.1=py37_0
3636
jinja2=2.10=py37_0
3737
jpeg=9b=he5867d9_2
@@ -59,7 +59,7 @@ ncurses=6.1=h0a44026_0
5959
notebook=5.6.0=py37_0
6060
numpy=1.15.0=py37h648b28d_0
6161
numpy-base=1.15.0=py37h8a80b8c_0
62-
openssl=1.0.2p=h1de35cc_0
62+
openssl=1.1.1=h1de35cc_0
6363
pandas=0.23.4=py37h6440ff4_0
6464
pandoc=2.2.1=h1a437c5_0
6565
pandocfilters=1.4.2=py37_1
@@ -77,7 +77,7 @@ pycparser=2.18=py37_1
7777
pygments=2.2.0=py37_0
7878
pyopenssl=18.0.0=py37_0
7979
pyqt=5.9.2=py37h655552a_0
80-
python=3.7.0=hc167b69_0
80+
python=3.7.1=haf84260_3
8181
python-dateutil=2.7.3=py37_0
8282
pytz=2018.5=py37_0
8383
pyzmq=17.1.2=py37h1de35cc_0
@@ -90,11 +90,11 @@ setuptools=40.0.0=py37_0
9090
simplegeneric=0.8.1=py37_2
9191
sip=4.19.8=py37h0a44026_0
9292
six=1.11.0=py37_1
93-
sqlite=3.24.0=ha441bb4_0
93+
sqlite=3.25.2=ha441bb4_0
9494
terminado=0.8.1=py37_1
9595
testpath=0.3.1=py37_0
9696
text-unidecode=1.2=py37_0
97-
tk=8.6.7=h35a86e2_3
97+
tk=8.6.8=ha441bb4_0
9898
tornado=5.1=py37h1de35cc_0
9999
traitlets=4.3.2=py37_0
100100
twisted=18.7.0=py37h1de35cc_1

s2n03-challenge1-top-referrers.ipynb

+26-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"\n",
1111
"Currently, anyone with **5 or more** referrals is considered a top referrer.\n",
1212
"\n",
13-
"In the cell labelled CHALLENGE, follow the instructions to return what is required. Use `Kernel > Restart and run all cells` to check your work. If all the tests pass, you got it!"
13+
"When you have completed the challenge, press the `Run Tests` button.\n",
14+
"\n",
15+
"*Need a little extra help? Check out the [Treehouse Forum](https://teamtreehouse.com/community?instruction=4552).*"
1416
]
1517
},
1618
{
@@ -241,6 +243,20 @@
241243
"execution_count": 3,
242244
"metadata": {},
243245
"outputs": [
246+
{
247+
"data": {
248+
"application/vnd.jupyter.widget-view+json": {
249+
"model_id": "3173395f5f7e4c1dacc395df45c550f1",
250+
"version_major": 2,
251+
"version_minor": 0
252+
},
253+
"text/plain": [
254+
"Button(description='Run Tests', style=ButtonStyle())"
255+
]
256+
},
257+
"metadata": {},
258+
"output_type": "display_data"
259+
},
244260
{
245261
"data": {
246262
"text/markdown": [
@@ -271,7 +287,7 @@
271287
"AssertionError: 475 != 142 : Whoops I received a different count than I expected, make sure the last line is the entire resulting DataFrame (not just the head)\n",
272288
"\n",
273289
"----------------------------------------------------------------------\n",
274-
"Ran 3 tests in 0.005s\n",
290+
"Ran 3 tests in 0.006s\n",
275291
"\n",
276292
"FAILED (failures=3)\n",
277293
"\n",
@@ -288,6 +304,13 @@
288304
"source": [
289305
"check(__name__, 'Find the top referrers')"
290306
]
307+
},
308+
{
309+
"cell_type": "code",
310+
"execution_count": null,
311+
"metadata": {},
312+
"outputs": [],
313+
"source": []
291314
}
292315
],
293316
"metadata": {
@@ -306,7 +329,7 @@
306329
"name": "python",
307330
"nbconvert_exporter": "python",
308331
"pygments_lexer": "ipython3",
309-
"version": "3.7.0"
332+
"version": "3.7.1"
310333
}
311334
},
312335
"nbformat": 4,

s2n05-challenge2-update-user.ipynb

+24-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"\n",
1313
"There are a couple ways to make this change happen, let's see what you can figure out!\n",
1414
"\n",
15-
"After you've completed the TODO's choose `Kernel > Restart and Run all Cells` to see your results!\n"
15+
"After you've completed the TODO's click the `Run Tests` button\n",
16+
"\n",
17+
"*Need a little extra help? Check out the [Treehouse Forum](https://teamtreehouse.com/community?instruction=4572).*"
1618
]
1719
},
1820
{
@@ -44,13 +46,6 @@
4446
"len(users)"
4547
]
4648
},
47-
{
48-
"cell_type": "code",
49-
"execution_count": null,
50-
"metadata": {},
51-
"outputs": [],
52-
"source": []
53-
},
5449
{
5550
"cell_type": "code",
5651
"execution_count": 2,
@@ -120,8 +115,8 @@
120115
" <tr>\n",
121116
" <th>adrian</th>\n",
122117
" <td>Adrian</td>\n",
123-
" <td>Yang</td>\n",
124-
" <td>adrian.yang@teamtreehouse.com</td>\n",
118+
" <td>Fang</td>\n",
119+
" <td>adrian.fang@teamtreehouse.com</td>\n",
125120
" <td>True</td>\n",
126121
" <td>2018-04-28</td>\n",
127122
" <td>3</td>\n",
@@ -207,7 +202,7 @@
207202
"aaron Aaron Davis [email protected] \n",
208203
"acook Anthony Cook [email protected] \n",
209204
"adam.saunders Adam Saunders [email protected] \n",
210-
"adrian Adrian Yang adrian.yang@teamtreehouse.com \n",
205+
"adrian Adrian Fang adrian.fang@teamtreehouse.com \n",
211206
"adrian.blair Adrian Blair [email protected] \n",
212207
"... ... ... ... \n",
213208
"wilson Robert Wilson [email protected] \n",
@@ -253,6 +248,20 @@
253248
"execution_count": 3,
254249
"metadata": {},
255250
"outputs": [
251+
{
252+
"data": {
253+
"application/vnd.jupyter.widget-view+json": {
254+
"model_id": "ca87e33565ed41e39c1d89da5125f6cc",
255+
"version_major": 2,
256+
"version_minor": 0
257+
},
258+
"text/plain": [
259+
"Button(description='Run Tests', style=ButtonStyle())"
260+
]
261+
},
262+
"metadata": {},
263+
"output_type": "display_data"
264+
},
256265
{
257266
"data": {
258267
"text/markdown": [
@@ -262,20 +271,20 @@
262271
"FAIL: test_jeffrey_with_one_f (tests.helpers.TestUpdateUsers)\n",
263272
"----------------------------------------------------------------------\n",
264273
"Traceback (most recent call last):\n",
265-
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 52, in test_jeffrey_with_one_f\n",
274+
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 56, in test_jeffrey_with_one_f\n",
266275
" 'Did you rename the username jeffrey to jefrey?'\n",
267276
"AssertionError: False is not true : Did you rename the username jeffrey to jefrey?\n",
268277
"\n",
269278
"======================================================================\n",
270279
"FAIL: test_kim_deal (tests.helpers.TestUpdateUsers)\n",
271280
"----------------------------------------------------------------------\n",
272281
"Traceback (most recent call last):\n",
273-
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 46, in test_kim_deal\n",
282+
" File \"/Users/craig/Code/scripting/intro-to-pandas/tests/test_cells.py\", line 50, in test_kim_deal\n",
274283
" 'Are you sure you updated the last name of [email protected] to \"Deal\"?'\n",
275284
"AssertionError: nan != 'Deal' : Are you sure you updated the last name of [email protected] to \"Deal\"?\n",
276285
"\n",
277286
"----------------------------------------------------------------------\n",
278-
"Ran 2 tests in 0.002s\n",
287+
"Ran 2 tests in 0.003s\n",
279288
"\n",
280289
"FAILED (failures=2)\n",
281290
"\n",
@@ -310,7 +319,7 @@
310319
"name": "python",
311320
"nbconvert_exporter": "python",
312321
"pygments_lexer": "ipython3",
313-
"version": "3.7.0"
322+
"version": "3.7.1"
314323
}
315324
},
316325
"nbformat": 4,

s2n09-challenge3-verified-email-list.ipynb

+19-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"\n",
1414
"Ensure that all first names are title cased. Do not include any records that have a missing last name, and make sure that their email is verified (**`email_verified`** should be set True). Sort by last name and then by first.\n",
1515
"\n",
16-
"Choose `Kernel > Restart & Run all` to run the tests properly. \n"
16+
"Once you have completed the TODOs, choose the `Run Tests` button.\n",
17+
"\n",
18+
"*Need a little extra help? Check out the [Treehouse Forum](https://teamtreehouse.com/community?instruction=4573).*\n"
1719
]
1820
},
1921
{
@@ -245,6 +247,20 @@
245247
"execution_count": 3,
246248
"metadata": {},
247249
"outputs": [
250+
{
251+
"data": {
252+
"application/vnd.jupyter.widget-view+json": {
253+
"model_id": "9979fc1830b443128f18c18c4cc5f59f",
254+
"version_major": 2,
255+
"version_minor": 0
256+
},
257+
"text/plain": [
258+
"Button(description='Run Tests', style=ButtonStyle())"
259+
]
260+
},
261+
"metadata": {},
262+
"output_type": "display_data"
263+
},
248264
{
249265
"data": {
250266
"text/markdown": [
@@ -294,7 +310,7 @@
294310
"AssertionError: 19 != 0 : Make sure you title case the first names, there are still some lower case versions\n",
295311
"\n",
296312
"----------------------------------------------------------------------\n",
297-
"Ran 5 tests in 0.034s\n",
313+
"Ran 5 tests in 0.033s\n",
298314
"\n",
299315
"FAILED (failures=5)\n",
300316
"\n",
@@ -329,7 +345,7 @@
329345
"name": "python",
330346
"nbconvert_exporter": "python",
331347
"pygments_lexer": "ipython3",
332-
"version": "3.7.0"
348+
"version": "3.7.1"
333349
}
334350
},
335351
"nbformat": 4,

tests/helpers.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import sys
55
import unittest
66

7-
from IPython.display import display, Markdown
7+
from IPython.display import display, Markdown, Javascript
8+
import ipywidgets as widgets
89

910

1011
registered_tests = {}
@@ -23,9 +24,13 @@ def wrapped(cls):
2324
def cell_matching(module, test_text):
2425
# In is a list of notebook cell inputs
2526
# Out is a dictionary of cell outputs
27+
matching_indices = []
2628
for index, value in enumerate(module.In):
2729
if test_text in value:
28-
return Cell(value, module.Out.get(index))
30+
matching_indices.append(index)
31+
if matching_indices:
32+
# The last entry is the call to `check`
33+
return Cell(value, module.Out.get(matching_indices[-2]))
2934
return None, None
3035

3136

@@ -43,6 +48,9 @@ class BoundTestClass(test_cls):
4348
BoundTestClass.__doc__ = "Cell Tests for " + test_text
4449
return BoundTestClass
4550

51+
def execute_all_cells(b):
52+
display(Javascript('''IPython.notebook.execute_all_cells();'''))
53+
4654

4755
def check(module_name, test_text):
4856
module = sys.modules[module_name]
@@ -51,4 +59,7 @@ def check(module_name, test_text):
5159
runner = unittest.TextTestRunner(stream=output_stream)
5260
runner.run(unittest.defaultTestLoader.loadTestsFromTestCase(test_class))
5361
md = '```\n' + output_stream.getvalue() + '\n```'
62+
button = widgets.Button(description='Run Tests')
63+
button.on_click(execute_all_cells)
64+
display(button)
5465
display(Markdown(md))

0 commit comments

Comments
 (0)