Skip to content

Commit

Permalink
Merge pull request #7 from erpbrasil/fix/tests
Browse files Browse the repository at this point in the history
Fix/tests
  • Loading branch information
mileo authored Feb 4, 2021
2 parents b784025 + de5d0af commit 451f0d2
Show file tree
Hide file tree
Showing 19 changed files with 422 additions and 219 deletions.
65 changes: 15 additions & 50 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,45 @@
version: '{branch}-{build}'
build: off
cache:
- '%LOCALAPPDATA%\pip\Cache'
environment:
global:
COVERALLS_EXTRAS: '-v'
COVERALLS_REPO_TOKEN: [Required for Appveyor, take it from https://coveralls.io/github/erpbrasil/erpbrasil.edoc.pdf]
WITH_COMPILER: 'cmd /E:ON /V:ON /C .\ci\appveyor-with-compiler.cmd'
matrix:
- TOXENV: check
TOXPYTHON: C:\Python36\python.exe
PYTHON_HOME: C:\Python36
PYTHON_VERSION: '3.6'
PYTHON_ARCH: '32'
- TOXENV: py27,codecov,coveralls
TOXPYTHON: C:\Python27\python.exe
PYTHON_HOME: C:\Python27
PYTHON_VERSION: '2.7'
PYTHON_ARCH: '32'
- TOXENV: py27,codecov,coveralls
TOXPYTHON: C:\Python27-x64\python.exe
PYTHON_HOME: C:\Python27-x64
PYTHON_VERSION: '2.7'
PYTHON_ARCH: '64'
WINDOWS_SDK_VERSION: v7.0
- TOXENV: py35,codecov,coveralls
TOXPYTHON: C:\Python35\python.exe
PYTHON_HOME: C:\Python35
PYTHON_VERSION: '3.5'
PYTHON_ARCH: '32'
- TOXENV: py35,codecov,coveralls
TOXPYTHON: C:\Python35-x64\python.exe
PYTHON_HOME: C:\Python35-x64
PYTHON_VERSION: '3.5'
PYTHON_ARCH: '64'
- TOXENV: py36,codecov,coveralls
TOXPYTHON: C:\Python36\python.exe
PYTHON_HOME: C:\Python36
PYTHON_VERSION: '3.6'
TOXPYTHON: C:\Python37\python.exe
PYTHON_HOME: C:\Python37
PYTHON_VERSION: '3.7'
PYTHON_ARCH: '32'
- TOXENV: py36,codecov,coveralls
TOXPYTHON: C:\Python36-x64\python.exe
PYTHON_HOME: C:\Python36-x64
PYTHON_VERSION: '3.6'
PYTHON_ARCH: '64'
- TOXENV: py37,codecov,coveralls
- TOXENV: 'py37,codecov'
TOXPYTHON: C:\Python37\python.exe
PYTHON_HOME: C:\Python37
PYTHON_VERSION: '3.7'
PYTHON_ARCH: '32'
- TOXENV: py37,codecov,coveralls
- TOXENV: 'py37,codecov'
TOXPYTHON: C:\Python37-x64\python.exe
PYTHON_HOME: C:\Python37-x64
PYTHON_VERSION: '3.7'
PYTHON_ARCH: '64'
- TOXENV: py38,codecov,coveralls
TOXPYTHON: C:\Python38\python.exe
PYTHON_HOME: C:\Python38
PYTHON_VERSION: '3.8'
PYTHON_ARCH: '32'
- TOXENV: py38,codecov,coveralls
TOXPYTHON: C:\Python38-x64\python.exe
PYTHON_HOME: C:\Python38-x64
PYTHON_VERSION: '3.8'
PYTHON_ARCH: '64'
init:
- ps: echo $env:TOXENV
- ps: ls C:\Python*
install:
- '%PYTHON_HOME%\python -mpip install --progress-bar=off tox -rci/requirements.txt'
- 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:
- cmd /E:ON /V:ON /C .\ci\appveyor-with-compiler.cmd %PYTHON_HOME%\Scripts\tox
- '%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:
Expand Down
30 changes: 13 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
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
Expand All @@ -10,31 +19,18 @@ matrix:
- python: '3.6'
env:
- TOXENV=check
- python: '3.6'
- python: '3.8'
env:
- TOXENV=docs
- env:
- TOXENV=py27,codecov,coveralls
python: '2.7'
- env:
- TOXENV=py35,codecov,coveralls
python: '3.5'
- env:
- TOXENV=py36,codecov,coveralls
- TOXENV=py36,codecov
python: '3.6'
- env:
- TOXENV=py37,codecov,coveralls
- TOXENV=py37,codecov
python: '3.7'
- env:
- TOXENV=py38,codecov,coveralls
- TOXENV=py38,codecov
python: '3.8'
- env:
- TOXENV=pypy,codecov,coveralls
python: 'pypy'
- env:
- TOXENV=pypy3,codecov,coveralls
- TOXPYTHON=pypy3
python: 'pypy3'
before_install:
- python --version
- uname -a
Expand Down
9 changes: 1 addition & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ Overview
.. list-table::
:stub-columns: 1

* - docs
- |docs|
* - tests
- | |travis| |appveyor| |requires|
| |coveralls| |codecov|
* - package
- | |version| |wheel| |supported-versions| |supported-implementations|
| |commits-since|
.. |docs| image:: https://readthedocs.org/projects/erpbrasil.edoc.pdf/badge/?style=flat
:target: https://readthedocs.org/projects/erpbrasiledocpdf
:alt: Documentation Status
.. |travis| image:: https://api.travis-ci.org/erpbrasil/erpbrasil.edoc.pdf.svg?branch=master
:alt: Travis-CI Build Status
Expand Down Expand Up @@ -82,9 +77,7 @@ You can also install the in-development version with::
Documentation
=============


https://erpbrasiledocpdf.readthedocs.io/

https://erpbrasil.github.io/docs/

Development
===========
Expand Down
111 changes: 111 additions & 0 deletions ci/appveyor-bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""
AppVeyor will at least have few Pythons around so there's no point of implementing a bootstrapper in PowerShell.
This is a port of https://github.com/pypa/python-packaging-user-guide/blob/master/source/code/install.ps1
with various fixes and improvements that just weren't feasible to implement in PowerShell.
"""
from __future__ import print_function
from os import environ
from os.path import exists
from subprocess import check_call

try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve

BASE_URL = "https://www.python.org/ftp/python/"
GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
GET_PIP_PATH = "C:\get-pip.py"
URLS = {
("2.7", "64"): BASE_URL + "2.7.13/python-2.7.13.amd64.msi",
("2.7", "32"): BASE_URL + "2.7.13/python-2.7.13.msi",
("3.4", "64"): BASE_URL + "3.4.4/python-3.4.4.amd64.msi",
("3.4", "32"): BASE_URL + "3.4.4/python-3.4.4.msi",
("3.5", "64"): BASE_URL + "3.5.4/python-3.5.4-amd64.exe",
("3.5", "32"): BASE_URL + "3.5.4/python-3.5.4.exe",
("3.6", "64"): BASE_URL + "3.6.2/python-3.6.2-amd64.exe",
("3.6", "32"): BASE_URL + "3.6.2/python-3.6.2.exe",
}
INSTALL_CMD = {
# Commands are allowed to fail only if they are not the last command. Eg: uninstall (/x) allowed to fail.
"2.7": [["msiexec.exe", "/L*+!", "install.log", "/qn", "/x", "{path}"],
["msiexec.exe", "/L*+!", "install.log", "/qn", "/i", "{path}", "TARGETDIR={home}"]],
"3.4": [["msiexec.exe", "/L*+!", "install.log", "/qn", "/x", "{path}"],
["msiexec.exe", "/L*+!", "install.log", "/qn", "/i", "{path}", "TARGETDIR={home}"]],
"3.5": [["{path}", "/quiet", "TargetDir={home}"]],
"3.6": [["{path}", "/quiet", "TargetDir={home}"]],
}


def download_file(url, path):
print("Downloading: {} (into {})".format(url, path))
progress = [0, 0]

def report(count, size, total):
progress[0] = count * size
if progress[0] - progress[1] > 1000000:
progress[1] = progress[0]
print("Downloaded {:,}/{:,} ...".format(progress[1], total))

dest, _ = urlretrieve(url, path, reporthook=report)
return dest


def install_python(version, arch, home):
print("Installing Python", version, "for", arch, "bit architecture to", home)
if exists(home):
return

path = download_python(version, arch)
print("Installing", path, "to", home)
success = False
for cmd in INSTALL_CMD[version]:
cmd = [part.format(home=home, path=path) for part in cmd]
print("Running:", " ".join(cmd))
try:
check_call(cmd)
except Exception as exc:
print("Failed command", cmd, "with:", exc)
if exists("install.log"):
with open("install.log") as fh:
print(fh.read())
else:
success = True
if success:
print("Installation complete!")
else:
print("Installation failed")


def download_python(version, arch):
for _ in range(3):
try:
return download_file(URLS[version, arch], "installer.exe")
except Exception as exc:
print("Failed to download:", exc)
print("Retrying ...")


def install_pip(home):
pip_path = home + "/Scripts/pip.exe"
python_path = home + "/python.exe"
if exists(pip_path):
print("pip already installed.")
else:
print("Installing pip...")
download_file(GET_PIP_URL, GET_PIP_PATH)
print("Executing:", python_path, GET_PIP_PATH)
check_call([python_path, GET_PIP_PATH])


def install_packages(home, *packages):
cmd = [home + "/Scripts/pip.exe", "install"]
cmd.extend(packages)
check_call(cmd)


if __name__ == "__main__":
install_python(environ['PYTHON_VERSION'], environ['PYTHON_ARCH'], environ['PYTHON_HOME'])
install_pip(environ['PYTHON_HOME'])
install_packages(environ['PYTHON_HOME'], "setuptools>=18.0.1", "wheel", "tox", "virtualenv>=13.1.0")
109 changes: 109 additions & 0 deletions ci/appveyor-download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env python
"""
Use the AppVeyor API to download Windows artifacts.
Taken from: https://bitbucket.org/ned/coveragepy/src/tip/ci/download_appveyor.py
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
"""
from __future__ import unicode_literals

import argparse
import os
import zipfile

import requests


def make_auth_headers():
"""Make the authentication headers needed to use the Appveyor API."""
path = os.path.expanduser("~/.appveyor.token")
if not os.path.exists(path):
raise RuntimeError(
"Please create a file named `.appveyor.token` in your home directory. "
"You can get the token from https://ci.appveyor.com/api-token"
)
with open(path) as f:
token = f.read().strip()

headers = {
'Authorization': 'Bearer {}'.format(token),
}
return headers


def download_latest_artifacts(account_project, build_id):
"""Download all the artifacts from the latest build."""
if build_id is None:
url = "https://ci.appveyor.com/api/projects/{}".format(account_project)
else:
url = "https://ci.appveyor.com/api/projects/{}/build/{}".format(account_project, build_id)
build = requests.get(url, headers=make_auth_headers()).json()
jobs = build['build']['jobs']
print(u"Build {0[build][version]}, {1} jobs: {0[build][message]}".format(build, len(jobs)))

for job in jobs:
name = job['name']
print(u" {0}: {1[status]}, {1[artifactsCount]} artifacts".format(name, job))

url = "https://ci.appveyor.com/api/buildjobs/{}/artifacts".format(job['jobId'])
response = requests.get(url, headers=make_auth_headers())
artifacts = response.json()

for artifact in artifacts:
is_zip = artifact['type'] == "Zip"
filename = artifact['fileName']
print(u" {0}, {1} bytes".format(filename, artifact['size']))

url = "https://ci.appveyor.com/api/buildjobs/{}/artifacts/{}".format(job['jobId'], filename)
download_url(url, filename, make_auth_headers())

if is_zip:
unpack_zipfile(filename)
os.remove(filename)


def ensure_dirs(filename):
"""Make sure the directories exist for `filename`."""
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)


def download_url(url, filename, headers):
"""Download a file from `url` to `filename`."""
ensure_dirs(filename)
response = requests.get(url, headers=headers, stream=True)
if response.status_code == 200:
with open(filename, 'wb') as f:
for chunk in response.iter_content(16 * 1024):
f.write(chunk)
else:
print(u" Error downloading {}: {}".format(url, response))


def unpack_zipfile(filename):
"""Unpack a zipfile, using the names in the zip."""
with open(filename, 'rb') as fzip:
z = zipfile.ZipFile(fzip)
for name in z.namelist():
print(u" extracting {}".format(name))
ensure_dirs(name)
z.extract(name)


parser = argparse.ArgumentParser(description='Download artifacts from AppVeyor.')
parser.add_argument('--id',
metavar='PROJECT_ID',
default='erpbrasil/erpbrasil.edoc.pdf',
help='Project ID in AppVeyor.')
parser.add_argument('build',
nargs='?',
metavar='BUILD_ID',
help='Build ID in AppVeyor. Eg: master-123')

if __name__ == "__main__":
# import logging
# logging.basicConfig(level="DEBUG")
args = parser.parse_args()
download_latest_artifacts(args.id, args.build)
Loading

0 comments on commit 451f0d2

Please sign in to comment.