diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 00e9fae..0000000 --- a/.appveyor.yml +++ /dev/null @@ -1,46 +0,0 @@ -version: '{branch}-{build}' -build: off -cache: - - '%LOCALAPPDATA%\pip\Cache' -environment: - global: - WITH_COMPILER: 'cmd /E:ON /V:ON /C .\ci\appveyor-with-compiler.cmd' - matrix: - - TOXENV: check - TOXPYTHON: C:\Python37\python.exe - PYTHON_HOME: C:\Python37 - PYTHON_VERSION: '3.7' - PYTHON_ARCH: '32' - - TOXENV: 'py37,codecov' - TOXPYTHON: C:\Python37\python.exe - PYTHON_HOME: C:\Python37 - PYTHON_VERSION: '3.7' - PYTHON_ARCH: '32' - - TOXENV: 'py37,codecov' - TOXPYTHON: C:\Python37-x64\python.exe - PYTHON_HOME: C:\Python37-x64 - PYTHON_VERSION: '3.7' - PYTHON_ARCH: '64' -init: - - ps: echo $env:TOXENV - - ps: ls C:\Python* -install: - - python -u ci\appveyor-bootstrap.py - - python -m pip install -U pip - - '%PYTHON_HOME%\Scripts\virtualenv --version' - - '%PYTHON_HOME%\Scripts\easy_install --version' - - '%PYTHON_HOME%\Scripts\pip --version' - - '%PYTHON_HOME%\Scripts\tox --version' - - choco install -r -y swig -test_script: - - '%WITH_COMPILER% %PYTHON_HOME%\Scripts\tox' - -on_failure: - - ps: dir "env:" - - ps: get-content .tox\*\log\* -artifacts: - - path: dist\* - -### To enable remote debugging uncomment this (also, see: http://www.appveyor.com/docs/how-to/rdp-to-build-worker): -# on_finish: -# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 6cd9eca..5002af8 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,40 +1,89 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python package - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - +name: build +on: [push, pull_request] jobs: - build: - - runs-on: ubuntu-latest + test: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + timeout-minutes: 30 strategy: fail-fast: false matrix: - python-version: ["3.5", "3.8", "3.10"] - + include: + - name: 'check' + python: '3.9' + toxpython: 'python3.9' + tox_env: 'check' + os: 'ubuntu-latest' + - name: 'docs' + python: '3.9' + toxpython: 'python3.9' + tox_env: 'docs' + os: 'ubuntu-latest' + - name: 'py37 (ubuntu)' + python: '3.7' + toxpython: 'python3.7' + python_arch: 'x64' + tox_env: 'py37' + os: 'ubuntu-latest' + - name: 'py37 (windows)' + python: '3.7' + toxpython: 'python3.7' + python_arch: 'x64' + tox_env: 'py37' + os: 'windows-latest' + - name: 'py38 (ubuntu)' + python: '3.8' + toxpython: 'python3.8' + python_arch: 'x64' + tox_env: 'py38' + os: 'ubuntu-latest' + - name: 'py38 (windows)' + python: '3.8' + toxpython: 'python3.8' + python_arch: 'x64' + tox_env: 'py38' + os: 'windows-latest' + - name: 'py39 (ubuntu)' + python: '3.9' + toxpython: 'python3.9' + python_arch: 'x64' + tox_env: 'py39' + os: 'ubuntu-latest' + - name: 'py39 (windows)' + python: '3.9' + toxpython: 'python3.9' + python_arch: 'x64' + tox_env: 'py39' + os: 'windows-latest' + - name: 'py310 (ubuntu)' + python: '3.10' + toxpython: 'python3.10' + python_arch: 'x64' + tox_env: 'py310' + os: 'ubuntu-latest' + - name: 'py310 (windows)' + python: '3.10' + toxpython: 'python3.10' + python_arch: 'x64' + tox_env: 'py310' + os: 'windows-latest' steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + - uses: actions/checkout@v3 with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m 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 + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + architecture: ${{ matrix.python_arch }} + - name: install dependencies run: | - pytest + python -mpip install --progress-bar=off -r ci/requirements.txt + virtualenv --version + pip --version + tox --version + pip list --format=freeze + - name: test + env: + TOXPYTHON: '${{ matrix.toxpython }}' + run: > + tox -e ${{ matrix.tox_env }} -v diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 59d673f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,52 +0,0 @@ -language: python -dist: xenial -cache: false - -addons: - apt: - packages: - - expect-dev # provides unbuffer utility - - python-lxml # because pip installation is slow - - pdftk - - libreoffice - - graphviz -env: - global: - - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so - - SEGFAULT_SIGNALS=all -matrix: - include: - - python: '3.6' - env: - - TOXENV=check - - python: '3.8' - env: - - TOXENV=docs - - env: - - TOXENV=py36,codecov - python: '3.6' - - env: - - TOXENV=py37,codecov - python: '3.7' - - env: - - TOXENV=py38,codecov - python: '3.8' -before_install: - - python --version - - uname -a - - lsb_release -a || true -install: - - python -mpip install --progress-bar=off tox -rci/requirements.txt - - virtualenv --version - - easy_install --version - - pip --version - - tox --version -script: - - tox -v -after_failure: - - more .tox/log/* | cat - - more .tox/*/log/* | cat -notifications: - email: - on_success: never - on_failure: always diff --git a/ci/requirements.txt b/ci/requirements.txt index 1c8d385..6226712 100644 --- a/ci/requirements.txt +++ b/ci/requirements.txt @@ -1,3 +1,4 @@ virtualenv>=16.6.0 pip>=19.1.1 setuptools>=18.0.1 +tox diff --git a/setup.py b/setup.py index acac36b..a4cf61c 100644 --- a/setup.py +++ b/setup.py @@ -79,6 +79,7 @@ def read(*names, **kwargs): 'lxml', 'py3o.template', 'sh', + 'pytz', 'python-dateutil', # eg: 'aspectlib==1.1.1', 'six>=1.7', ], diff --git a/src/erpbrasil/edoc/pdf/danfe_formata.py b/src/erpbrasil/edoc/pdf/danfe_formata.py index dfa5a5e..c30d8fc 100644 --- a/src/erpbrasil/edoc/pdf/danfe_formata.py +++ b/src/erpbrasil/edoc/pdf/danfe_formata.py @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- import base64 import locale -import pytz - from datetime import datetime -from dateutil.parser import parse - -from genshi import Markup -from reportlab.graphics.barcode import createBarcodeDrawing +import pytz +from dateutil.parser import parse from erpbrasil.base.fiscal import cnpj_cpf from erpbrasil.base.misc import format_zipcode +from genshi import Markup +from reportlab.graphics.barcode import createBarcodeDrawing def formata_decimal(numero, digitos): @@ -145,7 +143,7 @@ def formata_dhRecbto(dhRecbto): # FIXME em algum ponto o valor do campo esta sendo formatado para string # deveria ter um tratamento caso o valor seja None deveria retornar a string # vazia '' ao invés de retornar 'None' - if dhRecbto is 'None': + if dhRecbto == 'None': return '' else: dhRecbto = str(dhRecbto) diff --git a/src/erpbrasil/edoc/pdf/nfe.py b/src/erpbrasil/edoc/pdf/nfe.py index 89b7273..92b6d6a 100644 --- a/src/erpbrasil/edoc/pdf/nfe.py +++ b/src/erpbrasil/edoc/pdf/nfe.py @@ -77,7 +77,7 @@ def __getattribute__(*args): result = objectify.ObjectifiedElement.__getattribute__(*args) # Caso existe um metodo de formatação para o atributo no danfe_formatado - if type(result) == NFeElement: + if type(result) is NFeElement: search = re.search('{.*}(.*)', result.tag) if not search: return result diff --git a/tests/test_xml.py b/tests/test_xml.py index a26d3ab..74a0415 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -7,10 +7,12 @@ OUTPUT = 'output' TIPO = 'danfe' -for (dirpath, dirnames, filenames) in walk(PATH): - for file in filenames: - arquivo = path.join(PATH, file) - output = path.join(OUTPUT, file) - print('XML: ' + file) - print(base.ImprimirXml.imprimir(caminho_xml=arquivo, output_dir=output)) +def test_pdf_gen(): + for (dirpath, dirnames, filenames) in walk(PATH): + for file in filenames: + arquivo = path.join(PATH, file) + output = path.join(OUTPUT, file) + + print('XML: ' + file) + print(base.ImprimirXml.imprimir(caminho_xml=arquivo, output_dir=output)) diff --git a/tox.ini b/tox.ini index bf53832..b51aab3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,3 @@ -[testenv:bootstrap] -deps = - jinja2 - matrix - tox -skip_install = true -commands = - python ci/bootstrap.py -passenv = - * ; a generative tox configuration, see: https://tox.readthedocs.io/en/latest/config.html#generative-envlist [tox] @@ -15,18 +5,17 @@ envlist = clean, check, docs, - {py36,py37,py38,pypy,pypy3}, + {py37,py38,py39,py310}, report ignore_basepython_conflict = true [testenv] basepython = - pypy: {env:TOXPYTHON:pypy} - pypy3: {env:TOXPYTHON:pypy3} - py36: {env:TOXPYTHON:python3.6} - {py38,docs,spell}: {env:TOXPYTHON:python3.8} + {py39,docs,spell}: {env:TOXPYTHON:python3.9} py37: {env:TOXPYTHON:python3.7} py38: {env:TOXPYTHON:python3.8} + py39: {env:TOXPYTHON:python3.9} + py310: {env:TOXPYTHON:python3.10} {bootstrap,clean,check,report,codecov}: {env:TOXPYTHON:python3} setenv = PYTHONPATH={toxinidir}/tests @@ -36,25 +25,29 @@ passenv = usedevelop = false deps = pytest - pytest-travis-fold pytest-cov + commands = {posargs:pytest --cov --cov-report=term-missing -vv tests} +[testenv:bootstrap] +deps = + jinja2 + matrix + tox +skip_install = true +commands = + python ci/bootstrap.py + [testenv:check] deps = - docutils check-manifest - flake8 readme-renderer pygments - isort skip_install = true commands = - python setup.py check --strict --metadata --restructuredtext + python setup.py check --strict --metadata --restructuredtext -vv check-manifest {toxinidir} - flake8 src tests setup.py - isort --verbose --check-only --diff --recursive src tests setup.py [testenv:spell] setenv = @@ -80,6 +73,7 @@ deps = codecov skip_install = true commands = + coverage xml --ignore-errors codecov [] [testenv:report]