-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,947 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
on: pull_request | ||
|
||
name: Github CI Coverage | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Run image | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: "1.4.2" | ||
|
||
- name: Install poetry packages | ||
run: poetry install --with coverage | ||
|
||
- name: Generate coverage report | ||
run: poetry run pytest --cov=brazilcep | ||
|
||
- name: Coveralls | ||
uses: coverallsapp/github-action@v2 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
on: pull_request | ||
|
||
name: Github CI Lint | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Run image | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: "1.4.2" | ||
|
||
- name: Check lock file | ||
run: poetry lock --check | ||
|
||
- name: Install poetry packages | ||
run: poetry install --with lint | ||
|
||
- name: Lint with flake8 | ||
run: | | ||
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Github CI | ||
name: Github CI PyTest | ||
|
||
on: push | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
ci: | ||
strategy: | ||
fail-fast: false | ||
|
||
matrix: | ||
python-version: [3.5, 3.6, 3.7, 3.8] | ||
python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
poetry-version: ["1.4.2"] | ||
os: [ubuntu-22.04, macos-latest, windows-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi | ||
- name: Test with pytest | ||
run: | | ||
pytest | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Run image | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: ${{ matrix.poetry-version }} | ||
|
||
- name: Install dependencies | ||
run: poetry install --with github-actions | ||
|
||
- name: Run tests | ||
run: poetry run pytest |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import enum | ||
import re | ||
|
||
from . import apicep, correios, viacep | ||
|
||
NUMBERS = re.compile(r'[^0-9]') | ||
|
||
|
||
class WebService(enum.Enum): | ||
"""Enum with the webservices available for consultation. | ||
Note: These values are passed as an argument to | ||
CEP query method. | ||
""" | ||
CORREIOS = 0 | ||
VIACEP = 1 | ||
APICEP = 2 | ||
|
||
|
||
services = { | ||
WebService.CORREIOS: correios.fetch_address, | ||
WebService.VIACEP: viacep.fetch_address, | ||
WebService.APICEP: apicep.fetch_address, | ||
} | ||
|
||
|
||
def get_address_from_cep(cep, webservice=WebService.APICEP): | ||
"""Returns the address corresponding to the zip (cep) code entered. | ||
Args: | ||
cep (str): CEP to be queried. | ||
Raises: | ||
ConnectionError: When connection error occurs in CEP query | ||
Timeout: When occurs timeout of webservice response | ||
HTTPError: Invalid HTTP format query | ||
CEPNotFund: CEP not exist in API | ||
BaseException: When any error occurs in the CEP query | ||
returns: | ||
address (dict): Address data of the queried CEP. | ||
""" | ||
|
||
if webservice not in (value for attribute, value in WebService.__dict__.items()): # noqa | ||
raise KeyError("""Invalid webservice. Please use this options: | ||
WebService.CORREIOS, WebService.VIACEP, WebService.APICEP | ||
""") | ||
|
||
cep = _format_cep(cep) | ||
|
||
return services[webservice](_format_cep(cep)) | ||
|
||
def _format_cep(cep): | ||
"""Format CEP, removing any non-numeric characters. | ||
Args: | ||
cep (str): CEP to be formatted. | ||
Raises: | ||
ValueError: When the string is empty or does not contain numbers. | ||
returns: | ||
cep (str): string containing the formatted CEP. | ||
""" | ||
if not isinstance(cep, str) or not cep: | ||
raise ValueError('CEP must be a non-empty string containing only numbers') # noqa | ||
|
||
return NUMBERS.sub('', cep) |
Oops, something went wrong.