Skip to content

Commit 44b779d

Browse files
committed
Add PyInstaller tests
1 parent f00fbad commit 44b779d

File tree

4 files changed

+146
-1
lines changed

4 files changed

+146
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ MANIFEST
2929
# Usually these files are written by a python script from a template
3030
# before PyInstaller builds the exe, so as to inject date/other infos into it.
3131
*.manifest
32-
*.spec
3332

3433
# Installer logs
3534
pip-log.txt

tests/PyInstaller/test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
# =============================================================================
3+
# Created on 22:54
4+
#
5+
# @author: Brénainn
6+
#
7+
#
8+
# test.py
9+
# Copyright (C) 2019-2020 Brénainn Woodsend
10+
#
11+
# This program is free software: you can redistribute it and/or modify
12+
# it under the terms of the GNU General Public License as published by
13+
# the Free Software Foundation, either version 3 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
23+
# =============================================================================
24+
"""
25+
"""
26+
import vtkplotlib
27+
28+
import pytest
29+
pytest.main()

tests/PyInstaller/test.spec

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
block_cipher = None
4+
5+
from PyInstaller.utils.hooks import collect_data_files
6+
7+
8+
a = Analysis(['test.py'],
9+
pathex=[SPECPATH],
10+
binaries=[],
11+
# I seriously doubt anyone actually will want the rabbit in their packages so it is excluded by
12+
# default (in hook-vtkplotlib.py). But it is needed for testing so include it here.
13+
datas=collect_data_files("vtkplotlib", "**.*.stl"),
14+
hiddenimports=["vtkplotlib"],
15+
hookspath=[],
16+
runtime_hooks=[],
17+
excludes=["matplotlib.pylab", "matplotlib.backends", "matplotlib.pyplot", 'vtkmodules.all', 'scipy'],
18+
win_no_prefer_redirects=False,
19+
win_private_assemblies=False,
20+
cipher=block_cipher,
21+
noarchive=False)
22+
pyz = PYZ(a.pure, a.zipped_data,
23+
cipher=block_cipher)
24+
exe = EXE(pyz,
25+
a.scripts,
26+
[],
27+
exclude_binaries=True,
28+
name='test',
29+
debug=False,
30+
bootloader_ignore_signals=False,
31+
strip=False,
32+
upx=False,
33+
console=True )
34+
coll = COLLECT(exe,
35+
a.binaries,
36+
a.zipfiles,
37+
a.datas,
38+
strip=False,
39+
upx=False,
40+
upx_exclude=[],
41+
name='test')

tests/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Welcome to the vtkplotlib test suite!
2+
3+
This guide explains how to run the test suite.
4+
5+
## Test requirements
6+
7+
Some tests for features requiring extra optional dependencies are conditionally skipped if that library isn't installed. To install only the basics use (in the root of this repository):
8+
9+
```shell
10+
pip install .[test_minimal]
11+
```
12+
13+
Or to get everything:
14+
15+
```shell
16+
pip install .[test_full]
17+
```
18+
19+
In either case you may use the `-e` parameter.
20+
21+
## Run the tests
22+
23+
The test-suite is a `pytest` one. Use (in the root of this repository):
24+
25+
```shell
26+
pytest tests
27+
```
28+
29+
Or, if your working directory is not the root of this repo:
30+
31+
```shell
32+
pytest /full/or/relative/path/to/tests
33+
```
34+
35+
It's not particularly well automated. You still have to click and close through each window. I have made a few attempts to improve this but not with much success.
36+
37+
Be sure to test on Python 2.7 and 3.5 as well as your go-to version.
38+
39+
## Testing with PyInstaller
40+
41+
### Setup
42+
43+
To do this requires a PyInstaller that is recent enough to allow libraries to provide their own hooks:
44+
45+
``` shell
46+
pip install "PyInstaller>=4.0"
47+
```
48+
49+
And make sure your `matplotlib` is older than `3.3.0`.
50+
51+
```shell
52+
pip install "matplotlib<3.3"
53+
```
54+
55+
### Build
56+
57+
Next `cd` into the `./tests/PyInstaller/` directory and run:
58+
59+
```shell
60+
PyInstaller --clean --noconfirm test.spec
61+
```
62+
63+
The `--noconfirm` is optional. And `--clean` is only necessary if you have changed the *vtkplotlib* source code.
64+
65+
This creates an executable at `./dist/test/test` (or `dist\test\test.exe` on Windows).
66+
67+
### Test
68+
69+
This executable is just `pytest.main()` with *vtkplotlib* installed in it. The tests themselves are excluded. Run it as you would run `pytest`. Assuming the working directory is still `./tests/PyInstaller/` use:
70+
71+
```shell
72+
dist/test/test ../
73+
```
74+
75+
Avoid running it with the root of this repo as the current working directory. Otherwise you may unintentionally use the original source *vtkplotlib* rather than the bundled one.
76+

0 commit comments

Comments
 (0)