ti_publica:dicas_python
Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
| Ambos lados da revisão anteriorRevisão anteriorPróxima revisão | Revisão anterior | ||
| ti_publica:dicas_python [2019/11/29 11:51] – [Instalações] cartola | ti_publica:dicas_python [2020/01/10 18:57] (atual) – [Recomendações PEP] cartola | ||
|---|---|---|---|
| Linha 10: | Linha 10: | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| - | * [[https:// | + | * [[https:// |
| + | * Isso acaba já instalando o pip3 | ||
| * Dentro do venv: | * Dentro do venv: | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| + | * Pro YouCompleteMe funcionar no Vim dentro de um venv de Python3 tive que instalar:\\ < | ||
| ==== Configurando o ambiente ==== | ==== Configurando o ambiente ==== | ||
| Linha 68: | Linha 70: | ||
| ===== Testes com pytest ===== | ===== Testes com pytest ===== | ||
| + | A ideia é que você crie um programa que vá testar seu código. O pytest é uma ferramenta que vai facilitar isso. | ||
| + | |||
| + | Exemplo de código: | ||
| + | <code python> | ||
| + | """ | ||
| + | | ||
| + | for passnum in range(len(lista)-1, | ||
| + | mudou = False | ||
| + | for i in range(passnum): | ||
| + | if lista[i] > lista[i+1]: | ||
| + | lista[i], lista[i+1] = lista[i+1], lista[i] | ||
| + | print(lista) | ||
| + | mudou = True | ||
| + | if not mudou: | ||
| + | return lista | ||
| + | return lista</ | ||
| + | |||
| + | Exemplo de programa que testa o código: | ||
| + | <code python># -*- coding: UTF-8 -*- | ||
| + | |||
| + | import pytest | ||
| + | import semana5 | ||
| + | |||
| + | class Testa_semana5_bubble(): | ||
| + | |||
| + | @pytest.mark.parametrize(" | ||
| + | ([5, 1, 4, 2], [1, 2, 4, 5]), | ||
| + | ([12, 13, 14, 11], [11, 12, 13, 14]), | ||
| + | ([12, 13, -2, 14, 11], [-2, 11, 12, 13, 14]), | ||
| + | ]) | ||
| + | |||
| + | def testes(self, | ||
| + | assert semana5.bubble_sort(lista) == resultado</ | ||
| + | |||
| + | Para realizar o teste chamamos o programa que testa via pytest: | ||
| + | <code shell>$ pytest-3 testa.py | ||
| + | === test session starts === | ||
| + | platform linux -- Python 3.6.8, pytest-3.3.2, | ||
| + | rootdir: / | ||
| + | plugins: pylint-0.8.0 | ||
| + | collected 3 items | ||
| + | |||
| + | testa.py ... [100%] | ||
| + | |||
| + | === 3 passed in 0.03 seconds === | ||
| + | </ | ||
| ===== Venv ===== | ===== Venv ===== | ||
| Linha 82: | Linha 130: | ||
| =====pexpect/ | =====pexpect/ | ||
| - | O [[https:// | + | O pexpect é o equivalente ao programa original "[[https:// |
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| ===== Django ===== | ===== Django ===== | ||
| + | ===== Recomendações PEP ===== | ||
| + | |||
| + | ===== Referências externas ===== | ||
| + | * [[https:// | ||
ti_publica/dicas_python.1575028284.txt.gz · Última modificação: por cartola
