Commit 2f1f33c5 authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

doctest

parent 81329bf0
...@@ -149,6 +149,27 @@ ...@@ -149,6 +149,27 @@
"\n" "\n"
] ]
}, },
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"function"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f = lambda x: x * x\n",
"type(f)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 41,
...@@ -300,12 +321,12 @@ ...@@ -300,12 +321,12 @@
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 2.4.2\n", "### 2.4.2\n",
"Dada una lista *a*, utilizando una comprensión, imprimir una lista de tuplas, en donde cada tupla contiene el indice del y el valor de elemento de la lista orginal." "Dada una lista *a*, utilizando una comprensión, imprimir una lista de tuplas, en donde cada tupla contiene el indice y el valor de elemento de la lista orginal."
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 68, "execution_count": 69,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -316,14 +337,352 @@ ...@@ -316,14 +337,352 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2.5 Documentacion (docstring)" "### 2.4.3\n",
"Genera una lista que contenga una tuplas con todos los pares posibles de elementos entre las dos listas."
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"a = [0,1,2,3,4,5,6]\n",
"b = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.4.4 \n",
"Utilizando *filter* y una expresion *lambda* generar una lista que contenga todos los numeros impares de una lista de entrada **a**."
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [],
"source": [
"a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.4.5\n",
"Utilizado ***reduce*** y una expresion *lambda*, obten la suma de todos lo elementos en una lista."
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [],
"source": [
"a = [5, 8, 10, 20, 50, 100] "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.4.6 \n",
"Utilizando *map* y una expresion *lambda* obtener una lista cuyos elementos sean la suma de los elementos correspondientes en las listas **a** y **b**.\n"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [],
"source": [
"a = [5, 10, 15, 20]\n",
" \n",
"b = [30, 35, 40, 45]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.6.7\n",
"Escribir un generador en forma de expresion que obtenga las primeras 10 ternas pitagoricas.\n",
"\n",
"[Wikipedia](https://es.wikipedia.org/wiki/Terna_pitag%C3%B3rica): Una terna pitagórica es un conjunto ordenado de tres números enteros positivos a, b, c, y son solución de la ecuación diofantina cuadrática $a^{2}+b^{2}=c^{2}$.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.6.8 \n",
"Escribir un generador en forma de funcion recursiva que entregue la lista de todas las permitaciones de los elementos en una lista."
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [],
"source": [
"a = [\"a\", \"b\", \"c\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.5 Modulos y Paquetes\n",
"En Python, cada uno de nuestros archivos .py se denominan módulos. Estos módulos, a la vez, pueden formar parte de paquetes. Un paquete, es una carpeta que contiene archivos .py. Para que una carpeta pueda ser considerada un paquete, debe contener un archivo de inicio llamado ``__init__.py``. Este archivo, no necesita contener ninguna instrucción. De hecho, puede estar vacío.\n",
"\n",
"\n",
"``\n",
"└── miModulo\n",
" ├── __init__.py \n",
" └── helloWOrld.py \n",
"``"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello\n"
]
}
],
"source": [
"from miModulo import helloWorld\n",
"helloWorld.hello()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.6 Documentacion (docstring)\n",
"\n",
"Python **Docstring** es el texto de documentación que puede aprecer en la definición de una clase, módulo, función o método, y se escribe como la primera declaración. Se puede acceder a las cadenas de documenacion desde el atributo doc para cualquiera de los objetos de Python y también con la función incorporada **help()**."
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generators have a ``Yields`` section instead of a ``Returns`` section.\n",
"\n",
" Args:\n",
" n (int): The upper limit of the range to generate, from 0 to `n` - 1.\n",
"\n",
" Yields:\n",
" int: The next number in the range of 0 to `n` - 1.\n",
"\n",
" Examples:\n",
" Examples should be written in doctest format, and should illustrate how\n",
" to use the function.\n",
"\n",
" >>> print([i for i in example_generator(4)])\n",
" [0, 1, 2, 3]\n",
"\n",
" \n",
"Help on function example_generator in module __main__:\n",
"\n",
"example_generator(n)\n",
" Generators have a ``Yields`` section instead of a ``Returns`` section.\n",
" \n",
" Args:\n",
" n (int): The upper limit of the range to generate, from 0 to `n` - 1.\n",
" \n",
" Yields:\n",
" int: The next number in the range of 0 to `n` - 1.\n",
" \n",
" Examples:\n",
" Examples should be written in doctest format, and should illustrate how\n",
" to use the function.\n",
" \n",
" >>> print([i for i in example_generator(4)])\n",
" [0, 1, 2, 3]\n",
"\n"
]
}
],
"source": [
"def example_generator(n):\n",
" \"\"\"Generators have a ``Yields`` section instead of a ``Returns`` section.\n",
"\n",
" Args:\n",
" n (int): The upper limit of the range to generate, from 0 to `n` - 1.\n",
"\n",
" Yields:\n",
" int: The next number in the range of 0 to `n` - 1.\n",
"\n",
" Examples:\n",
" Examples should be written in doctest format, and should illustrate how\n",
" to use the function.\n",
"\n",
" >>> print([i for i in example_generator(4)])\n",
" [0, 1, 2, 3]\n",
"\n",
" \"\"\"\n",
" for i in range(n):\n",
" yield i\n",
"\n",
"type(example_generator)\n",
"print(example_generator.__doc__)\n",
"help(example_generator)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.6.1 pydoc\n",
"En la linea de comando el modulo **pydoc** permite general la documentacion de los modulo en formato html:\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"cd miModulo\n",
"pydoc -w helloWorld.py"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n",
"<html><head><title>Python: module helloWorld</title>\n",
"<meta charset=\"utf-8\">\n",
"</head><body bgcolor=\"#f0f0f8\">\n",
"\n",
"<table width=\"100%\" cellspacing=0 cellpadding=2 border=0 summary=\"heading\">\n",
"<tr bgcolor=\"#7799ee\">\n",
"<td valign=bottom>&nbsp;<br>\n",
"<font color=\"#ffffff\" face=\"helvetica, arial\">&nbsp;<br><big><big><strong>helloWorld</strong></big></big></font></td\n",
"><td align=right valign=bottom\n",
"><font color=\"#ffffff\" face=\"helvetica, arial\"><a href=\".\">index</a><br><a href=\"file:/home/mchc/git/tap1012/miModulo/helloWorld.py\">/home/mchc/git/tap1012/miModulo/helloWorld.py</a></font></td></tr></table>\n",
" <p><tt>This&nbsp;example&nbsp;module&nbsp;shows&nbsp;various&nbsp;types&nbsp;of&nbsp;documentation&nbsp;available&nbsp;for&nbsp;use<br>\n",
"with&nbsp;pydoc.&nbsp;&nbsp;To&nbsp;generate&nbsp;HTML&nbsp;documentation&nbsp;for&nbsp;this&nbsp;module&nbsp;issue&nbsp;the<br>\n",
"command:<br>\n",
"&nbsp;<br>\n",
"&nbsp;&nbsp;&nbsp;&nbsp;pydoc&nbsp;-w&nbsp;foo</tt></p>\n",
"<p>\n",
"<table width=\"100%\" cellspacing=0 cellpadding=2 border=0 summary=\"section\">\n",
"<tr bgcolor=\"#eeaa77\">\n",
"<td colspan=3 valign=bottom>&nbsp;<br>\n",
"<font color=\"#ffffff\" face=\"helvetica, arial\"><big><strong>Functions</strong></big></font></td></tr>\n",
" \n",
"<tr><td bgcolor=\"#eeaa77\"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>\n",
"<td width=\"100%\"><dl><dt><a name=\"-hello\"><strong>hello</strong></a>()</dt><dd><tt>Documentacion&nbsp;de&nbsp;función&nbsp;<a href=\"#-hello\">hello</a>()&nbsp;del&nbsp;modulo&nbsp;miModulo.</tt></dd></dl>\n",
"</td></tr></table>\n",
"</body></html>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import HTML\n",
"HTML(filename=\"miModulo/helloWorld.html\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.7 Casos de Prueba (doctest)\n",
"\n",
"doctest prueba el código fuente ejecutando ejemplos incrustados en la documentación y verificando que producen los resultados esperados. Funciona al analizar el texto de ayuda para encontrar ejemplos, ejecutarlos y luego comparar el texto de salida con el valor esperado.\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trying:\n",
" multiply(4, 3)\n",
"Expecting:\n",
" 12\n",
"ok\n",
"Trying:\n",
" multiply('a', 3)\n",
"Expecting:\n",
" 'aaa'\n",
"ok\n",
"1 items had no tests:\n",
" __main__\n",
"1 items passed all tests:\n",
" 2 tests in __main__.multiply\n",
"2 tests in 2 items.\n",
"2 passed and 0 failed.\n",
"Test passed.\n"
]
},
{
"data": {
"text/plain": [
"TestResults(failed=0, attempted=2)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def multiply(a, b):\n",
" '''\n",
" >>> multiply(4, 3)\n",
" 12\n",
" >>> multiply('a', 3)\n",
" 'aaa'\n",
" '''\n",
" return a * b\n",
"import doctest\n",
"\n",
"doctest.testmod(verbose=True)\n"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2.6 y Casos de Prueba (doctest)" "## 2.8 Ejercicios\n",
"Escribe la documentacion y los casos de prueba para todos los ejercicios de la semana 1 y 2."
] ]
}, },
{ {
......
...@@ -149,6 +149,27 @@ ...@@ -149,6 +149,27 @@
"\n" "\n"
] ]
}, },
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"function"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f = lambda x: x * x\n",
"type(f)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 41,
...@@ -300,12 +321,12 @@ ...@@ -300,12 +321,12 @@
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 2.4.2\n", "### 2.4.2\n",
"Dada una lista *a*, utilizando una comprensión, imprimir una lista de tuplas, en donde cada tupla contiene el indice del y el valor de elemento de la lista orginal." "Dada una lista *a*, utilizando una comprensión, imprimir una lista de tuplas, en donde cada tupla contiene el indice y el valor de elemento de la lista orginal."
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 68, "execution_count": 69,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -316,14 +337,352 @@ ...@@ -316,14 +337,352 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2.5 Documentacion (docstring)" "### 2.4.3\n",
"Genera una lista que contenga una tuplas con todos los pares posibles de elementos entre las dos listas."
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"a = [0,1,2,3,4,5,6]\n",
"b = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.4.4 \n",
"Utilizando *filter* y una expresion *lambda* generar una lista que contenga todos los numeros impares de una lista de entrada **a**."
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [],
"source": [
"a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.4.5\n",
"Utilizado ***reduce*** y una expresion *lambda*, obten la suma de todos lo elementos en una lista."
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [],
"source": [
"a = [5, 8, 10, 20, 50, 100] "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.4.6 \n",
"Utilizando *map* y una expresion *lambda* obtener una lista cuyos elementos sean la suma de los elementos correspondientes en las listas **a** y **b**.\n"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [],
"source": [
"a = [5, 10, 15, 20]\n",
" \n",
"b = [30, 35, 40, 45]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.6.7\n",
"Escribir un generador en forma de expresion que obtenga las primeras 10 ternas pitagoricas.\n",
"\n",
"[Wikipedia](https://es.wikipedia.org/wiki/Terna_pitag%C3%B3rica): Una terna pitagórica es un conjunto ordenado de tres números enteros positivos a, b, c, y son solución de la ecuación diofantina cuadrática $a^{2}+b^{2}=c^{2}$.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.6.8 \n",
"Escribir un generador en forma de funcion recursiva que entregue la lista de todas las permitaciones de los elementos en una lista."
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [],
"source": [
"a = [\"a\", \"b\", \"c\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.5 Modulos y Paquetes\n",
"En Python, cada uno de nuestros archivos .py se denominan módulos. Estos módulos, a la vez, pueden formar parte de paquetes. Un paquete, es una carpeta que contiene archivos .py. Para que una carpeta pueda ser considerada un paquete, debe contener un archivo de inicio llamado ``__init__.py``. Este archivo, no necesita contener ninguna instrucción. De hecho, puede estar vacío.\n",
"\n",
"\n",
"``\n",
"└── miModulo\n",
" ├── __init__.py \n",
" └── helloWOrld.py \n",
"``"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello\n"
]
}
],
"source": [
"from miModulo import helloWorld\n",
"helloWorld.hello()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.6 Documentacion (docstring)\n",
"\n",
"Python **Docstring** es el texto de documentación que puede aprecer en la definición de una clase, módulo, función o método, y se escribe como la primera declaración. Se puede acceder a las cadenas de documenacion desde el atributo doc para cualquiera de los objetos de Python y también con la función incorporada **help()**."
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generators have a ``Yields`` section instead of a ``Returns`` section.\n",
"\n",
" Args:\n",
" n (int): The upper limit of the range to generate, from 0 to `n` - 1.\n",
"\n",
" Yields:\n",
" int: The next number in the range of 0 to `n` - 1.\n",
"\n",
" Examples:\n",
" Examples should be written in doctest format, and should illustrate how\n",
" to use the function.\n",
"\n",
" >>> print([i for i in example_generator(4)])\n",
" [0, 1, 2, 3]\n",
"\n",
" \n",
"Help on function example_generator in module __main__:\n",
"\n",
"example_generator(n)\n",
" Generators have a ``Yields`` section instead of a ``Returns`` section.\n",
" \n",
" Args:\n",
" n (int): The upper limit of the range to generate, from 0 to `n` - 1.\n",
" \n",
" Yields:\n",
" int: The next number in the range of 0 to `n` - 1.\n",
" \n",
" Examples:\n",
" Examples should be written in doctest format, and should illustrate how\n",
" to use the function.\n",
" \n",
" >>> print([i for i in example_generator(4)])\n",
" [0, 1, 2, 3]\n",
"\n"
]
}
],
"source": [
"def example_generator(n):\n",
" \"\"\"Generators have a ``Yields`` section instead of a ``Returns`` section.\n",
"\n",
" Args:\n",
" n (int): The upper limit of the range to generate, from 0 to `n` - 1.\n",
"\n",
" Yields:\n",
" int: The next number in the range of 0 to `n` - 1.\n",
"\n",
" Examples:\n",
" Examples should be written in doctest format, and should illustrate how\n",
" to use the function.\n",
"\n",
" >>> print([i for i in example_generator(4)])\n",
" [0, 1, 2, 3]\n",
"\n",
" \"\"\"\n",
" for i in range(n):\n",
" yield i\n",
"\n",
"type(example_generator)\n",
"print(example_generator.__doc__)\n",
"help(example_generator)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.6.1 pydoc\n",
"En la linea de comando el modulo **pydoc** permite general la documentacion de los modulo en formato html:\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"cd miModulo\n",
"pydoc -w helloWorld.py"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n",
"<html><head><title>Python: module helloWorld</title>\n",
"<meta charset=\"utf-8\">\n",
"</head><body bgcolor=\"#f0f0f8\">\n",
"\n",
"<table width=\"100%\" cellspacing=0 cellpadding=2 border=0 summary=\"heading\">\n",
"<tr bgcolor=\"#7799ee\">\n",
"<td valign=bottom>&nbsp;<br>\n",
"<font color=\"#ffffff\" face=\"helvetica, arial\">&nbsp;<br><big><big><strong>helloWorld</strong></big></big></font></td\n",
"><td align=right valign=bottom\n",
"><font color=\"#ffffff\" face=\"helvetica, arial\"><a href=\".\">index</a><br><a href=\"file:/home/mchc/git/tap1012/miModulo/helloWorld.py\">/home/mchc/git/tap1012/miModulo/helloWorld.py</a></font></td></tr></table>\n",
" <p><tt>This&nbsp;example&nbsp;module&nbsp;shows&nbsp;various&nbsp;types&nbsp;of&nbsp;documentation&nbsp;available&nbsp;for&nbsp;use<br>\n",
"with&nbsp;pydoc.&nbsp;&nbsp;To&nbsp;generate&nbsp;HTML&nbsp;documentation&nbsp;for&nbsp;this&nbsp;module&nbsp;issue&nbsp;the<br>\n",
"command:<br>\n",
"&nbsp;<br>\n",
"&nbsp;&nbsp;&nbsp;&nbsp;pydoc&nbsp;-w&nbsp;foo</tt></p>\n",
"<p>\n",
"<table width=\"100%\" cellspacing=0 cellpadding=2 border=0 summary=\"section\">\n",
"<tr bgcolor=\"#eeaa77\">\n",
"<td colspan=3 valign=bottom>&nbsp;<br>\n",
"<font color=\"#ffffff\" face=\"helvetica, arial\"><big><strong>Functions</strong></big></font></td></tr>\n",
" \n",
"<tr><td bgcolor=\"#eeaa77\"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>\n",
"<td width=\"100%\"><dl><dt><a name=\"-hello\"><strong>hello</strong></a>()</dt><dd><tt>Documentacion&nbsp;de&nbsp;función&nbsp;<a href=\"#-hello\">hello</a>()&nbsp;del&nbsp;modulo&nbsp;miModulo.</tt></dd></dl>\n",
"</td></tr></table>\n",
"</body></html>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import HTML\n",
"HTML(filename=\"miModulo/helloWorld.html\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.7 Casos de Prueba (doctest)\n",
"\n",
"doctest prueba el código fuente ejecutando ejemplos incrustados en la documentación y verificando que producen los resultados esperados. Funciona al analizar el texto de ayuda para encontrar ejemplos, ejecutarlos y luego comparar el texto de salida con el valor esperado.\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trying:\n",
" multiply(4, 3)\n",
"Expecting:\n",
" 12\n",
"ok\n",
"Trying:\n",
" multiply('a', 3)\n",
"Expecting:\n",
" 'aaa'\n",
"ok\n",
"1 items had no tests:\n",
" __main__\n",
"1 items passed all tests:\n",
" 2 tests in __main__.multiply\n",
"2 tests in 2 items.\n",
"2 passed and 0 failed.\n",
"Test passed.\n"
]
},
{
"data": {
"text/plain": [
"TestResults(failed=0, attempted=2)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def multiply(a, b):\n",
" '''\n",
" >>> multiply(4, 3)\n",
" 12\n",
" >>> multiply('a', 3)\n",
" 'aaa'\n",
" '''\n",
" return a * b\n",
"import doctest\n",
"\n",
"doctest.testmod(verbose=True)\n"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2.6 y Casos de Prueba (doctest)" "## 2.8 Ejercicios\n",
"Escribe la documentacion y los casos de prueba para todos los ejercicios de la semana 1 y 2."
] ]
}, },
{ {
......
"""
This example module shows various types of documentation available for use
with pydoc. To generate HTML documentation for this module issue the
command:
pydoc -w foo
"""
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module helloWorld</title>
<meta charset="utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>helloWorld</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/mchc/git/tap1012/miModulo/helloWorld.py">/home/mchc/git/tap1012/miModulo/helloWorld.py</a></font></td></tr></table>
<p><tt>This&nbsp;example&nbsp;module&nbsp;shows&nbsp;various&nbsp;types&nbsp;of&nbsp;documentation&nbsp;available&nbsp;for&nbsp;use<br>
with&nbsp;pydoc.&nbsp;&nbsp;To&nbsp;generate&nbsp;HTML&nbsp;documentation&nbsp;for&nbsp;this&nbsp;module&nbsp;issue&nbsp;the<br>
command:<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;pydoc&nbsp;-w&nbsp;foo</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-hello"><strong>hello</strong></a>()</dt><dd><tt>Documentacion&nbsp;de&nbsp;función&nbsp;<a href="#-hello">hello</a>()&nbsp;del&nbsp;modulo&nbsp;miModulo.</tt></dd></dl>
</td></tr></table>
</body></html>
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This example module shows various types of documentation available for use
with pydoc. To generate HTML documentation for this module issue the
command:
pydoc -w foo
"""
def hello():
'''
Documentacion de función hello() del modulo miModulo.
'''
print("hello")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment