Skip to content

Commit

Permalink
Added Flake8 and Mypy tests via Travis-CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhuang committed Sep 10, 2017
1 parent 0bb3e59 commit f9c83ed
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 11 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ install: true
matrix:
include:
- python: "2.7"
env: PY_EXE=python2.7
env: PY=true PY_EXE=python2.7
- python: "3.5"
env: PY_EXE=python3.5
env: PY=true PY_EXE=python3.5
- python: "3.5"
env: Flake8=true PY_EXE=python3.5
- python: "3.6"
env: Mypy=true PY_EXE=python3.6
script:
- bash ./run-tests-for-ci.sh
- bash ./run-travis-ci.sh
72 changes: 72 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Most of these settings are taken from here:
# https://github.com/ogrisel/python-appveyor-demo/blob/master/appveyor.yml
#

version: 1.0.{build}

build: off

cache:
- '%LOCALAPPDATA%\pip\Cache'

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 .\\appveyor\\run_with_env.cmd"

matrix:
# Pre-installed Python versions, which Appveyor may upgrade to
# a later point release.
# See: http://www.appveyor.com/docs/installed-software#python

- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x" # currently 2.7.13
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python35-x64"
PYTHON_VERSION: "3.5.x" # currently 3.5.3
PYTHON_ARCH: "64"

init:
- "ECHO %PYTHON%"
- ps: "ls C:/Python*"

install:
# Prepend newly installed Python to the PATH of this build (this cannot be
# done from inside the powershell script as it would require to restart
# the parent CMD process).
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"

- ECHO "Filesystem root:"
- ps: "ls \"C:/\""

# Check that we have the expected version and architecture for Python
- "python --version"
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""

# Upgrade to the latest version of pip to avoid it displaying warnings
# about it being out of date.
- "pip install --disable-pip-version-check --user --upgrade pip"

- "git submodule update --init --recursive"

# Install requirements
- ps: "cat requirements.txt | ?{$_ -notmatch 'dnspython'} > req.txt"
- "%CMD_IN_ENV% pip install -r req.txt"
- ps: "if ($env:PYTHON -like '*Python2*') { pip install dnspython mock} else { pip install dnspython3 }"


before_test:
- "%CMD_IN_ENV% pip install coverage"

test_script:
# Run the project tests
- "copy local_settings.example.py local_settings.py /Y"
- "%CMD_IN_ENV% coverage run manage.py test test/"

after_test:
- "%CMD_IN_ENV% pip install codecov"
- "%CMD_IN_ENV% codecov -X gcov"
88 changes: 88 additions & 0 deletions appveyor/run_with_env.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
:: To build extensions for 64 bit Python 3, we need to configure environment
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
::
:: To build extensions for 64 bit Python 2, we need to configure environment
:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of:
:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0)
::
:: 32 bit builds, and 64-bit builds for 3.5 and beyond, do not require specific
:: environment configurations.
::
:: Note: this script needs to be run with the /E:ON and /V:ON flags for the
:: cmd interpreter, at least for (SDK v7.0)
::
:: More details at:
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
:: http://stackoverflow.com/a/13751649/163740
::
:: Author: Olivier Grisel
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
::
:: Notes about batch files for Python people:
::
:: Quotes in values are literally part of the values:
:: SET FOO="bar"
:: FOO is now five characters long: " b a r "
:: If you don't want quotes, don't include them on the right-hand side.
::
:: The CALL lines at the end of this file look redundant, but if you move them
:: outside of the IF clauses, they do not run properly in the SET_SDK_64==Y
:: case, I don't know why.
@ECHO OFF

SET COMMAND_TO_RUN=%*
SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
SET WIN_WDK=c:\Program Files (x86)\Windows Kits\10\Include\wdf

:: Extract the major and minor versions, and allow for the minor version to be
:: more than 9. This requires the version number to have two dots in it.
SET MAJOR_PYTHON_VERSION=%PYTHON_VERSION:~0,1%
IF "%PYTHON_VERSION:~3,1%" == "." (
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1%
) ELSE (
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,2%
)

:: Based on the Python version, determine what SDK version to use, and whether
:: to set the SDK for 64-bit.
IF %MAJOR_PYTHON_VERSION% == 2 (
SET WINDOWS_SDK_VERSION="v7.0"
SET SET_SDK_64=Y
) ELSE (
IF %MAJOR_PYTHON_VERSION% == 3 (
SET WINDOWS_SDK_VERSION="v7.1"
IF %MINOR_PYTHON_VERSION% LEQ 4 (
SET SET_SDK_64=Y
) ELSE (
SET SET_SDK_64=N
IF EXIST "%WIN_WDK%" (
:: See: https://connect.microsoft.com/VisualStudio/feedback/details/1610302/
REN "%WIN_WDK%" 0wdf
)
)
) ELSE (
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
EXIT 1
)
)

IF %PYTHON_ARCH% == 64 (
IF %SET_SDK_64% == Y (
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
) ELSE (
ECHO Using default MSVC build environment for 64 bit architecture
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
)
) ELSE (
ECHO Using default MSVC build environment for 32 bit architecture
ECHO Executing: %COMMAND_TO_RUN%
call %COMMAND_TO_RUN% || EXIT 1
)
10 changes: 3 additions & 7 deletions run-tests-for-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ $PIP install -r req.txt

cp local_settings.example.py local_settings.py

#python manage.py test test/

$PIP install coverage
coverage run --source=. manage.py test test/
coverage report -m

$PIP install codecov
codecov -X gcov
coverage run manage.py test test/
coverage report -m
codecov
20 changes: 20 additions & 0 deletions run-travis-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash

# before_script
if [[ $Flake8 == true ]]; then
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh
fi

if [[ $Mypy == true ]]; then
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-mypy.sh
cp local_settings.example.py local_settings.py
fi

# run ci according to env variables
if [[ $PY == true ]]; then
. ./run-tests-for-ci.sh
elif [[ $Mypy == true ]]; then
. ./prepare-and-run-mypy.sh python3.6 mypy==0.521 typed-ast==1.0.4
elif [[ $Flake8 == true ]]; then
. ./prepare-and-run-flake8.sh relate course accounts test bin
fi
8 changes: 7 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ max-line-length=85
exclude=course/migrations,accounts/migrations,static,components,course/mdx_mathjax.py

[coverage:run]
source = .
branch=True
cover_pylib=False
omit =
*/.env/*
*/__init__.py
*/virtualenv*/*
*/setuptools*/*
*/migrations/*
Expand All @@ -33,6 +33,9 @@ exclude_lines =
def __repr__
if self.debug
if settings.Debug
if debug
debug_print
if show_log

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
Expand All @@ -42,4 +45,7 @@ exclude_lines =
if 0:
if __name__ == .__main__.:

# mypy import
if False:

ignore_errors = True

0 comments on commit f9c83ed

Please sign in to comment.