Skip to content

Instantly share code, notes, and snippets.

@embray
Created December 14, 2012 02:08
Show Gist options
  • Save embray/4281956 to your computer and use it in GitHub Desktop.
Save embray/4281956 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "Example Usage"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"%load_ext ipython_nose\n",
"# %reload_ext ipython_nose"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from nose import SkipTest\n",
"\n",
"def test_foo():\n",
" assert True\n",
" \n",
"def test_bar():\n",
" assert False\n",
" \n",
"def test_baz():\n",
" raise SkipTest(\"Skipped\")\n",
" \n",
"import random\n",
"import time\n",
"def test_generate():\n",
" for _ in range(random.randint(0, 10)):\n",
" time.sleep(0.25)\n",
" yield lambda x: None, _\n",
" def fail(x):\n",
" time.sleep(0.25)\n",
" raise AssertionError(\"Failed\")\n",
" for _ in range(random.randint(0, 10)):\n",
" yield fail, _\n",
" def skip(x):\n",
" time.sleep(0.25)\n",
" raise SkipTest(\"Skipped\")\n",
" for _ in range(random.randint(0, 10)):\n",
" yield skip, _"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%nose"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<div id=\"ipython_nose_16760aa7f08d4e66ab88e7f673b3248d\"></div>"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d = $(\"#ipython_nose_16760aa7f08d4e66ab88e7f673b3248d\");"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>F</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>S</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>.</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>F</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>F</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>S</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>S</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d.append($(\"<span>S</span>\"));"
],
"output_type": "display_data"
},
{
"javascript": [
"delete document.ipython_nose_16760aa7f08d4e66ab88e7f673b3248d;"
],
"output_type": "display_data"
},
{
"html": [
" <style type=\"text/css\">\n",
" span.nosefailedfunc {\n",
" font-family: monospace;\n",
" font-weight: bold;\n",
" }\n",
" div.noseresults {\n",
" width: 100%;\n",
" }\n",
" div.nosebar {\n",
" float: left;\n",
" padding: 1ex 0px 1ex 0px;\n",
" }\n",
" div.nosebar.fail {\n",
" background: #ff3019; /* Old browsers */\n",
" /* FF3.6+ */\n",
" background: -moz-linear-gradient(top, #ff3019 0%, #cf0404 100%);\n",
" /* Chrome,Safari4+ */\n",
" background: -webkit-gradient(linear, left top, left bottom,\n",
" color-stop(0%,#ff3019),\n",
" color-stop(100%,#cf0404));\n",
" /* Chrome10+,Safari5.1+ */\n",
" background: -webkit-linear-gradient(top, #ff3019 0%,#cf0404 100%);\n",
" /* Opera 11.10+ */\n",
" background: -o-linear-gradient(top, #ff3019 0%,#cf0404 100%);\n",
" /* IE10+ */\n",
" background: -ms-linear-gradient(top, #ff3019 0%,#cf0404 100%);\n",
" /* W3C */\n",
" background: linear-gradient(to bottom, #ff3019 0%,#cf0404 100%);\n",
" }\n",
" div.nosebar.pass {\n",
" background: #52b152;\n",
" background: -moz-linear-gradient(top, #52b152 1%, #008a00 100%);\n",
" background: -webkit-gradient(linear, left top, left bottom,\n",
" color-stop(1%,#52b152),\n",
" color-stop(100%,#008a00));\n",
" background: -webkit-linear-gradient(top, #52b152 1%,#008a00 100%);\n",
" background: -o-linear-gradient(top, #52b152 1%,#008a00 100%);\n",
" background: -ms-linear-gradient(top, #52b152 1%,#008a00 100%);\n",
" background: linear-gradient(to bottom, #52b152 1%,#008a00 100%);\n",
" }\n",
" div.nosebar.skip {\n",
" background: #f1e767;\n",
" background: -moz-linear-gradient(top, #f1e767 0%, #feb645 100%);\n",
" background: -webkit-gradient(linear, left top, left bottom,\n",
" color-stop(0%,#f1e767),\n",
" color-stop(100%,#feb645));\n",
" background: -webkit-linear-gradient(top, #f1e767 0%,#feb645 100%);\n",
" background: -o-linear-gradient(top, #f1e767 0%,#feb645 100%);\n",
" background: -ms-linear-gradient(top, #f1e767 0%,#feb645 100%);\n",
" background: linear-gradient(to bottom, #f1e767 0%,#feb645 100%);\n",
" }\n",
" div.nosebar.leftmost {\n",
" border-radius: 4px 0 0 4px;\n",
" }\n",
" div.nosebar.rightmost {\n",
" border-radius: 0 4px 4px 0;\n",
" }\n",
" div.nosefailbanner {\n",
" border-radius: 4px 0 0 4px;\n",
" border-left: 10px solid #cf0404;\n",
" padding: 0.5ex 0em 0.5ex 1em;\n",
" margin-top: 1ex;\n",
" margin-bottom: 0px;\n",
" }\n",
" div.nosefailbanner.expanded {\n",
" border-radius: 4px 4px 0 0;\n",
" border-top: 10px solid #cf0404;\n",
" }\n",
" pre.nosetraceback {\n",
" border-radius: 0 4px 4px 4px;\n",
" border-left: 10px solid #cf0404;\n",
" padding: 1em;\n",
" margin-left: 0px;\n",
" margin-top: 0px;\n",
" display: none;\n",
" }\n",
" </style>\n",
" \n",
" <script>\n",
" setTimeout(function () {\n",
" $('.nosefailtoggle').bind(\n",
" 'click',\n",
" function () {\n",
" $(\n",
" $(this)\n",
" .parent().toggleClass('expanded')\n",
" .parent()\n",
" .children()\n",
" .filter('.nosetraceback')\n",
" ).toggle();\n",
" }\n",
" );},\n",
" 0);\n",
" </script>\n",
" \n",
" <div class=\"noseresults\">\n",
" <div class=\"nosebar fail leftmost\" style=\"width: 16%\">&nbsp;</div>\n",
" <div class=\"nosebar skip\" style=\"width: 22%\">&nbsp;</div>\n",
" <div class=\"nosebar pass rightmost\" style=\"width: 62%\">&nbsp;</div>\n",
" 15/18 tests passed; 3 failed; 4 skipped\n",
" </div>\n",
" \n",
" <div class=\"nosefailure\">\n",
" <div class=\"nosefailbanner\">\n",
" failed: <span class=\"nosefailedfunc\">__main__.test_bar</span>\n",
" [<a class=\"nosefailtoggle\" href=\"#\">toggle traceback</a>]\n",
" </div>\n",
" <pre class=\"nosetraceback\">Traceback (most recent call last):\n",
" File \"/bray/sc1/root/lib/python2.7/unittest/case.py\", line 318, in run\n",
" testMethod()\n",
" File \"/bray/sc1/root/lib/python2.7/site-packages/nose/case.py\", line 197, in runTest\n",
" self.test(*self.arg)\n",
" File \"&lt;<a href=\"#ipython-input-2-dba9827c77f1\">ipython-input-2-dba9827c77f1</a><script>\n",
" $(\"div.prompt.input_prompt:contains([2])\")\n",
" .attr(\"id\", \"ipython-input-2-dba9827c77f1\");\n",
" </script>&gt;\", line 7, in test_bar\n",
" assert False\n",
"AssertionError\n",
"</pre>\n",
" </div>\n",
" \n",
" <div class=\"nosefailure\">\n",
" <div class=\"nosefailbanner\">\n",
" failed: <span class=\"nosefailedfunc\">__main__.test_generate(0,)</span>\n",
" [<a class=\"nosefailtoggle\" href=\"#\">toggle traceback</a>]\n",
" </div>\n",
" <pre class=\"nosetraceback\">Traceback (most recent call last):\n",
" File \"/bray/sc1/root/lib/python2.7/unittest/case.py\", line 318, in run\n",
" testMethod()\n",
" File \"/bray/sc1/root/lib/python2.7/site-packages/nose/case.py\", line 197, in runTest\n",
" self.test(*self.arg)\n",
" File \"&lt;<a href=\"#ipython-input-2-dba9827c77f1\">ipython-input-2-dba9827c77f1</a><script>\n",
" $(\"div.prompt.input_prompt:contains([2])\")\n",
" .attr(\"id\", \"ipython-input-2-dba9827c77f1\");\n",
" </script>&gt;\", line 20, in fail\n",
" raise AssertionError(\"Failed\")\n",
"AssertionError: Failed\n",
"</pre>\n",
" </div>\n",
" \n",
" <div class=\"nosefailure\">\n",
" <div class=\"nosefailbanner\">\n",
" failed: <span class=\"nosefailedfunc\">__main__.test_generate(1,)</span>\n",
" [<a class=\"nosefailtoggle\" href=\"#\">toggle traceback</a>]\n",
" </div>\n",
" <pre class=\"nosetraceback\">Traceback (most recent call last):\n",
" File \"/bray/sc1/root/lib/python2.7/unittest/case.py\", line 318, in run\n",
" testMethod()\n",
" File \"/bray/sc1/root/lib/python2.7/site-packages/nose/case.py\", line 197, in runTest\n",
" self.test(*self.arg)\n",
" File \"&lt;<a href=\"#ipython-input-2-dba9827c77f1\">ipython-input-2-dba9827c77f1</a><script>\n",
" $(\"div.prompt.input_prompt:contains([2])\")\n",
" .attr(\"id\", \"ipython-input-2-dba9827c77f1\");\n",
" </script>&gt;\", line 20, in fail\n",
" raise AssertionError(\"Failed\")\n",
"AssertionError: Failed\n",
"</pre>\n",
" </div>\n",
" "
],
"output_type": "pyout",
"prompt_number": 3,
"text": [
"15/18 tests passed; 3 failed; 4 skipped\n",
"========\n",
"__main__.test_bar\n",
"========\n",
"Traceback (most recent call last):\n",
" File \"/bray/sc1/root/lib/python2.7/unittest/case.py\", line 318, in run\n",
" testMethod()\n",
" File \"/bray/sc1/root/lib/python2.7/site-packages/nose/case.py\", line 197, in runTest\n",
" self.test(*self.arg)\n",
" File \"<ipython-input-2-dba9827c77f1>\", line 7, in test_bar\n",
" assert False\n",
"AssertionError\n",
"\n",
"========\n",
"__main__.test_generate(0,)\n",
"========\n",
"Traceback (most recent call last):\n",
" File \"/bray/sc1/root/lib/python2.7/unittest/case.py\", line 318, in run\n",
" testMethod()\n",
" File \"/bray/sc1/root/lib/python2.7/site-packages/nose/case.py\", line 197, in runTest\n",
" self.test(*self.arg)\n",
" File \"<ipython-input-2-dba9827c77f1>\", line 20, in fail\n",
" raise AssertionError(\"Failed\")\n",
"AssertionError: Failed\n",
"\n",
"========\n",
"__main__.test_generate(1,)\n",
"========\n",
"Traceback (most recent call last):\n",
" File \"/bray/sc1/root/lib/python2.7/unittest/case.py\", line 318, in run\n",
" testMethod()\n",
" File \"/bray/sc1/root/lib/python2.7/site-packages/nose/case.py\", line 197, in runTest\n",
" self.test(*self.arg)\n",
" File \"<ipython-input-2-dba9827c77f1>\", line 20, in fail\n",
" raise AssertionError(\"Failed\")\n",
"AssertionError: Failed\n",
"\n"
]
}
],
"prompt_number": 3
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment