diff --git a/.github/setup.py b/.github/setup.py new file mode 100644 index 000000000..cb079043d --- /dev/null +++ b/.github/setup.py @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/.github/workflows/- name: Codecov uses: codecov/codecov-action@v3.1.0 b/.github/workflows/- name: Codecov uses: codecov/codecov-action@v3.1.0 new file mode 100644 index 000000000..cb079043d --- /dev/null +++ b/.github/workflows/- name: Codecov uses: codecov/codecov-action@v3.1.0 @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/.github/workflows/.travis.yml b/.github/workflows/.travis.yml new file mode 100644 index 000000000..9f0ebb869 --- /dev/null +++ b/.github/workflows/.travis.yml @@ -0,0 +1,36 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "master" branch + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. diff --git a/.github/workflows/d27c9d81-5278-433c-91b9-56587db70ab0 b/.github/workflows/d27c9d81-5278-433c-91b9-56587db70ab0 new file mode 100644 index 000000000..cb079043d --- /dev/null +++ b/.github/workflows/d27c9d81-5278-433c-91b9-56587db70ab0 @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/.github/workflows/setup.py b/.github/workflows/setup.py new file mode 100644 index 000000000..9f0ebb869 --- /dev/null +++ b/.github/workflows/setup.py @@ -0,0 +1,36 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "master" branch + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..9f0ebb869 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "master" branch + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. diff --git a/.github/workflows/test_exemplo.py b/.github/workflows/test_exemplo.py new file mode 100644 index 000000000..cb079043d --- /dev/null +++ b/.github/workflows/test_exemplo.py @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/.travis.yml b/.travis.yml index 6694375b7..136742181 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: python python: - - 3.7 + - 3.10 install: - pip install -q pipenv codecov - pipenv sync --dev script: - flake8 - - pytest libpythonpro --cov=libpythonpro -after_success: - - codecov \ No newline at end of file + - pytest Libpythonpro diff --git a/Libpythonpro/__init__.py b/Libpythonpro/__init__.py new file mode 100644 index 000000000..edcfd0dd7 --- /dev/null +++ b/Libpythonpro/__init__.py @@ -0,0 +1 @@ +__version__ = '0.2' \ No newline at end of file diff --git a/libpythonpro/github_api.py b/Libpythonpro/github_api.py similarity index 67% rename from libpythonpro/github_api.py rename to Libpythonpro/github_api.py index 8b0fbafb9..abc64ed4d 100644 --- a/libpythonpro/github_api.py +++ b/Libpythonpro/github_api.py @@ -4,10 +4,13 @@ def buscar_avatar(usuario): """ Busca o avatar de um usuário no Github - - :param usuario: str com o nome de usuário no github + :Param usuário: str com o nome usuário no github :return: str com o link do avatar """ url = f'https://api.github.com/users/{usuario}' resp = requests.get(url) return resp.json()['avatar_url'] + + +if __name__ == '__main__': + print(buscar_avatar('Carloshbfreire')) diff --git a/libpythonpro/spam/__init__.py b/Libpythonpro/tests/__init__.py similarity index 100% rename from libpythonpro/spam/__init__.py rename to Libpythonpro/tests/__init__.py diff --git a/Libpythonpro/tests/test_exemplo.py b/Libpythonpro/tests/test_exemplo.py new file mode 100644 index 000000000..470a3111a --- /dev/null +++ b/Libpythonpro/tests/test_exemplo.py @@ -0,0 +1,2 @@ +def test_int(): + assert 1 == 1 \ No newline at end of file diff --git a/README.md b/README.md index 676c14d7f..3deff37c6 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,27 @@ Nesse curso é ensinado como contribuir com projetos de código aberto Link para o curso [Python Pro](https://www.python.pro.br/) -[![Build Status](https://travis-ci.org/pythonprobr/libpythonpro.svg?branch=master)](https://travis-ci.org/pythonprobr/libpythonpro) +[![Build Status](https://app.travis-ci.com/Carloshbfreire/libpythonpro-1.svg?branch=master)](https://app.travis-ci.com/Carloshbfreire/libpythonpro-1) + [![Updates](https://pyup.io/repos/github/pythonprobr/libpythonpro/shield.svg)](https://pyup.io/repos/github/pythonprobr/libpythonpro/) [![Python 3](https://pyup.io/repos/github/pythonprobr/libpythonpro/python-3-shield.svg)](https://pyup.io/repos/github/pythonprobr/libpythonpro/) [![codecov](https://codecov.io/gh/pythonprobr/libpythonpro/branch/master/graph/badge.svg)](https://codecov.io/gh/pythonprobr/libpythonpro) -Suportada versão 3 de Python + +Suportada versão 3 de Python Carlinhos Para instalar: ```console -pip install pipenv -pipenv install --dev +python3 -m venv .venv +source .venv/bin/activate +pip install -r requirements-dev.txt ``` Para conferir qualidade de código: ```console -pipenv run flake8 +flake8 ``` Tópicos a serem abordados: @@ -32,4 +35,7 @@ Tópicos a serem abordados: 3. Pip 4. Mock 5. Pipenv - \ No newline at end of file + +Revisando aula sobre Fork. + +Link do Curso [Python pro](https://pythonpro.com.br/) \ No newline at end of file diff --git a/libpythonpro/__init__.py b/libpythonpro/__init__.py deleted file mode 100644 index b650ceb08..000000000 --- a/libpythonpro/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = '0.2' diff --git a/libpythonpro/spam/db.py b/libpythonpro/spam/db.py deleted file mode 100644 index ce90ca60b..000000000 --- a/libpythonpro/spam/db.py +++ /dev/null @@ -1,31 +0,0 @@ -from time import sleep - - -class Sessao: - contador = 0 - usuarios = [] - - def salvar(self, usuario): - Sessao.contador += 1 - usuario.id = Sessao.contador - self.usuarios.append(usuario) - - def listar(self): - return self.usuarios - - def roll_back(self): - self.usuarios.clear() - - def fechar(self): - pass - - -class Conexao: - def __init__(self): - sleep(1) - - def gerar_sessao(self): - return Sessao() - - def fechar(self): - pass diff --git a/libpythonpro/spam/enviador_de_email.py b/libpythonpro/spam/enviador_de_email.py deleted file mode 100644 index fa0952223..000000000 --- a/libpythonpro/spam/enviador_de_email.py +++ /dev/null @@ -1,9 +0,0 @@ -class Enviador: - def enviar(self, remetente, destinatario, assunto, corpo): - if '@' not in remetente: - raise EmailInvalido(f'Email de remetente inválido: {remetente}') - return remetente - - -class EmailInvalido(Exception): - pass diff --git a/libpythonpro/spam/main.py b/libpythonpro/spam/main.py deleted file mode 100644 index f81821ae4..000000000 --- a/libpythonpro/spam/main.py +++ /dev/null @@ -1,13 +0,0 @@ -class EnviadorDeSpam: - def __init__(self, sessao, enviador): - self.sessao = sessao - self.enviador = enviador - - def enviar_emails(self, remetente, assunto, corpo): - for usuario in self.sessao.listar(): - self.enviador.enviar( - remetente, - usuario.email, - assunto, - corpo - ) diff --git a/libpythonpro/spam/modelos.py b/libpythonpro/spam/modelos.py deleted file mode 100644 index 093b35a2a..000000000 --- a/libpythonpro/spam/modelos.py +++ /dev/null @@ -1,5 +0,0 @@ -class Usuario: - def __init__(self, nome, email): - self.email = email - self.nome = nome - self.id = None diff --git a/libpythonpro/tests/__init__.py b/libpythonpro/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/libpythonpro/tests/test_exemplo.py b/libpythonpro/tests/test_exemplo.py deleted file mode 100644 index 78cd50236..000000000 --- a/libpythonpro/tests/test_exemplo.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_int(): - assert 1 == 1 diff --git a/libpythonpro/tests/test_spam/__init__.py b/libpythonpro/tests/test_spam/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/libpythonpro/tests/test_spam/conftest.py b/libpythonpro/tests/test_spam/conftest.py deleted file mode 100644 index a16f3970a..000000000 --- a/libpythonpro/tests/test_spam/conftest.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest - -from libpythonpro.spam.db import Conexao - - -@pytest.fixture(scope='session') -def conexao(): - # Setup - conexao_obj = Conexao() - yield conexao_obj - # Tear Down - conexao_obj.fechar() - - -@pytest.fixture -def sessao(conexao): - sessao_obj = conexao.gerar_sessao() - yield sessao_obj - sessao_obj.roll_back() - sessao_obj.fechar() diff --git a/libpythonpro/tests/test_spam/test_enviador_de_email.py b/libpythonpro/tests/test_spam/test_enviador_de_email.py deleted file mode 100644 index c72a0bbe9..000000000 --- a/libpythonpro/tests/test_spam/test_enviador_de_email.py +++ /dev/null @@ -1,38 +0,0 @@ -import pytest - -from libpythonpro.spam.enviador_de_email import EmailInvalido, Enviador - - -def test_criar_enviador_de_email(): - enviador = Enviador() - assert enviador is not None - - -@pytest.mark.parametrize( - 'remetente', - ['foo@bar.com.br', 'renzo@python.pro.br'] -) -def test_remetente(remetente): - enviador = Enviador() - resultado = enviador.enviar( - remetente, - 'luciano@python.pro.br', - 'Cursos Python Pro', - 'Primeira turma Guido Von Rossum aberta.' - ) - assert remetente in resultado - - -@pytest.mark.parametrize( - 'remetente', - ['', 'renzo'] -) -def test_remetente_invalido(remetente): - enviador = Enviador() - with pytest.raises(EmailInvalido): - enviador.enviar( - remetente, - 'luciano@python.pro.br', - 'Cursos Python Pro', - 'Primeira turma Guido Von Rossum aberta.' - ) diff --git a/libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py b/libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py deleted file mode 100644 index d2db43893..000000000 --- a/libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py +++ /dev/null @@ -1,49 +0,0 @@ -from unittest.mock import Mock - -import pytest - -from libpythonpro.spam.main import EnviadorDeSpam -from libpythonpro.spam.modelos import Usuario - - -@pytest.mark.parametrize( - 'usuarios', - [ - [ - Usuario(nome='Renzo', email='renzo@python.pro.br'), - Usuario(nome='Luciano', email='renzo@python.pro.br') - ], - [ - Usuario(nome='Renzo', email='renzo@python.pro.br') - ] - ] -) -def test_qde_de_spam(sessao, usuarios): - for usuario in usuarios: - sessao.salvar(usuario) - enviador = Mock() - enviador_de_spam = EnviadorDeSpam(sessao, enviador) - enviador_de_spam.enviar_emails( - 'renzo@python.pro.br', - 'Curso Python Pro', - 'Confira os módulos fantásticos' - ) - assert len(usuarios) == enviador.enviar.call_count - - -def test_parametros_de_spam(sessao): - usuario = Usuario(nome='Renzo', email='renzo@python.pro.br') - sessao.salvar(usuario) - enviador = Mock() - enviador_de_spam = EnviadorDeSpam(sessao, enviador) - enviador_de_spam.enviar_emails( - 'luciano@python.pro.br', - 'Curso Python Pro', - 'Confira os módulos fantásticos' - ) - enviador.enviar.assert_called_once_with( - 'luciano@python.pro.br', - 'renzo@python.pro.br', - 'Curso Python Pro', - 'Confira os módulos fantásticos' - ) diff --git a/libpythonpro/tests/test_spam/test_github_api.py b/libpythonpro/tests/test_spam/test_github_api.py deleted file mode 100644 index 21ce9c5d0..000000000 --- a/libpythonpro/tests/test_spam/test_github_api.py +++ /dev/null @@ -1,28 +0,0 @@ -from unittest.mock import Mock - -import pytest - -from libpythonpro import github_api - - -@pytest.fixture -def avatar_url(mocker): - resp_mock = Mock() - url = 'https://avatars3.githubusercontent.com/u/402714?v=4' - resp_mock.json.return_value = { - 'login': 'renzo', 'id': 402714, - 'avatar_url': url, - } - get_mock = mocker.patch('libpythonpro.github_api.requests.get') - get_mock.return_value = resp_mock - return url - - -def test_buscar_avatar(avatar_url): - url = github_api.buscar_avatar('renzo') - assert avatar_url == url - - -def test_buscar_avatar_integracao(): - url = github_api.buscar_avatar('renzon') - assert 'https://avatars3.githubusercontent.com/u/3457115?v=4' == url diff --git a/libpythonpro/tests/test_spam/test_usuarios.py b/libpythonpro/tests/test_spam/test_usuarios.py deleted file mode 100644 index 09b523445..000000000 --- a/libpythonpro/tests/test_spam/test_usuarios.py +++ /dev/null @@ -1,17 +0,0 @@ -from libpythonpro.spam.modelos import Usuario - - -def test_salvar_usuario(sessao): - usuario = Usuario(nome='Renzo', email='renzo@python.pro.br') - sessao.salvar(usuario) - assert isinstance(usuario.id, int) - - -def test_listar_usuarios(sessao): - usuarios = [ - Usuario(nome='Renzo', email='renzo@python.pro.br'), - Usuario(nome='Luciano', email='renzo@python.pro.br') - ] - for usuario in usuarios: - sessao.salvar(usuario) - assert usuarios == sessao.listar() diff --git a/setup.py b/setup.py index 1fea97a65..f4c5b0992 100644 --- a/setup.py +++ b/setup.py @@ -101,7 +101,7 @@ def find_package_data( return out -PACKAGE = "libpythonpro" +PACKAGE = "Libpythonpro" NAME = PACKAGE DESCRIPTION = "Módulo para exemplificar construção de projetos Python no curso PyTools" AUTHOR = "Renzo Nuccitelli" @@ -117,7 +117,7 @@ def find_package_data( long_description_content_type='text/markdown', author=AUTHOR, author_email=AUTHOR_EMAIL, - license="GNU AFFERO GENERAL PUBLIC LICENSE", + license=read('GNU AFFERO GENERAL PUBLIC LICENSE'), url=URL, packages=find_packages(exclude=["tests.*", "tests"]), package_data=find_package_data(PACKAGE, only_in_packages=False), @@ -128,7 +128,7 @@ def find_package_data( "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.10", "Framework :: Pytest", ], install_requires=[