Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e6b752

Browse files
committed
tests: use tox, enable PyPy and PyPy3, add macOS and Windows CI
1 parent 02e738a commit 8e6b752

File tree

14 files changed

+236
-111
lines changed

14 files changed

+236
-111
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ MANIFEST*
1111
*.png.old
1212
*.pyc
1313
.pytest_cache
14+
.tox
15+
.vscode

.travis.yml

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,77 @@
11
language: python
2-
python:
3-
- 2.7
4-
- 3.5
5-
- 3.6
6-
- nightly # currently points to 3.8-dev
72

8-
# Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs
93
matrix:
104
include:
11-
- python: 3.7
5+
- os: linux
6+
python: "2.7"
7+
env:
8+
- TOXENV=py27
9+
- DISPLAY=":42"
1210
dist: xenial
1311
sudo: true
12+
- os: linux
13+
python: "3.5"
14+
env:
15+
- TOXENV=py35
16+
- DISPLAY=":42"
17+
dist: xenial
18+
sudo: true
19+
- os: linux
20+
python: "3.6"
21+
env:
22+
- TOXENV=py36
23+
- DISPLAY=":42"
24+
dist: xenial
25+
sudo: true
26+
- os: linux
27+
python: "3.7"
28+
env:
29+
- TOXENV=py37
30+
- DISPLAY=":42"
31+
dist: xenial
32+
sudo: true
33+
- os: linux
34+
python: "pypy"
35+
env:
36+
- TOXENV=pypy
37+
- DISPLAY=":42"
38+
dist: xenial
39+
sudo: true
40+
- os: linux
41+
python: "pypy3.5"
42+
env:
43+
- TOXENV=pypy3
44+
- DISPLAY=":42"
45+
dist: xenial
46+
sudo: true
47+
- os: osx
48+
language: generic
49+
env:
50+
- PYTHON_VERSION=2.7
51+
- TOXENV=py27
52+
- os: osx
53+
language: generic
54+
env:
55+
- PYTHON_VERSION=3.7
56+
- TOXENV=py37
57+
allow_failures:
58+
- python: pypy
59+
- python: pypy3.5
1460

1561
addons:
1662
apt:
1763
packages:
18-
- xpra
19-
- xserver-xorg-video-dummy
64+
- lsof
2065

2166
before_install:
22-
- xpra --xvfb="Xorg +extension RANDR -config `pwd`/tests/res/dummy.xorg.conf -logfile ${HOME}/.xpra/xorg.log" start :42
23-
24-
env:
25-
- DISPLAY=":42"
67+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then bash .travis/install.sh; fi
68+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- $DISPLAY -ac -screen 0 1280x1024x24; fi
2669

2770
install:
28-
- python -m pip install flake8 numpy pillow sphinx
29-
- python -m pip install -e .
71+
- python -m pip install --upgrade pip tox
3072

31-
script:
32-
- python -m pytest --display=":42.0" tests
33-
- python -m flake8 .
34-
- if [[ $TRAVIS_PYTHON_VERSION > '2.8' ]]; then cd docs && make clean html; fi
73+
before_script:
74+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi
3575

36-
after_script:
37-
- xpra stop :42
38-
- cat ~/.xpra/*.log
76+
script:
77+
- tox

.travis/install.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Taken largely from https://stackoverflow.com/q/45257534
3+
if [[ "$PYTHON_VERSION" == "2.7" ]]; then
4+
which virtualenv
5+
# Create and activate a virtualenv for conda
6+
virtualenv -p python condavenv
7+
source condavenv/bin/activate
8+
# Grab Miniconda 2
9+
wget https://repo.continuum.io/miniconda/Miniconda2-latest-MacOSX-x86_64.sh -O miniconda.sh
10+
else
11+
# Install or upgrade to Python 3
12+
brew update 1>/dev/null
13+
brew upgrade python
14+
# Create and activate a virtualenv for conda
15+
virtualenv -p python3 condavenv
16+
source condavenv/bin/activate
17+
# Grab Miniconda 3
18+
wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh
19+
fi
20+
21+
# Install our version of miniconda
22+
bash miniconda.sh -b -p $HOME/miniconda
23+
# Modify the PATH, even though this doesn't seem to be effective later on
24+
export PATH="$HOME/miniconda/bin:$PATH"
25+
hash -r
26+
# Configure conda to act non-interactively
27+
conda config --set always_yes yes --set changeps1 no
28+
# Update conda to the latest and greatest
29+
conda update -q conda
30+
# Enable conda-forge for binary packages, if necessary
31+
conda config --add channels conda-forge
32+
# Useful for debugging any issues with conda
33+
conda info -a
34+
echo "Creating conda virtualenv with Python $PYTHON_VERSION"
35+
conda create -n venv python=$PYTHON_VERSION
36+
# For whatever reason, source is not finding the activate script unless we
37+
# specify the full path to it
38+
source $HOME/miniconda/bin/activate venv
39+
# This is the Python that will be used for running tests, so we dump its
40+
# version here to help with troubleshooting
41+
which python
42+
python --version

CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ History:
22

33
<see Git checking messages for history>
44

5-
4.0.0 201x/xx/xx
5+
4.0.0 2019/xx/xx
66
- MSS: remove use of setup.py for setup.cfg
77
- MSS: renamed MSSBase to MSSMixin in base.py
88
- MSS: refactor ctypes argtype, restype and errcheck setup (fixes #84)
@@ -13,6 +13,7 @@ History:
1313
- MSS: fix Flake8 I100: Import statements are in the wrong order
1414
- MSS: fix Flake8 I201: Missing newline before sections or imports
1515
- MSS: fix PyLint bad-super-call: Bad first argument 'Exception' given to super()
16+
- tests: use tox, enable PyPy and PyPy3, add macOS and Windows CI
1617

1718
3.3.2 2018/11/20
1819
- new contributors: hugovk, Andreas Buhr

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
4.0.0 (201x-xx-xx)
1+
4.0.0 (2019-xx-xx)
22
==================
33

44
base.py

appveyor.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
build: off
2+
3+
cache:
4+
- '%LOCALAPPDATA%\pip\Cache'
5+
6+
environment:
7+
fast_finish: true
8+
matrix:
9+
- python: py27
10+
tox_env: py27
11+
python_path: c:\python27
12+
- python: py27-x64
13+
tox_env: py27
14+
python_path: c:\python27-x64
15+
- python: py35
16+
tox_env: py35
17+
python_path: c:\python35
18+
- python: py35-x64
19+
tox_env: py35
20+
python_path: c:\python35-x64
21+
- python: py36
22+
tox_env: py36
23+
python_path: c:\python36
24+
- python: py36-x64
25+
tox_env: py36
26+
python_path: c:\python36-x64
27+
- python: py37
28+
tox_env: py37
29+
python_path: c:\python37
30+
- python: py37-x64
31+
tox_env: py37
32+
python_path: c:\python37-x64
33+
34+
install:
35+
- python -m pip install virtualenv
36+
- python -m virtualenv env
37+
- env\Scripts\activate.bat
38+
- python -m pip install --upgrade pip tox
39+
40+
test_script:
41+
tox -e %tox_env%

docs/source/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ Methods
144144

145145
As it is using the :py:func:`format()` function, you can specify formatting options like ``{date:%Y-%m-%s}``.
146146

147+
.. warning:: On Windows, the default date format may result with a filename containing ':' which is not allowed::
148+
149+
IOerror: [Errno 22] invalid mode ('wb') or filename: 'sct_1-2019-01-01 21:20:43.114194.png'
150+
151+
To fix this, you must provide a custom formatting.
152+
147153
.. method:: shot()
148154

149155
:return str: The created file.

docs/source/developers.rst

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,20 @@ Testing
2323
Dependency
2424
----------
2525

26-
You will need `pytest <https://pypi.python.org/pypi/pytest>`_::
26+
You will need `tox <https://pypi.org/project/tox/>`_::
2727

28-
$ python -m pip install --upgrade --user pytest
28+
$ python -m pip install --upgrade --user tox
2929

3030

3131
How to Test?
3232
------------
3333

34-
Enable the developer mode::
35-
36-
$ python -m pip install -e .
37-
3834
Launch the test suit::
3935

40-
$ python -m pytest tests
41-
42-
.. Note::
43-
44-
As he module is Python 2 and 3 compliant, do no forgot to test for both. If you cannot, just say it when sending the patch, someone else will validate for you.
45-
46-
47-
Validating the Code
48-
===================
49-
50-
It is important to keep a clean base code. Use tools like `flake8 <https://pypi.python.org/pypi/flake8>`_.
51-
52-
53-
Dependencies
54-
------------
55-
56-
Install required packages::
57-
58-
$ python -m pip install --upgrade --user flake8
36+
$ tox
37+
# TOXENV=py37 tox
5938

60-
61-
How to Validate?
62-
----------------
63-
64-
::
65-
66-
$ python -m flake8 .
67-
68-
If there is no output, you are good ;)
39+
This will test MSS and ensure a good code quality.
6940

7041

7142
Static Type Checking
@@ -94,18 +65,6 @@ Running Mypy
9465
Documentation
9566
=============
9667

97-
Dependencies
98-
------------
99-
100-
You will need `Sphinx <http://sphinx-doc.org/>`_::
101-
102-
$ python -m pip install --upgrade --user sphinx
103-
104-
105-
How to Build?
106-
-------------
107-
108-
::
68+
To build the documentation, simply type::
10969

110-
$ cd docs
111-
$ make clean html
70+
$ TOXENV=docs tox

mss/windows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
HGDIOBJ,
1717
HWND,
1818
INT,
19-
LPARAM,
2019
LONG,
20+
LPARAM,
2121
RECT,
2222
UINT,
2323
WORD,

tests/conftest.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
import pytest
1111

1212

13-
def pytest_addoption(parser):
14-
txt = 'Display to use (examples: ":0.1", ":0" [default])'
15-
parser.addoption("--display", action="store", default=":0", help=txt)
16-
17-
1813
def purge_files():
1914
""" Remove all generated files from previous runs. """
2015

@@ -32,16 +27,11 @@ def before_tests(request):
3227
request.addfinalizer(purge_files)
3328

3429

35-
@pytest.fixture(scope="session")
36-
def display(request):
37-
return request.config.getoption("--display")
38-
39-
4030
@pytest.fixture(scope="module")
41-
def sct(display):
31+
def sct():
4232
try:
43-
# `display` keyword is only for GNU/Linux
44-
return mss.mss(display=display)
33+
# `display` kwarg is only for GNU/Linux
34+
return mss.mss(display=os.getenv("DISPLAY"))
4535
except TypeError:
4636
return mss.mss()
4737

0 commit comments

Comments
 (0)