Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Forked from anonymous/Untitled34.ipynb
Last active February 10, 2018 16:06
Show Gist options
  • Save tonyfast/57c1b38d42144450fca278f932b6786f to your computer and use it in GitHub Desktop.
Save tonyfast/57c1b38d42144450fca278f932b6786f to your computer and use it in GitHub Desktop.
Behavior driven development in the notebook.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "%reload_ext XXX.mumble",
"execution_count": 1,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<IPython.core.display.HTML object>",
"text/html": "<style>\n @import url(\"https://cdn.jsdelivr.net/npm/[email protected]/distr/fira_code.css\");\n\n pre code, \n div.output_area pre, \n .CodeMirror * {\n font-family: 'Fira Code' !important; \n font-variant-ligatures: initial !important;\n }\n\n .cm-string {\n font-variant-ligatures: none;\n }\n</style>\n"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": " \n ---\n ˣ:\n behave: https://github.com/behave/behave\n docs: https://pythonhosted.org/behave\n bdd: https://en.wikipedia.org/wiki/Behavior-driven_development \n ff: https://cucumber.io/docs/reference",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Making the notebook `behave`\n\n[`behave`](ˣ.behave) is a python library for [Behavior Driven Development](ˣ.bdd), it seems like a reasonable \ntool for folks to experience writing tests without knowing code.",
"execution_count": 3,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<IPython.core.display.Markdown object>",
"text/markdown": "# Making the notebook `behave`\n\n[`behave`](ˣ.behave) is a python library for [Behavior Driven Development](ˣ.bdd), it seems like a reasonable \ntool for folks to experience writing tests without knowing code."
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "## Feature Files\n\n[Feature files](ˣ.ff) define steps or actions in [behavior driven development](ˣ.bdd). The \n`feature_file` string below is an example the [`behave` docs](ˣ.docs) \n\n feature_file = \"\"\"\n Feature: Showing off behave\n\n Scenario: Run a simple test\n Given we have behave installed\n When we implement 5 tests\n Then behave will test them for us!\n \"\"\".strip()",
"execution_count": 4,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<IPython.core.display.Markdown object>",
"text/markdown": "## Feature Files\n\n[Feature files](ˣ.ff) define steps or actions in [behavior driven development](ˣ.bdd). The \n`feature_file` string below is an example the [`behave` docs](ˣ.docs) \n\n feature_file = \"\"\"\n Feature: Showing off behave\n\n Scenario: Run a simple test\n Given we have behave installed\n When we implement 5 tests\n Then behave will test them for us!\n \"\"\".strip()"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "## Pythonic feature descriptions\n\nAgain ripped from [the docs](ˣ.docs), the lines following define features that correspond\nto lines in `feature_file`.\n\n from behave import given, when, then, step, runner, configuration, parser\n\n @given('we have behave installed')\n def step_impl(context):\n pass\n\n @when('we implement {number:d} tests')\n def step_impl(context, number): # -- NOTE: number is converted into integer\n assert number > 1 or number == 0\n context.tests_count = number\n\n @then('behave will test them for us!')\n def step_impl(context):\n assert context.failed is False\n assert context.tests_count >= 0",
"execution_count": 5,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<IPython.core.display.Markdown object>",
"text/markdown": "## Pythonic feature descriptions\n\nAgain ripped from [the docs](ˣ.docs), the lines following define features that correspond\nto lines in `feature_file`.\n\n from behave import given, when, then, step, runner, configuration, parser\n\n @given('we have behave installed')\n def step_impl(context):\n pass\n\n @when('we implement {number:d} tests')\n def step_impl(context, number): # -- NOTE: number is converted into integer\n assert number > 1 or number == 0\n context.tests_count = number\n\n @then('behave will test them for us!')\n def step_impl(context):\n assert context.failed is False\n assert context.tests_count >= 0"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "## Making `behave` work in a running IPython context.\n\nParse the features of `feature_file` using the `behave.parser`\n\n features = [parser.parse_feature(feature_file)]\n \nUse the default configuration to initialize our `Runner`\n \n config = configuration.Configuration(tuple()) # force the argv values .\n \n## Run the tests\n\nRun the tests in a running IPython context.\n\n Runner = runner.ModelRunner(config=config, features=features).run()",
"execution_count": 11,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<IPython.core.display.Markdown object>",
"text/markdown": "## Making `behave` work in a running IPython context.\n\nParse the features of `feature_file` using the `behave.parser`\n\n features = [parser.parse_feature(feature_file)]\n \nUse the default configuration to initialize our `Runner`\n \n config = configuration.Configuration(tuple()) # force the argv values .\n \n## Run the tests\n\nRun the tests in a running IPython context.\n\n Runner = runner.ModelRunner(config=config, features=features).run()"
},
"metadata": {}
},
{
"output_type": "stream",
"text": "1 feature passed, 0 failed, 0 skipped\n1 scenario passed, 0 failed, 0 skipped\n3 steps passed, 0 failed, 0 skipped, 0 undefined\nTook 0m0.000s\n",
"name": "stdout"
}
]
}
],
"metadata": {
"kernelspec": {
"name": "other-env",
"display_name": "p6",
"language": "python"
},
"varInspector": {
"window_display": false,
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"library": "var_list.py",
"delete_cmd_prefix": "del ",
"delete_cmd_postfix": "",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"library": "var_list.r",
"delete_cmd_prefix": "rm(",
"delete_cmd_postfix": ") ",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
]
},
"toc": {
"threshold": 4,
"number_sections": true,
"toc_cell": false,
"toc_window_display": true,
"toc_section_display": "block",
"sideBar": true,
"navigate_menu": true,
"moveMenuLeft": true,
"widenNotebook": false,
"colors": {
"hover_highlight": "#DAA520",
"selected_highlight": "#FFD700",
"running_highlight": "#FF0000"
},
"nav_menu": {
"width": "250px",
"height": "77px"
}
},
"language_info": {
"name": "python",
"version": "3.6.3",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "Untitled34.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment