Skip to content

Commit

Permalink
Merge pull request #231 from nicoddemus/black-pre-commit
Browse files Browse the repository at this point in the history
Introduce pre-commit and black formatting
  • Loading branch information
nicoddemus committed Sep 1, 2018
2 parents eaaf9a3 + cc4ef52 commit 72a4f22
Show file tree
Hide file tree
Showing 34 changed files with 1,681 additions and 1,390 deletions.
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/ambv/black
rev: 18.6b4
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3
- repo: https://github.com/asottile/blacken-docs
rev: v0.2.0
hooks:
- id: blacken-docs
additional_dependencies: [black==18.6b4]
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v1.2.0
hooks:
- id: pyupgrade
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.0.0
hooks:
- id: rst-backticks
- repo: local
hooks:
- id: rst
name: rst
entry: rst-lint --encoding utf-8
files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
38 changes: 22 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: generic
language: python
python: "3.6"
sudo: required
dist: trusty

Expand All @@ -8,6 +9,7 @@ env:
- CONDA_CHANNELS=conda-forge SETUP_XVFB=true DEPS="pytest tox coveralls six"

matrix:
- LINTING=1
- PYTEST_QT_API=pyqt4 PYQT_PACKAGE="pyqt=4.*" PYTHON_VERSION=2.7
- PYTEST_QT_API=pyqt4v2 PYQT_PACKAGE="pyqt=4.*" PYTHON_VERSION=2.7
- PYTEST_QT_API=pyside PYQT_PACKAGE="pyside=1.*" PYTHON_VERSION=2.7
Expand All @@ -29,27 +31,32 @@ matrix:
- env: PYTEST_QT_API=pyside2 PYQT_PACKAGE="pyside2=2.*" PYTHON_VERSION=3.6

install:
- sudo apt-get update

# Xvfb / window manager
- sudo apt-get install -y xvfb herbstluftwm

# Setup miniconda
- git clone --depth 1 git://github.com/astropy/ci-helpers.git
- CONDA_DEPENDENCIES="${DEPS} ${PYQT_PACKAGE}" source ci-helpers/travis/setup_conda.sh
- source activate test && pip install -e .
- |
if [ $LINTING == "1" ]; then
pip install -U pip
pip install tox
else
# Xvfb / window manager
sudo apt-get update
sudo apt-get install -y xvfb herbstluftwm
# Setup miniconda
git clone --depth 1 git://github.com/astropy/ci-helpers.git
CONDA_DEPENDENCIES="${DEPS} ${PYQT_PACKAGE}" source ci-helpers/travis/setup_conda.sh
source activate test && pip install -e .
fi
before_script:
- "herbstluftwm &"
- sleep 1

script:
- source activate test && catchsegv coverage run --source=pytestqt -m pytest -v tests
# for some reason tox doesn't get installed with a u+x flag
- |
chmod u+x /home/travis/miniconda/envs/test/bin/tox
/home/travis/miniconda/envs/test/bin/tox -e lint
- |
if [ $LINTING == "1" ]; then
tox -e linting
else
source activate test && catchsegv coverage run --source=pytestqt -m pytest -v tests
fi
after_success:
- coveralls
Expand All @@ -65,4 +72,3 @@ deploy:
tags: true
repo: pytest-dev/pytest-qt
condition: $PYTEST_QT_API = pyqt5

2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Other Changes
`@The-Compiler`_ for the PR (closes `107`_)!

- raise ``RuntimeError`` instead of ``ImportError`` when failing to import
any Qt binding: raising the latter causes `pluggy` in `pytest-2.8` to
any Qt binding: raising the latter causes ``pluggy`` in ``pytest-2.8`` to
generate a subtle warning instead of a full blown error.
Thanks `@Sheeo`_ for bringing this problem to attention (closes `109`_).

Expand Down
46 changes: 26 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pytest-qt
=========

pytest-qt is a `pytest`_ plugin that allows programmers to write tests
for `PySide`_, `PySide2` and `PyQt`_ applications.
for `PySide`_, ``PySide2`` and `PyQt`_ applications.

The main usage is to use the `qtbot` fixture, responsible for handling `qApp`
creation as needed and provides methods to simulate user interaction,
The main usage is to use the ``qtbot`` fixture, responsible for handling ``qApp``
creation as needed and provides methods to simulate user interaction,
like key presses and mouse clicks:


Expand All @@ -15,11 +15,11 @@ like key presses and mouse clicks:
def test_hello(qtbot):
widget = HelloWidget()
qtbot.addWidget(widget)
# click in the Greet button and make sure it updates the appropriate label
qtbot.mouseClick(widget.button_greet, QtCore.Qt.LeftButton)
assert widget.greet_label.text() == 'Hello!'
assert widget.greet_label.text() == "Hello!"
.. _PySide: https://pypi.python.org/pypi/PySide
Expand All @@ -31,10 +31,10 @@ This allows you to test and make sure your view layer is behaving the way you ex

.. |version| image:: http://img.shields.io/pypi/v/pytest-qt.svg
:target: https://pypi.python.org/pypi/pytest-qt

.. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pytest-qt.svg
:target: https://anaconda.org/conda-forge/pytest-qt

.. |travis| image:: https://img.shields.io/travis/pytest-dev/pytest-qt/master.svg
:target: https://travis-ci.org/pytest-dev/pytest-qt

Expand All @@ -51,7 +51,10 @@ This allows you to test and make sure your view layer is behaving the way you ex
:target: https://pypi.python.org/pypi/pytest-qt/
:alt: Supported Python versions

|python| |version| |conda-forge| |travis| |appveyor| |coverage| |docs|
.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black

|python| |version| |conda-forge| |travis| |appveyor| |coverage| |docs| |black|


Features
Expand Down Expand Up @@ -133,15 +136,18 @@ fixed, and make sure to include yourself in the contributors list. :)
Running tests
-------------

Tests are run using `tox`_. The simplest way to test is with `PySide`_, as it
is available on pip and can be installed by ``tox`` automatically::
Tests are run using `tox`_. It is recommended to develop locally on Python 3 because
``PyQt5`` and ``PySide2`` are easily installable using ``pip``::

$ tox -e py34-pyside,py27-pyside,docs
$ tox -e py37-pyside2,py37-pyqt5

``pytest-qt`` is formatted using `black <https://github.com/ambv/black>`_ and uses
`pre-commit <https://github.com/pre-commit/pre-commit>`_ for linting checks before commits. You
can install ``pre-commit`` locally with::

$ pip install pre-commit
$ pre-commit install

If you want to test against `PyQt`_, install it into your global python
installation and use the ``py27-pyqt4``, ``py34-pyqt4`` or ``py34-pyqt5``
testing environments, and ``tox`` will copy the appropriate files into
its virtual environments to ensure isolation.

Contributors
------------
Expand All @@ -163,12 +169,12 @@ Many thanks to:

.. |pycharm| image:: https://www.jetbrains.com/pycharm/docs/logo_pycharm.png
:target: https://www.jetbrains.com/pycharm

.. |pydev| image:: http://www.pydev.org/images/pydev_banner3.png
:target: https://www.pydev.org

|pycharm|

|pydev|
|pycharm|

|pydev|

.. _tox: https://tox.readthedocs.io
5 changes: 2 additions & 3 deletions docs/app_exit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For example:
def test_exit_button(qtbot, monkeypatch):
exit_calls = []
monkeypatch.setattr(QApplication, 'exit', lambda: exit_calls.append(1))
monkeypatch.setattr(QApplication, "exit", lambda: exit_calls.append(1))
button = get_app_exit_button()
qtbot.click(button)
assert exit_calls == [1]
Expand All @@ -28,8 +28,7 @@ Or using the ``mock`` package:
.. code-block:: python
def test_exit_button(qtbot):
with mock.patch.object(QApplication, 'exit'):
with mock.patch.object(QApplication, "exit"):
button = get_app_exit_button()
qtbot.click(button)
assert QApplication.exit.call_count == 1
Loading

0 comments on commit 72a4f22

Please sign in to comment.