Merge pull request #515 from anthrotype/pytest

use pytest to collect and run unittests and doctests
This commit is contained in:
Cosimo Lupo 2016-02-07 02:12:05 +00:00
commit ecf721fa7b
9 changed files with 38 additions and 77 deletions

View File

@ -1,49 +1,37 @@
environment: environment:
global:
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
# /E:ON and /V:ON options are not enabled in the batch script intepreter
# See: http://stackoverflow.com/a/13751649/163740
CMD_IN_ENV: "cmd /E:ON /V:ON /C run_with_env.cmd"
# links to python-appveyor-demo's scripts by Olivier Grisel's (@ogrisel):
RUN_WITH_ENV_CMD_URL: "https://raw.githubusercontent.com/ogrisel/python-appveyor-demo/master/appveyor/run_with_env.cmd"
INSTALL_PS1_URL: "https://raw.githubusercontent.com/ogrisel/python-appveyor-demo/master/appveyor/install.ps1"
matrix: matrix:
- PYTHON: "C:\\Python27" - PYTHON: "C:\\Python27"
PYTHON_VERSION: "2.7.x" PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "32" PYTHON_ARCH: "32"
TOXENV: "py27"
- PYTHON: "C:\\Python34" - PYTHON: "C:\\Python34"
PYTHON_VERSION: "3.4.x" PYTHON_VERSION: "3.4.x"
PYTHON_ARCH: "32" PYTHON_ARCH: "32"
TOXENV: "py34"
- PYTHON: "C:\\Python35" - PYTHON: "C:\\Python35"
PYTHON_VERSION: "3.5.0" PYTHON_VERSION: "3.5.x"
PYTHON_ARCH: "32" PYTHON_ARCH: "32"
TOXENV: "py35"
- PYTHON: "C:\\Python27-x64" - PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x" PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "64" PYTHON_ARCH: "64"
TOXENV: "py27"
- PYTHON: "C:\\Python34-x64" - PYTHON: "C:\\Python34-x64"
PYTHON_VERSION: "3.4.x" PYTHON_VERSION: "3.4.x"
PYTHON_ARCH: "64" PYTHON_ARCH: "64"
TOXENV: "py34"
- PYTHON: "C:\\Python35-x64" - PYTHON: "C:\\Python35-x64"
PYTHON_VERSION: "3.5.0" PYTHON_VERSION: "3.5.x"
PYTHON_ARCH: "64" PYTHON_ARCH: "64"
TOXENV: "py35"
install: install:
# download 'run_with_env.cmd' script that configures environment variables for the # Prepend Python to the PATH of this build
# MSVC compiler and Windows SDK versions.
- "appveyor DownloadFile %RUN_WITH_ENV_CMD_URL%"
# download 'install.ps1' to install Python (official .msi of http://python.org) and
# pip when not already installed
- "appveyor DownloadFile %INSTALL_PS1_URL%"
- ps: if (-not(Test-Path($env:PYTHON))) { & install.ps1 }
# Prepend newly installed Python to the PATH of this build
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
# check that we have the expected version and architecture for Python # check that we have the expected version and architecture for Python
@ -53,23 +41,17 @@ install:
# upgrade pip to avoid out-of-date warnings # upgrade pip to avoid out-of-date warnings
- "pip install --disable-pip-version-check --user --upgrade pip" - "pip install --disable-pip-version-check --user --upgrade pip"
# Install the build dependencies of the project. If some dependencies contain # install the dependencies to run the tests
# compiled extensions and are not provided as pre-built wheel packages, - "pip install -r dev-requirements.txt"
# pip will build them from source using the MSVC compiler matching the
# target Python version and architecture
- "%CMD_IN_ENV% pip install -vr requirements.txt"
build: false build: false
test_script: test_script:
- "SET PATH=C:\\msys64\\usr\\bin;%PATH%" - "tox"
# 'run-test.sh' interprets $PYTHON as the executable name
- "SET PYTHON=python"
- "bash run-tests.sh"
after_test: after_test:
# if tests are successful, create packages for the project # if tests are successful, create packages for the project
- "%CMD_IN_ENV% python setup.py sdist --formats=zip" - python setup.py sdist --formats=zip"
artifacts: artifacts:
# archive the generated packages in the ci.appveyor.com build report # archive the generated packages in the ci.appveyor.com build report

View File

@ -51,4 +51,4 @@ fi
python -m virtualenv ~/.venv python -m virtualenv ~/.venv
source ~/.venv/bin/activate source ~/.venv/bin/activate
pip install tox pip install -r dev-requirements.txt

View File

@ -229,19 +229,19 @@ class Timer(object):
>>> timer = Timer() >>> timer = Timer()
>>> time.sleep(0.01) >>> time.sleep(0.01)
>>> print("First lap:", timer.split()) >>> print("First lap:", timer.split())
First lap: 0.0... First lap: ...
>>> time.sleep(0.02) >>> time.sleep(0.02)
>>> print("Second lap:", timer.split()) >>> print("Second lap:", timer.split())
Second lap: 0.0... Second lap: ...
>>> print("Overall time:", timer.time()) >>> print("Overall time:", timer.time())
Overall time: 0.0... Overall time: ...
Can be used as a context manager inside with-statements. Can be used as a context manager inside with-statements.
>>> with Timer() as t: >>> with Timer() as t:
... time.sleep(0.01) ... time.sleep(0.01)
>>> print("%0.3f seconds" % t.elapsed) >>> print("%0.3f seconds" % t.elapsed)
0.0... seconds 0... seconds
If initialised with a logger, it can log the elapsed time automatically If initialised with a logger, it can log the elapsed time automatically
upon exiting the with-statement. upon exiting the with-statement.
@ -259,7 +259,7 @@ class Timer(object):
>>> timer = Timer(log) >>> timer = Timer(log)
>>> with timer(): >>> with timer():
... time.sleep(0.01) ... time.sleep(0.01)
elapsed time: 0.01...s elapsed time: ...s
>>> with timer('redo it', level=logging.INFO): >>> with timer('redo it', level=logging.INFO):
... time.sleep(0.02) ... time.sleep(0.02)
Took ... to redo it Took ... to redo it
@ -274,7 +274,7 @@ class Timer(object):
... def test2(): ... def test2():
... time.sleep(0.02) ... time.sleep(0.02)
>>> test1() >>> test1()
Took 0.01... to run 'test1' Took ... to run 'test1'
>>> test2() >>> test2()
Took ... to run test 2 Took ... to run test 2
""" """

View File

@ -36,8 +36,11 @@ class OpenFuncWrapperTest(unittest.TestCase):
try: try:
with open(datafile, 'rb') as infile, \ with open(datafile, 'rb') as infile, \
tempfile.NamedTemporaryFile(delete=False) as outfile: tempfile.NamedTemporaryFile(delete=False) as outfile:
env = dict(os.environ)
env["PYTHONPATH"] = os.pathsep.join(sys.path)
check_call( check_call(
[sys.executable, script], stdin=infile, stdout=outfile) [sys.executable, script], stdin=infile, stdout=outfile,
env=env)
result = not filecmp.cmp(infile.name, outfile.name, shallow=False) result = not filecmp.cmp(infile.name, outfile.name, shallow=False)
finally: finally:
os.remove(script) os.remove(script)

View File

@ -7,7 +7,7 @@ from .woff2 import (WOFF2Reader, woff2DirectorySize, woff2DirectoryFormat,
WOFF2FlavorData, woff2TransformedTableTags, WOFF2GlyfTable, WOFF2LocaTable, WOFF2FlavorData, woff2TransformedTableTags, WOFF2GlyfTable, WOFF2LocaTable,
WOFF2Writer) WOFF2Writer)
import unittest import unittest
import sstruct from fontTools.misc import sstruct
import os import os
import random import random
import copy import copy

2
dev-requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pytest>=2.8
tox>=2.3

View File

@ -1 +1 @@
git+https://github.com/google/brotli@66db08156eba94f1fb0f77b6af519e4adedea8bf#egg=Brotli git+https://github.com/google/brotli@v0.3.0#egg=Brotli

View File

@ -12,46 +12,17 @@ elif test "x$1" = x-2; then
shift shift
fi fi
test "x$PYTHON" = x && PYTHON=python test "x$PYTHON" = x && PYTHON=python
echo "$(which $PYTHON) --version"
$PYTHON --version 2>&1
echo
# Setup environment
DIR=`dirname "$0"`
cd "$DIR/Lib"
if [ "x$PYTHONPATH" != "x" ]; then
PYTHONPATH=".:$PYTHONPATH"
else
PYTHONPATH="."
fi
export PYTHONPATH
# Find tests # Find tests
FILTER= FILTERS=
for arg in "$@"; do for arg in "$@"; do
test "x$FILTER" != x && FILTER="$FILTER|" test "x$FILTERS" != x && FILTERS="$FILTERS or "
FILTER="$FILTER$arg" FILTERS="$FILTERS$arg"
done done
test "x$FILTER" = "x" && FILTER=. # Run tests
TESTS=`grep -r --include='*.py' -l -e doctest -e unittest * | grep -E "$FILTER"` if [ -z "$FILTERS" ]; then
$PYTHON -m pytest
ret=0
FAILS=
for test in $TESTS; do
echo "Running tests in $test"
test=`echo "$test" | sed 's@[/\\]@.@g;s@[.]py$@@'`
if ! $PYTHON -m $test -v; then
ret=$((ret+1))
FAILS="$FAILS
$test"
fi
done
echo
echo "SUMMARY:"
if test $ret = 0; then
echo "All tests passed."
else else
echo "$ret source file(s) had tests failing:$FAILS" >&2 $PYTHON -m pytest -k "$FILTERS"
fi fi
exit $ret

View File

@ -9,8 +9,11 @@ commands =
py.test py.test
[pytest] [pytest]
minversion = 2.8
testpaths = testpaths =
Lib/fontTools Lib/fontTools
python_files =
*_test.py
addopts = addopts =
# run py.test in verbose mode # run py.test in verbose mode
-v -v