]> git.phdru.name Git - m_librarian.git/commitdiff
CI: Run tests at Travis and AppVeyor
authorOleg Broytman <phd@phdru.name>
Sun, 22 Apr 2018 17:52:07 +0000 (20:52 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 22 Apr 2018 20:43:29 +0000 (23:43 +0300)
.travis.yml [new file with mode: 0644]
TODO
appveyor.yml [new file with mode: 0644]
devscripts/CI/run_with_env.cmd [new file with mode: 0644]
devscripts/requirements/requirements_tests.txt
devscripts/requirements/requirements_tox.txt
tests/conftest.py [new file with mode: 0644]
tests/dbutils.py
tox.ini

diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..47bf07d
--- /dev/null
@@ -0,0 +1,39 @@
+# Only test master and pull requests; skip tags.
+# Other branches can allow themselves.
+branches:
+  only:
+    - master
+
+# Prefer docker containers
+sudo: required
+
+language: python
+
+python:
+  - "2.7"
+
+cache: pip
+
+matrix:
+  include:
+  - python: "2.7"
+    env: TOXENV=py27
+  - python: "3.4"
+    env: TOXENV=py34
+  - python: "3.5"
+    env: TOXENV=py35
+  - python: "3.6"
+    env: TOXENV=py36
+  - python: "2.7"
+    env: TOXENV=py27-flake8
+  - python: "3.4"
+    env: TOXENV=py34-flake8
+
+install:
+  - travis_retry pip install --upgrade pip setuptools tox ppu
+
+script:
+  - tox
+
+before_cache:
+  - remove-old-files.py -o 180 ~/.cache/pip
diff --git a/TODO b/TODO
index 88223de412f8513acc30a8dbff65abbdadc90722..3c1ce617491db8e9295eb13048906eff55db2794 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-GitHub, Travis, AppVeyor, PyPI.
+PyPI.
 
 
 Import from SQL instead of INPX. Import annotations and illustrations.
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644 (file)
index 0000000..128ac37
--- /dev/null
@@ -0,0 +1,56 @@
+# Heavily inspired by Oliver Grisel's appveyor-demo (https://github.com/ogrisel/python-appveyor-demo)
+version: '{branch}-{build}'
+
+# Only test master and pull requests; skip tags.
+# Other branches can allow themselves.
+branches:
+  only:
+    - master
+skip_branch_with_pr: false
+skip_tags: true
+
+cache:
+  - '%LOCALAPPDATA%\pip\Cache'
+
+# Match travis
+clone_depth: 50
+
+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 devscripts\\CI\\run_with_env.cmd"
+
+  matrix:
+    - TOXENV: "py27-sqlite-w32"
+      PYTHON_VERSION: "2.7"
+      PYTHON_ARCH: "32"
+      PYTHON_HOME: "C:\\Python27"
+    - TOXENV: "py36-sqlite-w32"
+      PYTHON_VERSION: "3.6"
+      PYTHON_ARCH: "32"
+      PYTHON_HOME: "C:\\Python36"
+    - TOXENV: "py36-sqlite-w32"
+      PYTHON_VERSION: "3.6"
+      PYTHON_ARCH: "64"
+      PYTHON_HOME: "C:\\Python36-x64"
+
+install:
+  # Ensure we use the right python version
+  - "SET PATH=%PYTHON_HOME%;%PYTHON_HOME%\\Scripts;%PATH%"
+  - "SET TOXPYTHON=%PYTHON_HOME%\\python.exe"
+  - "python --version"
+  - "python -c \"import struct; print(struct.calcsize('P') * 8)\""
+  - "python -m pip install --upgrade pip setuptools"
+  - "pip install --upgrade tox ppu"
+  - "pip --version"
+
+# No build step
+build: false
+
+test_script:
+  - "%CMD_IN_ENV% tox"
+
+after_test:
+  - remove-old-files.py -o 180 %LOCALAPPDATA%\\pip\\Cache
diff --git a/devscripts/CI/run_with_env.cmd b/devscripts/CI/run_with_env.cmd
new file mode 100644 (file)
index 0000000..5da547c
--- /dev/null
@@ -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
+)
index 8e890d819b41b5fc02a1412a619883d51d7ae6bc..353aa9e3da07c97f6853394a88b122808b3d3513 100644 (file)
@@ -2,3 +2,4 @@
 
 pytest
 pytest-cov
+ppu
index 9927ea49c9c91dcb797c18e615721d685a71ef87..ff4ecb65168e532d24caac30294992218b490643 100644 (file)
@@ -1 +1 @@
-tox >= 1.8
+tox >= 2.0
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644 (file)
index 0000000..16600e7
--- /dev/null
@@ -0,0 +1,5 @@
+# flake8: noqa
+# Skip testing the entire module: names here are imported for pytest
+
+from sqlobject.conftest import \
+    pytest_addoption, pytest_configure, setup_tests
index c315fff5e4914ecc2ece30d59b81d3de1301c2d2..bb5a362a18e0b576065b76bfd80c3a247945b64e 100644 (file)
@@ -1,5 +1,6 @@
 
 import os
+from sqlobject.tests.dbtest import getConnection
 from m_librarian.db import open_db, init_db
 from m_librarian.inp import import_inpx
 
@@ -7,19 +8,23 @@ __all__ = ['setup_module', 'teardown_module', 'load_inpx']
 
 
 def setup_module():
-    try:
-        os.remove('/tmp/m_librarian-test.sqlite')
-    except OSError:
-        pass
-    open_db('sqlite:///tmp/m_librarian-test.sqlite')
+    connection = getConnection()
+    if connection.dbName == 'sqlite':
+        try:
+            connection.dropDatabase()
+        except OSError:
+            pass
+    open_db(connection.uri())
     init_db()
 
 
 def teardown_module():
-    try:
-        os.remove('/tmp/m_librarian-test.sqlite')
-    except OSError:
-        pass
+    connection = getConnection()
+    if connection.dbName == 'sqlite':
+        try:
+            connection.dropDatabase()
+        except OSError:
+            pass
 
 
 def load_inpx(inpx):
diff --git a/tox.ini b/tox.ini
index afd438dcdb70dbb6163d596d2a094ed8c87e0acc..c81cceefd8e7b6ded2690d5bc9abc416ee5cfb8a 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,17 +1,27 @@
 [tox]
-minversion = 1.8
-toxworkdir={homedir}/.tox/m_librarian
+minversion = 2.0
 envlist = {py27,py34,py35,py36},{py27,py34}-flake8
 
 # Base test environment settings
 [testenv]
+basepython =
+    py27: {env:TOXPYTHON:python2.7}
+    py34: {env:TOXPYTHON:python3.4}
+    py35: {env:TOXPYTHON:python3.5}
+    py36: {env:TOXPYTHON:python3.6}
+commands =
+    {envpython} --version
+    {envpython} -c "import struct; print(struct.calcsize('P') * 8)"
 deps =
     -rdevscripts/requirements/requirements_tests.txt
-sitepackages = True
+passenv = CI TRAVIS TRAVIS_* APPVEYOR DISTUTILS_USE_SDK MSSdk INCLUDE LIB WINDIR
+platform = linux
 
 [general]
 commands =
-    python -m pytest --cov=m_librarian
+    {[testenv]commands}
+    -rm.py -f /tmp/test.sqdb
+    {envpython} -m pytest --cov=m_librarian -D sqlite:///tmp/test.sqdb
 
 [testenv:py27]
 commands = {[general]commands}
@@ -25,12 +35,41 @@ commands = {[general]commands}
 [testenv:py36]
 commands = {[general]commands}
 
+[sqlite-w32]
+platform = win32
+commands =
+    {[testenv]commands}
+    -rm.py -f C:/projects/m-librarian/test.sqdb
+    pytest --cov=m_librarian -D sqlite:/C:/projects/m-librarian/test.sqdb?debug=1
+    rm.py -f C:/projects/m-librarian/test.sqdb
+
+[testenv:py27-sqlite-w32]
+platform = win32
+commands = {[sqlite-w32]commands}
+
+[testenv:py34-sqlite-w32]
+platform = win32
+commands = {[sqlite-w32]commands}
+
+[testenv:py35-sqlite-w32]
+platform = win32
+commands = {[sqlite-w32]commands}
+
+[testenv:py36-sqlite-w32]
+platform = win32
+commands = {[sqlite-w32]commands}
+
+# flake8
 [testenv:py27-flake8]
 deps =
     flake8
-commands = flake8
+commands =
+    {[testenv]commands}
+    flake8
 
 [testenv:py34-flake8]
 deps =
     flake8
-commands = flake8
+commands =
+    {[testenv]commands}
+    flake8