Skip to content

Commit

Permalink
Add pre-commit framework configuration and lint documentation (#228)
Browse files Browse the repository at this point in the history
* Lint rst and other files

* Add pre-commit framework configuration
  • Loading branch information
unode authored Jun 11, 2021
1 parent 5076e76 commit 9aeb196
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ A clear and concise description of what you expected to happen.
- Python Version: [e.g. 3.4, 3.8]
- Mattermost Version: [e.g. 5.1.0]
- mmpy_bot Version: [e.g. 1.2.1]

**Additional context**
Add any other context about the problem here [e.g. Settings for your bot, API Version]
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Linting

# Controls when the action will run.
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
Expand Down
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: check-symlinks
- id: check-docstring-first
- id: check-added-large-files
- id: check-merge-conflict
- repo: https://github.com/pycqa/isort
# Formants, sorts and reorganizes imports
rev: 5.8.0
hooks:
- id: isort
args:
- "--profile"
- "black"
- "--filter-files"
- repo: https://github.com/psf/black
# Code style formatting
rev: 21.5b1
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
# Checks the code for PEP8 violations and common pitfals
rev: 3.9.0
hooks:
- id: flake8
- repo: https://github.com/mattseymour/pre-commit-pytype
rev: '2020.10.8'
hooks:
- id: pytype
args:
- "-j"
- "auto"
- "."
- repo: https://github.com/myint/docformatter
# Formats docstrings following PEP 257
rev: v1.3.1
hooks:
- id: docformatter
args:
- "--wrap-summaries"
- "88"
- "--wrap-descriptions"
- "88"
- repo: https://github.com/pycqa/doc8
# sphinx rst style checker
rev: 0.9.0a1
hooks:
- id: doc8
6 changes: 4 additions & 2 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ Credits
=======

Active Contributors
------------
-------------------

* Alex Tzonkov <alex.tzonkov@gmail.com>
* Jelmer Neeven <jelmer@neeven.tech>
* Renato Alves <alves.rjc@gmail.com>
* Thomas Tuffin <ttuffin@redhat.com>

Past Contributors
------------------
-----------------

* Victor Hu <selain@nature.ee.ncku.edu.tw>
* tgly307 <tgly307@163.com>
* GoTLiuM InSPiRiT <gotlium@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For Python 2 and Python3 < 3.8 support, please use versions v1.3.9 or lower.
##### Additional features added in v2.x:
- Multi-threading and asyncio execution
- Integrated webhook server
- Support for click functions
- Support for click functions
- Job scheduling

## Compatibility
Expand Down
60 changes: 39 additions & 21 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,32 @@ We recommend using `venv <https://docs.python.org/3.8/library/venv.html>`_ to ke
Testing
=======

mmpy_bot develops all tests based on pytest. If you need to add your own tests and run tests, please install the dev requirements.
mmpy_bot develops all tests based on pytest. If you need to add your own
tests and run tests, please install the dev requirements.

.. code-block:: bash
$ pip install -r dev-requirements.txt
All the tests are put in `mmpy_bot\tests`.
There are two test packages: :code:`unit_tests` and :code:`integration_tests`.
There are two test packages: :code:`unit_tests` and
:code:`integration_tests`.

Tests which can be performed by a single bot without requiring a server or interaction with other bots should be kept in the :code:`unit_tests` package.
Tests that require interactions between bots on a mattermost server belong to the :code:`integration_tests` package.
Tests which can be performed by a single bot without requiring a server or
interaction with other bots should be kept in the :code:`unit_tests` package.
Tests that require interactions between bots on a mattermost server belong to
the :code:`integration_tests` package.


Adding unit tests
-----------------

There are multiple test modules inside unit_tests package, one for each module in the code.
The naming convention of these modules is *modulename_test*.
Inside each module, there will be several test functions with naming convention *test_methodname*, grouped into classes for each corresponding class in the code.
If you need to add more unit tests, please consider following these conventions.
There are multiple test modules inside unit_tests package, one for each
module in the code. The naming convention of these modules is
*modulename_test*. Inside each module, there will be several test functions
with naming convention *test_methodname*, grouped into classes for each
corresponding class in the code. If you need to add more unit tests, please
consider following these conventions.


Running the unit tests
Expand All @@ -70,13 +76,18 @@ To run the unit tests (in parallel), simply execute:
Adding integration tests
------------------------

The integration tests are run on the `jneeven:mattermost-bot-test` docker image, for which dockerfiles are provided in the `tests/intergration_tests` folder.
The tests are defined as interactions between a bot (the responder) and a driver (the one sending test messages), which live inside the docker image.
Their respective tokens are available in `tests/integration_tests/utils.py`, and the two bots are available as pytest fixtures so they can be easily re-used.
Note that while the bot is also a fixture, it should not be used in any functions.
It will simply be started whenever the integration tests are executed.
The integration tests are run on the `jneeven:mattermost-bot-test` docker
image, for which dockerfiles are provided in the `tests/intergration_tests`
folder. The tests are defined as interactions between a bot (the responder)
and a driver (the one sending test messages), which live inside the docker
image. Their respective tokens are available in
`tests/integration_tests/utils.py`, and the two bots are available as pytest
fixtures so they can be easily re-used. Note that while the bot is also a
fixture, it should not be used in any functions. It will simply be started
whenever the integration tests are executed.

An integration test might look like this (also have a look at the actual code in `tests/integration_tests/test_example_plugin.py`):
An integration test might look like this (also have a look at the actual code
in `tests/integration_tests/test_example_plugin.py`):

.. code-block:: python
Expand All @@ -94,17 +105,23 @@ An integration test might look like this (also have a look at the actual code in
# Checks whether the bot has sent us the expected reply
assert expect_reply(driver, post)["message"] == "Bring it on!"
In this test, the driver sends a message in the "off-topic" channel, and waits for the bot to reply 'Bring it on!'.
If no reply occurs within a default response timeout (15 seconds by default, but this can be passed as an argument to `expect_reply`), an exception will be raised.
The driver fixture is imported from the utils and can be re-used in every test function simply by adding it as a function argument.
In this test, the driver sends a message in the "off-topic" channel, and
waits for the bot to reply 'Bring it on!'. If no reply occurs within a
default response timeout (15 seconds by default, but this can be passed as an
argument to `expect_reply`), an exception will be raised. The driver fixture
is imported from the utils and can be re-used in every test function simply
by adding it as a function argument.



Running the integration_tests
-----------------------------

Running the integration_tests is easy: simply `cd` into `tests/integration_tests`, and run `docker-compose up -d` to start a local mattermost server.
Then run `pytest -n auto .` to start the tests! For more info about the integration tests an the docker server, have a look at `tests/integration_tests/README.md`.
Running the integration_tests is easy: simply `cd` into
`tests/integration_tests`, and run `docker-compose up -d` to start a local
mattermost server. Then run `pytest -n auto .` to start the tests! For more
info about the integration tests an the docker server, have a look at
`tests/integration_tests/README.md`.

Test coverage:
--------------
Expand All @@ -123,8 +140,9 @@ Set necessary configuration as described above, and run:
$ py.test --cov=mmpy_bot tests\
It automatically runs tests and measures code coverage of modules under mmpy_bot root dir.
Using "--cov-report" parameter to write report into "cov_html" folder by html format.
It automatically runs tests and measures code coverage of modules under
mmpy_bot root dir. Using "--cov-report" parameter to write report into
"cov_html" folder by html format.

.. code-block:: bash
Expand Down
27 changes: 19 additions & 8 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _getting-started:

Getting Started
=================
===============

Compatibility
-------------
Expand Down Expand Up @@ -36,7 +36,9 @@ Git Repo
Running the bot
---------------
We recommend creating an `entrypoint` file for executing the bot, which will look something like this:

We recommend creating an `entrypoint` file for executing the bot, which will
look something like this:

.. code-block:: python
Expand All @@ -62,8 +64,11 @@ For more information on configuring bot settings and plugins, please see `settin

Container
#########
A container image is available at `jneeven/mmpy_bot <https://hub.docker.com/r/jneeven/mmpy_bot>`_.
Using your preferred container management software (Docker/Podman), you can pull the image and run it using the following steps:

A container image is available at `jneeven/mmpy_bot
<https://hub.docker.com/r/jneeven/mmpy_bot>`_.
Using your preferred container management software (Docker/Podman), you can
pull the image and run it using the following steps:

#. Pull the image from the Docker repository:

Expand All @@ -77,15 +82,21 @@ Using your preferred container management software (Docker/Podman), you can pull
$ podman run -d --name=mmpy_bot --network=host -e MATTERMOST_URL=<mattermost_server_url> -e MATTERMOST_PORT=<mattermost_server_port> -e BOT_TOKEN=<bot_token> docker.io/jneeven/mmpy_bot
You can also find an example `docker-compose.yml` file `here <https://github.com/attzonko/mmpy_bot/blob/main/docker-compose.yml>`_.
You can also find an example `docker-compose.yml` file `here
<https://github.com/attzonko/mmpy_bot/blob/master/docker-compose.yml>`_.

Customizing your bot
####################
Getting your bot running is only the beginning. The real fun begins with writing plugins to get it functioning exactly how you want it! Head on over to the :ref:`plugins <plugins>` page to get started.

Getting your bot running is only the beginning. The real fun begins with
writing plugins to get it functioning exactly how you want it! Head on over
to the :ref:`plugins <plugins>` page to get started.

Fetch mmpy_bot version
####################
To check your installed version of `mmpy_bot`, simply open a Python interpreter and run the following commands:
######################

To check your installed version of `mmpy_bot`, simply open a Python
interpreter and run the following commands:

.. code-block:: python
Expand Down
Loading

0 comments on commit 9aeb196

Please sign in to comment.