Skip to content

Commit

Permalink
Merge pull request #19 from jamescooke/docs
Browse files Browse the repository at this point in the history
Add RTD
  • Loading branch information
jamescooke committed May 27, 2018
2 parents 47893db + 39b6e56 commit 4caef49
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ venv/
# Custom: python2 venv
venv2/

# Sphinx documentation
docs/_build/

# isort
/isort.out
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lint_files=setup.py flake8_aaa tests
rst_files=README.rst CHANGELOG.rst
rst_files=README.rst CHANGELOG.rst docs/discovery.rst docs/rules.rst

venv:
virtualenv venv --python=python3
Expand Down Expand Up @@ -31,6 +31,7 @@ lint:
@echo "=== setup.py ==="
python setup.py check --metadata --strict


.PHONY: fixlint
fixlint:
@echo "=== fixing isort ==="
Expand All @@ -39,6 +40,11 @@ fixlint:
yapf --recursive --in-place $(lint_files)


.PHONY: doc
doc:
$(MAKE) -C docs html


# --- Building / Publishing ---

.PHONY: clean
Expand Down
84 changes: 24 additions & 60 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@
:target: https://travis-ci.org/jamescooke/flake8-aaa/branches
:alt: Travis build

.. image:: https://img.shields.io/readthedocs/flake8-aaa.svg
:alt: Read the Docs
:target: https://flake8-aaa.readthedocs.io/

flake8-aaa plugin
=================
.. image:: https://img.shields.io/pypi/v/flake8-aaa.svg
:alt: PyPI
:target: https://pypi.org/project/flake8-aaa/

.. image:: https://img.shields.io/pypi/pyversions/flake8-aaa.svg
:alt: PyPI - Python Version
:target: https://pypi.org/project/flake8-aaa/

.. image:: https://img.shields.io/github/license/jamescooke/flake8-aaa.svg
:alt: flake8-aaa is licensed under the MIT License
:target: https://github.com/jamescooke/flake8-aaa/blob/master/LICENSE


flake8-aaa
==========

A `flake8 <http://flake8.pycqa.org/en/latest/index.html>`_ plugin for linting
Python tests against the rules of the `Arrange Act Assert pattern
Expand All @@ -14,66 +30,14 @@ of testing.
Resources
---------

* `Changelog <CHANGELOG.rst>`_


Docs
====

(to be extracted to RTD)


Test discovery
--------------

* Filename must start with ``test_`` and have been collected for linting by
``flake8``.

* Test must be a function where its name starts with ``test``.

* Tests that contain only comments, docstrings or ``pass`` are skipped.


Error codes
-----------

AAA01: no Act block found in test
:::::::::::::::::::::::::::::::::

Test found to have no Act block.

An Act block is usually a line like ``result =`` or a check that an exception
is raised using ``with pytest.raises(Exception):``.

Resolution
..........

Add an Act block to the test or mark a line that should be considered the
action.

Even if the result of a test action is ``None``, assign that result and test
it::

result = action()

assert result is None

If you can't set a ``result``, then mark the end of the line considered the Act
block with ``# act`` (case insensitive)::

data['new_key'] = 1 # act
* `Documentation on ReadTheDocs <https://flake8-aaa.readthedocs.io/>`_

AAA02: multiple Act blocks found in test
::::::::::::::::::::::::::::::::::::::::
* `Package on PyPI <https://pypi.org/project/flake8-aaa/>`_

There must be one and only one Act block in every test. The linter found more
than one potential Act block in this test.
* `Source code on GitHub <https://github.com/jamescooke/flake8-aaa>`_

A test that contains more than one ``result =`` statement or more than one line
marked ``# act`` creates ambiguity and raises this error code.
* `Licensed on MIT <https://github.com/jamescooke/flake8-aaa/blob/master/LICENSE>`_

Resolution
..........
* `Changelog <https://github.com/jamescooke/blob/master/CHANGELOG.rst>`_

Splitting the failing test into multiple tests. Where there is complicated or
reused set-up code then that should be extracted into fixtures.
Tested on Pythons 2.7 and 3.6.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = Flake8-AAA
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
153 changes: 153 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# -*- coding: utf-8 -*-

# -- Path setup --------------------------------------------------------------

import os
import sys

# Base directory of project
basedir = os.path.dirname(os.path.dirname(__file__))

sys.path.insert(0, basedir)

# --- Load __about__ info ----------------------------------------------------

about = {}
with open(os.path.join(basedir, 'flake8_aaa', '__about__.py')) as f:
exec(f.read(), about)

# -- Project information -----------------------------------------------------

project = about['__name__']
copyright = about['__copyright__']
author = about['__author__']

# Version == release (strategy copied from Warehouse)
version = release = about['__version__']

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.napoleon',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}

# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Flake8-AAAdoc'

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(
master_doc,
'flake8-aaa.tex',
'{} Documentation'.format(project),
author,
'manual',
),
]

# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, 'flake8-aaa', '{} Documentation'.format(project), [author], 1)]

# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(
master_doc,
project,
'{} Documentation'.format(project),
author,
'Flake8-AAA',
about['__description__'],
'Miscellaneous',
),
]
9 changes: 9 additions & 0 deletions docs/discovery.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Test discovery
==============

* Filename must start with ``test_`` and have been collected for linting by
``flake8``.

* Test must be a function where its name starts with ``test``.

* Tests that contain only comments, docstrings or ``pass`` are skipped.
11 changes: 11 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Welcome to Flake8-AAA's documentation!
======================================

.. include:: ../README.rst

.. toctree::
:maxdepth: 2
:caption: Contents:

discovery
rules
43 changes: 43 additions & 0 deletions docs/rules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Rules and error codes
=====================

AAA01: no Act block found in test
---------------------------------

Test found to have no Act block.

An Act block is usually a line like ``result =`` or a check that an exception
is raised using ``with pytest.raises(Exception):``.

Resolution
..........

Add an Act block to the test or mark a line that should be considered the
action.

Even if the result of a test action is ``None``, assign that result and pint it
with a test::

result = action()

assert result is None

If you can not assign a ``result``, then mark the end of the line considered
the Act block with ``# act`` (case insensitive)::

data['new_key'] = 1 # act

AAA02: multiple Act blocks found in test
----------------------------------------

There must be one and only one Act block in every test. The linter found more
than one potential Act block in this test.

A test that contains more than one ``result =`` statement or more than one line
marked ``# act`` creates ambiguity and raises this error code.

Resolution
..........

Splitting the failing test into multiple tests. Where there is complicated or
reused set-up code then that should be extracted into one or more fixtures.

0 comments on commit 4caef49

Please sign in to comment.