Skip to content

Commit 25ab71c

Browse files
tkfstevengj
authored andcommitted
Suggestion: Use tox and pytest (#178)
* Run tests via tox and py.test * Use tox in Travis * Use tox in AppVeyor * Add PYJULIA_TEST_REBUILD to recompile PyCall * Disable capturing for now * Pass JULIA_EXE through tox.ini * Travis style versioning in ci/install-julia.sh * Use a script to rebuild PyCall.jl * More debugging info about Python interpreter * Use "python -m pytest" in tox * Move with_rebuilt script to a module so that it's runnable in Windows as well. * Pass around Julia runtime path * Don't show stack-trace from julia.with_rebuilt * Flush stderr in Julia._debug * Avoid pytest hiding debug message * Smoke test with IPython; fix a bug in JuliaImporter * Fix exception printing The Julia exception objects don't have a `.message` attribute, we can just print the plain object. * Fix AppVeyor configuration * Fix comparison of the interpreter paths in Windows * Fix env for Python 2.7 + Windows * Flush stdout in julia.with_rebuilt * Test success paths of IPython magics * Test failure paths of IPython magics * Fix exe_differs check * Add Testing section in README
1 parent 9dfc132 commit 25ab71c

File tree

16 files changed

+336
-123
lines changed

16 files changed

+336
-123
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pip-log.txt
2424

2525
# Unit test / coverage reports
2626
.coverage
27+
.pytest_cache
2728
.tox
2829
nosetests.xml
2930

.travis.yml

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,43 @@
1+
language: python
2+
os:
3+
- linux
4+
python:
5+
- "2.7"
6+
- "3.6"
7+
env:
8+
matrix:
9+
- JULIA_VERSION=0.6.4 CROSS_VERSION=1
10+
- JULIA_VERSION=0.7.0-rc2
11+
# - JULIA_VERSION=nightly
12+
global:
13+
- TOXENV=py
114
matrix:
215
# Python environment is not functional on OS X
316
include:
4-
- language: python
5-
python: 2.7
6-
env: JULIA_VERSION=juliareleases
7-
os: linux
8-
- language: python
9-
python: 2.7
10-
env: JULIA_VERSION=julianightlies
11-
os: linux
12-
- language: python
13-
python: 3.5
14-
env:
15-
- JULIA_VERSION=juliareleases
16-
- CROSS_VERSION=1
17-
os: linux
18-
- language: python
19-
python: 3.5
20-
env: JULIA_VERSION=julianightlies
21-
os: linux
22-
- language: python
23-
python: 3.5
24-
env:
25-
- JULIA_VERSION=julianightlies
26-
- CROSS_VERSION=1
27-
os: linux
2817
- language: generic
2918
env:
3019
- PYTHON=python2
31-
- JULIA_VERSION=julianightlies
20+
- JULIA_VERSION=0.7.0-rc2
21+
# - JULIA_VERSION=nightly
3222
os: osx
3323
- language: generic
3424
env:
3525
- PYTHON=python2
36-
- JULIA_VERSION=juliareleases
26+
- JULIA_VERSION=0.6.4
27+
- CROSS_VERSION=1
3728
os: osx
3829
- language: generic
3930
env:
4031
- PYTHON=python3
41-
- JULIA_VERSION=julianightlies
32+
- JULIA_VERSION=0.7.0-rc2
33+
# - JULIA_VERSION=nightly
4234
os: osx
4335
- language: generic
4436
env:
4537
- PYTHON=python3
46-
- JULIA_VERSION=juliareleases
47-
os: osx
48-
allow_failures:
49-
- env:
50-
- JULIA_VERSION=julianightlies
38+
- JULIA_VERSION=0.6.4
5139
- CROSS_VERSION=1
40+
os: osx
5241
branches:
5342
only:
5443
- master
@@ -57,19 +46,21 @@ notifications:
5746
before_script:
5847
- echo ./ci/install-julia.sh "$JULIA_VERSION"
5948
- ./ci/install-julia.sh "$JULIA_VERSION"
60-
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq -y; fi
61-
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get install libpcre3-dev -y; fi
62-
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get install python-numpy python3-numpy -y; fi
6349
- if [ "$TRAVIS_OS_NAME" = "osx" -a "$PYTHON" = "python3" ]; then brew update; brew upgrade python || echo "Ignoring errors..."; fi
6450
- if [ "$TRAVIS_OS_NAME" = "osx" -a "$PYTHON" = "python2" ]; then brew update; brew list python@2 &>/dev/null || brew install python@2 || echo "Ignoring errors..."; fi
6551
# Ignoring errors from brew since it may actually be OK to do so.
6652
# Following which command will catch installation failure:
67-
- which ${PYTHON:-python}
68-
script:
69-
- julia -e 'Pkg.add("PyCall")'
70-
- /usr/bin/python --version
7153
- PYTHON=${PYTHON:-python}
72-
- echo $PYTHON
73-
- $PYTHON --version
74-
- if [ "$CROSS_VERSION" = "1" ]; then /usr/bin/python -m unittest discover; fi
75-
- $PYTHON -m unittest discover
54+
- which $PYTHON
55+
- $PYTHON -m pip --version
56+
- $PYTHON -m pip install --quiet tox
57+
- julia -e 'Pkg.add("PyCall")'
58+
script:
59+
60+
# "py,py27" below would be redundant when the main interpreter is
61+
# Python 2.7 but it simplifies the CI setup.
62+
- if [ "$CROSS_VERSION" = "1" ]; then
63+
$PYTHON -m tox -e py,py27 -- -s;
64+
fi
65+
66+
- PYJULIA_TEST_REBUILD=yes $PYTHON -m tox -- -s

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ Experimenting with developing a better interface to [Julia language](https://jul
99
to run the tests, execute from the toplevel directory
1010

1111
```shell
12-
python -m unittest discover
12+
tox
1313
```
1414

15+
See [Testing](#testing) below for details.
16+
1517
**Note** You need to explicitly add julia to your `PATH`, an alias will not work.
1618

17-
`pyjulia` is tested against Python versions 2.7 and 3.5. Older versions of Python (than 2.7) are not supported.
19+
`pyjulia` is tested against Python versions 2.7, 3.6, and 3.7. Older versions of Python (than 2.7) are not supported.
1820

1921
Installation
2022
------------
@@ -138,3 +140,38 @@ Limitations
138140
------------
139141

140142
Not all valid Julia identifiers are valid Python identifiers. Unicode identifiers are invalid in Python 2.7 and so `pyjulia` cannot call or access Julia methods/variables with names that are not ASCII only. Additionally, it is a common idiom in Julia to append a `!` character to methods which mutate their arguments. These method names are invalid Python identifers. `pyjulia` renames these methods by subsituting `!` with `_b`. For example, the Julia method `sum!` can be called in `pyjulia` using `sum_b(...)`.
143+
144+
145+
Testing
146+
-------
147+
148+
The full syntax for invoking `tox` is
149+
150+
```shell
151+
[PYJULIA_TEST_REBUILD=yes] [JULIA_EXE=<julia>] tox [options] [-- pytest options]
152+
```
153+
154+
* `PYJULIA_TEST_REBUILD`: *Be careful using this environment
155+
variable!* When it is set to `yes`, your `PyCall.jl` installation
156+
will be rebuilt using the Python interpreter used for testing. The
157+
test suite tries to build back to the original configuration but the
158+
precompilation would be in the stale state after the test. Note
159+
also that it does not work if you unconditionally set `PYTHON`
160+
environment variable in your Julia startup file.
161+
162+
* `JULIA_EXE`: `julia` executable to be used for testing.
163+
164+
* Positional arguments after `--` are passed to `pytest`.
165+
166+
For example,
167+
168+
```shell
169+
PYJULIA_TEST_REBUILD=yes JULIA_EXE=~/julia/julia tox -e py37 -- -s
170+
```
171+
172+
means to execute tests with
173+
174+
* `pyjulia` in shared-cache mode
175+
* `julia` executable at `~/julia/julia`
176+
* Python 3.7
177+
* `pytest`'s capturing mode turned off

appveyor.yml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
11
environment:
2+
3+
TOXENV: py,py27
4+
TOX_TESTENV_PASSENV: DISTUTILS_USE_SDK MSSdk INCLUDE LIB
5+
# https://packaging.python.org/guides/supporting-windows-using-appveyor/#testing-with-tox
6+
27
# for more python versions have a look at
38
# https://github.com/ogrisel/python-appveyor-demo/blob/master/appveyor.yml
49
matrix:
5-
# 64 julia-0.6 Python-27
6-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
7-
PYTHONDIR: "C:\\Python27-x64"
8-
9-
# 32 julia-0.6 Python-27
10+
# 32 julia-0.6 Python-35
1011
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
11-
PYTHONDIR: "C:\\Python27"
12+
PYTHONDIR: "C:\\Python35"
13+
BATDIR: ci\appveyor\win32
14+
CROSS_VERSION: 1
15+
16+
# 32 julia latest Python-35
17+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
18+
PYTHONDIR: "C:\\Python35"
19+
BATDIR: ci\appveyor\win32
1220

1321
# 64 julia-0.6 Python-35
1422
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
1523
PYTHONDIR: "C:\\Python35-x64"
16-
17-
# 32 julia-latest Python-27
18-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
19-
PYTHONDIR: "C:\\Python27"
20-
21-
# 64 julia-latest Python-27
22-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
23-
PYTHONDIR: "C:\\Python27-x64"
24+
BATDIR: ci\appveyor\win64
25+
CROSS_VERSION: 1
2426

2527
# 64 julia latest Python-35
2628
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
2729
PYTHONDIR: "C:\\Python35-x64"
28-
29-
# 64 julia latest Cross Version
30-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
31-
PYTHONDIR: "C:\\Python35-x64"
32-
CROSS_VERSION_PATH: "C:\\Python27-x64"
33-
34-
# 32 julia latest Cross Version
35-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
36-
PYTHONDIR: "C:\\Python35"
37-
CROSS_VERSION_PATH: "C:\\Python27"
30+
BATDIR: ci\appveyor\win64
3831

3932
matrix:
40-
allow_failures:
41-
- CROSS_VERSION_PATH: "C:\\Python27-x64"
42-
- CROSS_VERSION_PATH: "C:\\Python27"
33+
allow_failures:
34+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
35+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
4336

4437
branches:
4538
only:
@@ -71,11 +64,18 @@ build_script:
7164
# - C:\projects\julia\bin\julia -e "using PyCall; @assert isdefined(:PyCall); @assert typeof(PyCall) === Module"
7265
- "SET PYTHON=%PYTHONDIR%\\python.exe"
7366
- C:\projects\julia\bin\julia -e "versioninfo(); Pkg.add(\"PyCall\")"
67+
- "%PYTHONDIR%\\python.exe -m pip install --quiet tox"
7468

7569
test_script:
76-
- "SET PATH=%PYTHONDIR%;%PYTHONDIR%\\Scripts;C:\\projects\\julia\\bin;%PATH%"
77-
- python --version
70+
- "SET PATH=%cd%\\%BATDIR%;%PYTHONDIR%;%PYTHONDIR%\\Scripts;C:\\projects\\julia\\bin;%PATH%"
7871
- dir
79-
- ps: if (Test-Path Env:\CROSS_VERSION_PATH) { Invoke-Expression "$env:CROSS_VERSION_PATH -m unittest discover" }
80-
# - python -c "import julia; julia.Julia(debug=True)"
81-
- python -m unittest discover
72+
73+
# Run cross-version tests but ignore the failures (from Python 2).
74+
# Once cross-version in Windows is fmixed, stop using
75+
# Invoke-Expression (which ignores the exit status).
76+
- ps: if ($env:CROSS_VERSION -eq 1) { Invoke-Expression "tox -- -s" }
77+
# - ps: if ($env:CROSS_VERSION -eq 1) { tox -- -s }
78+
79+
# Rebuild PyCall.ji for each Python interpreter before testing:
80+
- "SET PYJULIA_TEST_REBUILD=yes"
81+
- tox -- -s

ci/appveyor/win32/python2.7.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@C:\Python27\python.exe %*

ci/appveyor/win32/python3.5.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@C:\Python35\python.exe %*

ci/appveyor/win64/python2.7.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@C:\Python27-x64\python.exe %*

ci/appveyor/win64/python3.5.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@C:\Python35-x64\python.exe %*

ci/install-julia.sh

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
#!/bin/sh
2-
# install julia release: ./install-julia.sh juliareleases
3-
# install julia nightly: ./install-julia.sh julianightlies
4-
5-
VERSION="0.6.2"
6-
SHORTVERSION="0.6"
1+
#!/bin/bash
2+
# install julia vX.Y.Z: ./install-julia.sh X.Y.Z
3+
# install julia nightly: ./install-julia.sh nightly
74

85
# stop on error
96
set -e
10-
# default to juliareleases
11-
if [ $# -ge 1 ]; then
12-
JULIAVERSION=$1
13-
elif [ -z "$JULIAVERSION" ]; then
14-
JULIAVERSION=juliareleases
15-
fi
7+
VERSION="$1"
168

17-
case "$JULIAVERSION" in
18-
julianightlies)
9+
case "$VERSION" in
10+
nightly)
1911
BASEURL="https://julialangnightlies-s3.julialang.org/bin"
2012
JULIANAME="julia-latest"
2113
;;
22-
juliareleases)
14+
[0-9]*)
2315
BASEURL="https://julialang-s3.julialang.org/bin"
16+
SHORTVERSION="$(echo "$VERSION" | grep -Eo '^[0-9]+\.[0-9]+')"
2417
JULIANAME="$SHORTVERSION/julia-$VERSION"
2518
;;
2619
*)
27-
echo "Unrecognized JULIAVERSION=$JULIAVERSION, exiting"
20+
echo "Unrecognized VERSION=$VERSION, exiting"
2821
exit 1
2922
;;
3023
esac
@@ -34,22 +27,22 @@ case $(uname) in
3427
case $(uname -m) in
3528
x86_64)
3629
ARCH="x64"
37-
case "$JULIAVERSION" in
38-
julianightlies)
30+
case "$JULIANAME" in
31+
julia-latest)
3932
SUFFIX="linux64"
4033
;;
41-
juliareleases)
34+
*)
4235
SUFFIX="linux-x86_64"
4336
;;
4437
esac
4538
;;
4639
i386 | i486 | i586 | i686)
4740
ARCH="x86"
48-
case "$JULIAVERSION" in
49-
julianightlies)
41+
case "$JULIANAME" in
42+
julia-latest)
5043
SUFFIX="linux32"
5144
;;
52-
juliareleases)
45+
*)
5346
SUFFIX="linux-i686"
5447
;;
5548
esac

0 commit comments

Comments
 (0)