Skip to content

Commit b23acab

Browse files
committed
Merge branch 'ci'
- Adds requirements.txt - Closes #282 on d319f4e - Add support for Codecov flags - Add color output to AppVeyor pytest - Clean-up conftest.py - Misc CI clean-up
2 parents 0f00e3a + df59d0f commit b23acab

File tree

7 files changed

+103
-105
lines changed

7 files changed

+103
-105
lines changed

.travis.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
sudo: false
22

3-
# language: csharp installs mono/dotnet but has limited python.
43
language: python
54
python:
65
- 2.7
@@ -19,6 +18,7 @@ env:
1918
- LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
2019
- SEGFAULT_SIGNALS=all
2120
- PYTHONUNBUFFERED=True
21+
- CODECOV_ENV=TRAVIS_PYTHON_VERSION
2222

2323
addons:
2424
apt:
@@ -29,31 +29,32 @@ addons:
2929
- mono-devel
3030
- ca-certificates-mono
3131

32+
before_install:
33+
# Set-up location where `Python.Test.dll` will be output
34+
- export PYTHONPATH=`pwd`:$PYTHONPATH
35+
36+
# Set-up dll path for embedded tests
37+
- PY_LIBDIR=$(python -c 'import sysconfig; print(sysconfig.get_config_var("LIBDIR"))')
38+
- export LD_LIBRARY_PATH=$PY_LIBDIR:$LD_LIBRARY_PATH
39+
3240
install:
33-
- pip install --upgrade pycparser coverage codecov pytest
34-
# setup.py install works too, but need to deal w Python.test then
41+
- pip install --upgrade -r requirements.txt
42+
# `setup.py install` works too, but need to deal with `Python.Test` PATH
3543
- coverage run setup.py build_ext --inplace
3644

3745
script:
38-
# Set-up and run python tests
39-
- export PYTHONPATH=`pwd`:$PYTHONPATH
4046
- python -m pytest
4147

42-
# Set-up dll path for embedded tests
43-
- OUTPUT=$(python --version 2>&1)
44-
- PY_VER=${OUTPUT:7:9}
45-
- export LD_LIBRARY_PATH=/opt/python/$PY_VER/lib:$LD_LIBRARY_PATH
46-
- echo $LD_LIBRARY_PATH
47-
- cp Python.Runtime.dll.config src/embed_tests/bin/Python.Runtime.dll.config
48-
# Run embedded tests
48+
- cp Python.Runtime.dll.config src/embed_tests/bin/
4949
# - mono ./packages/NUnit.*/tools/nunit3-console.exe src/embed_tests/bin/Python.EmbeddingTest.dll
5050

51-
after_success:
51+
after_script:
5252
# Uncomment if need to geninterop, ie. py37 final
5353
# - python tools/geninterop/geninterop.py
5454

55-
# Waiting on mono-cov support or SharpCover
56-
- codecov
55+
# Waiting on mono-coverage, SharpCover or xr.Baboon
56+
- coverage xml -i
57+
- codecov --file coverage.xml --flags Setup_Linux
5758

5859
notifications:
5960
email: false

appveyor.yml

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ environment:
99
global:
1010
PYTHONUNBUFFERED: True
1111
PYTHONWARNINGS: 'ignore:::wheel.pep425tags:'
12-
PYTHONPATH: C:\testdir
13-
NUNIT: nunit3-console
14-
CONDA_BLD: C:\miniconda35
12+
CODECOV_ENV: PYTHON_VERSION, PLATFORM
1513

1614
matrix:
1715
- PYTHON_VERSION: 2.7
@@ -21,50 +19,41 @@ environment:
2119
- PYTHON_VERSION: 3.6
2220

2321
init:
24-
# Prepare environment
22+
# Prepare Environment
2523
- mkdir C:\testdir
2624

27-
# Set environment variables depending based on build cfg
28-
- set CONDA_PY=%PYTHON_VERSION:.=%
29-
- set CONDA_BLD_ARCH=%PLATFORM:x=%
30-
- set PYTHON=C:\PYTHON%PYTHON_VERSION:.=%
31-
- if %PLATFORM%==x86 (set CONDA_BLD_ARCH=32)
32-
# - if %PLATFORM%==x86 (set NUNIT=%NUNIT%-x86)
25+
# Update Environment Variables based on matrix/platform
26+
- set PY_VER=%PYTHON_VERSION:.=%
27+
- set PYTHON=C:\PYTHON%PY_VER%
3328
- if %PLATFORM%==x64 (set PYTHON=%PYTHON%-x64)
34-
- if %PLATFORM%==x64 (set CONDA_BLD=%CONDA_BLD%-x64)
3529

36-
# Prepend newly installed Python to the PATH of this build
30+
# Put desired Python version first in PATH
3731
- set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
3832

39-
# Check that we have the expected version, architecture for Python
40-
- python --version
41-
- python -c "import struct; print(struct.calcsize('P') * 8)"
42-
- python -c "import ctypes; print(ctypes.sizeof(ctypes.c_wchar))"
43-
4433
install:
45-
# install for wheels & coverage
46-
- pip install --upgrade pip wheel coverage codecov pytest
34+
- pip install --upgrade -r requirements.txt
4735

48-
# Install OpenCover. Can't put on packages.config; not Linux/Mono compatible
36+
# Install OpenCover. Can't put on `packages.config`, not Mono compatible
4937
- .\tools\nuget\nuget.exe install OpenCover -OutputDirectory packages
5038

5139
build_script:
52-
# build clean sdist & wheel with coverage of setup.py, install local wheel
53-
- coverage run setup.py sdist bdist_wheel
40+
# Create clean `sdist`. Only used for releases
41+
- python setup.py --quiet sdist
42+
# Build `wheel` with coverage of `setup.py`
43+
- coverage run setup.py bdist_wheel
5444

5545
test_script:
5646
- pip install --no-index --find-links=.\dist\ pythonnet
57-
- ps: Copy-Item (Resolve-Path .\build\*\Python.Test.dll) C:\testdir
47+
- ps: Copy-Item .\src\testing\bin\Python.Test.dll C:\testdir\
5848

59-
# Test runner
6049
- ps: .\ci\appveyor_run_tests.ps1
61-
62-
# Build conda-recipe on Pull Requests
6350
- ps: .\ci\appveyor_build_recipe.ps1
6451

6552
on_finish:
66-
# Upload coverage
67-
- codecov
53+
- coverage xml -i
54+
- codecov --file coverage.xml --flags Setup_Windows
55+
- codecov --file py.coverage --flags Python_Tests
56+
- codecov --file cs.coverage --flags Embedded_Tests
6857

6958
artifacts:
7059
- path: dist\*

ci/appveyor_build_recipe.ps1

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1+
# Build `conda.recipe` only if this is a Pull_Request. Saves time for CI.
2+
3+
$env:CONDA_PY = "$env:PY_VER"
4+
# Use pre-installed miniconda. Note that location differs if 64bit
5+
$env:CONDA_BLD = "C:\miniconda35"
6+
7+
if ($env:PLATFORM -eq "x86"){
8+
$env:CONDA_BLD_ARCH=32
9+
} else {
10+
$env:CONDA_BLD_ARCH=64
11+
$env:CONDA_BLD = "$env:CONDA_BLD" + "-x64"
12+
}
13+
114
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
215
# Update PATH, and keep a copy to restore at end of this PowerShell script
316
$old_path = $env:path
417
$env:path = "$env:CONDA_BLD;$env:CONDA_BLD\Scripts;" + $env:path
518

6-
Write-Host "Starting Conda Update/Install" -ForegroundColor "Green"
7-
conda update conda -q -y
8-
conda install conda-build jinja2 anaconda-client -q -y
19+
Write-Host "Starting conda install" -ForegroundColor "Green"
20+
conda config --set always_yes True
21+
conda config --set changeps1 False
22+
conda install conda-build jinja2 anaconda-client --quiet
923

10-
Write-Host "Starting Conda Recipe build" -ForegroundColor "Green"
11-
conda build conda.recipe -q --dirty
24+
Write-Host "Starting conda build recipe" -ForegroundColor "Green"
25+
conda build conda.recipe --dirty --quiet
1226

13-
$CONDA_PKG=(conda build conda.recipe -q --output)
14-
Copy-Item $CONDA_PKG "$env:APPVEYOR_BUILD_FOLDER\dist\"
15-
Write-Host "Completed Conda Recipe build" -ForegroundColor "Green"
27+
$CONDA_PKG=(conda build conda.recipe --output)
28+
Copy-Item $CONDA_PKG .\dist\
29+
Write-Host "Completed conda build recipe" -ForegroundColor "Green"
1630

1731
# Restore PATH back to original
1832
$env:path = $old_path
1933
} else {
20-
Write-Host "Skipping Conda Recipe build" -ForegroundColor "Green"
34+
Write-Host "Skipping conda build recipe" -ForegroundColor "Green"
2135
}

ci/appveyor_run_tests.ps1

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
# Script to simplify appveyor configuration and resolve path to tools
1+
# Script to simplify AppVeyor configuration and resolve path to tools
2+
3+
# Test Runner framework being used for embedded tests
4+
$CS_RUNNER = "nunit3-console"
5+
6+
# Needed for ARCH specific runners(NUnit2/XUnit3). Skip for NUnit3
7+
if ($FALSE -and $env:PLATFORM -eq "x86"){
8+
$CS_RUNNER = $CS_RUNNER + "-x86"
9+
}
210

311
# Executable paths for OpenCover
412
# Note if OpenCover fails, it won't affect the exit codes.
513
$OPENCOVER = Resolve-Path .\packages\OpenCover.*\tools\OpenCover.Console.exe
6-
$NUNIT = Resolve-Path .\packages\NUnit.*\tools\"$env:NUNIT".exe
14+
$CS_RUNNER = Resolve-Path .\packages\NUnit.*\tools\"$CS_RUNNER".exe
715
$PY = Get-Command python
816

917
# Can't use ".\build\*\Python.EmbeddingTest.dll". Missing framework files.
1018
$CS_TESTS = ".\src\embed_tests\bin\Python.EmbeddingTest.dll"
1119
$RUNTIME_DIR = ".\src\runtime\bin\"
1220

1321
# Run python tests with C# coverage
14-
# why `2>&1 | %{ "$_" }`? see: http://stackoverflow.com/a/20950421/5208670
1522
Write-Host ("Starting Python tests") -ForegroundColor "Green"
1623
.$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:py.coverage `
1724
-target:"$PY" -targetargs:"-m pytest" `
18-
-returntargetcode `
19-
2>&1 | %{ "$_" }
25+
-returntargetcode
2026
$PYTHON_STATUS = $LastExitCode
2127
if ($PYTHON_STATUS -ne 0) {
2228
Write-Host "Python tests failed, continuing to embedded tests" -ForegroundColor "Red"
2329
}
2430

2531
# Run Embedded tests with C# coverage
26-
# Powershell continuation: http://stackoverflow.com/a/2608186/5208670
27-
# Powershell options splatting: http://stackoverflow.com/a/24313253/5208670
2832
Write-Host ("Starting embedded tests") -ForegroundColor "Green"
2933
.$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:cs.coverage `
30-
-target:"$NUNIT" -targetargs:"$CS_TESTS" `
34+
-target:"$CS_RUNNER" -targetargs:"$CS_TESTS" `
3135
-filter:"+[*]Python.Runtime*" `
3236
-returntargetcode
33-
$NUNIT_STATUS = $LastExitCode
34-
if ($NUNIT_STATUS -ne 0) {
37+
$CS_STATUS = $LastExitCode
38+
if ($CS_STATUS -ne 0) {
3539
Write-Host "Embedded tests failed" -ForegroundColor "Red"
3640
}
3741

3842
# Set exit code to fail if either Python or Embedded tests failed
39-
if ($PYTHON_STATUS -ne 0 -or $NUNIT_STATUS -ne 0) {
43+
if ($PYTHON_STATUS -ne 0 -or $CS_STATUS -ne 0) {
4044
Write-Host "Tests failed" -ForegroundColor "Red"
4145
$host.SetShouldExit(1)
4246
}

requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Requirements for both Travis and AppVeyor
2+
pytest
3+
coverage
4+
5+
# Platform specific requirements
6+
pip; sys_platform == 'win32'
7+
wheel; sys_platform == 'win32'
8+
pycparser; sys_platform != 'win32'
9+
10+
# Coverage upload
11+
# codecov v2.0.6 isn't on PyPi
12+
https://github.com/codecov/codecov-python/tarball/v2.0.6

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# Don't combine `.bumpversion.cfg` with `setup.cfg`. Messes up formatting.
2+
13
[tool:pytest]
24
xfail_strict = True
5+
# -r fsxX: show extra summary info for: (f)ailed, (s)kip, (x)failed, (X)passed
6+
addopts = -r fsxX --color=yes

src/tests/conftest.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,31 @@
11
# -*- coding: utf-8 -*-
2-
# TODO: move tests one out of src. Pythonnet doesn't run...
2+
# TODO: move tests one out of src to project root.
3+
# TODO: travis has numpy on their workers. Maybe add tests?
34

45
"""Helpers for testing."""
56

6-
import io
7-
import os
7+
import ctypes
88
import sys
9+
import sysconfig
910

10-
import pytest
1111
import clr
1212

13+
# Add path for Python.Test & Add References
1314
sys.path.append('C:/testdir/')
1415
clr.AddReference("Python.Test")
1516
clr.AddReference("System.Collections")
1617
clr.AddReference("System.Data")
1718

18-
DIR_PATH = os.path.dirname(__file__)
19-
FILES_DIR = os.path.join(DIR_PATH, 'files')
2019

20+
def pytest_report_header(config):
21+
"""Generate extra report headers"""
22+
# FIXME: https://github.com/pytest-dev/pytest/issues/2257
23+
is_64bits = sys.maxsize > 2**32
24+
arch = "x64" if is_64bits else "x86"
25+
ucs = ctypes.sizeof(ctypes.c_wchar)
26+
libdir = sysconfig.get_config_var("LIBDIR")
27+
shared = bool(sysconfig.get_config_var("Py_ENABLE_SHARED"))
2128

22-
@pytest.fixture()
23-
def filepath():
24-
"""Returns full file path for test files."""
25-
26-
def make_filepath(filename):
27-
# http://stackoverflow.com/questions/18011902/parameter-to-a-fixture
28-
# Alternate solution is to use paramtrization `inderect=True`
29-
# http://stackoverflow.com/a/33879151
30-
# Syntax is noisy and requires specific variable names
31-
return os.path.join(FILES_DIR, filename)
32-
33-
return make_filepath
34-
35-
36-
@pytest.fixture()
37-
def load_file(filepath):
38-
"""Opens filename with encoding and return its contents."""
39-
40-
def make_load_file(filename, encoding='utf-8'):
41-
# http://stackoverflow.com/questions/18011902/parameter-to-a-fixture
42-
# Alternate solution is to use paramtrization `inderect=True`
43-
# http://stackoverflow.com/a/33879151
44-
# Syntax is noisy and requires specific variable names
45-
# And seems to be limited to only 1 argument.
46-
with io.open(filepath(filename), encoding=encoding) as f:
47-
return f.read().strip()
48-
49-
return make_load_file
50-
51-
52-
@pytest.fixture()
53-
def get_stream(filepath):
54-
def make_stream(filename, encoding='utf-8'):
55-
return io.open(filepath(filename), encoding=encoding)
56-
57-
return make_stream
29+
header = ("Arch: {arch}, UCS: {ucs}, LIBDIR: {libdir}, "
30+
"Py_ENABLE_SHARED: {shared}".format(**locals()))
31+
return header

0 commit comments

Comments
 (0)