forked from jamescooke/flake8-aaa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new --aaa-act-block-style option with default behaviour (jamescoo…
…ke#213) * Add faker to test requirements * Add helper for flattening list of allowed values * Add exception for handling bad config: UnexpectedConfigValue * Improve typing on classmethods on Config and ActBlockStyle * Remove default_config fixture and use Config.default_options() instead * Pass act_block_style setting to Function.mark_act() method * Pass act_block_style from Function to Block when building Act block * Split command / control doc, add options doc page * Adjust make docs recipe to use tox * Update docs: add options / config page, split out directives page * Fix lint: remove empty list from test and pass directly * Bump GHA step versions, set devpi server as default for pip in tox * Add type hint for Faker fixture in tests * Expand meta plugin tox envs to add a run with a cmd line option * Add tox env for testing config, split out dogfood env * Adjust examples so they run with default flake8 config * Bump example requirements for mypy bug * Update CHANGELOG
- Loading branch information
1 parent
31d6e0c
commit 56964e2
Showing
46 changed files
with
640 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
aaa_act_block_style = default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Directives | ||
========== | ||
|
||
Flake8-AAA can be controlled using some special directives in the form of | ||
comments in your test code. | ||
|
||
Explicitly marking blocks | ||
------------------------- | ||
|
||
One can set the act block explicitly using the ``# act`` comment. This is | ||
necessary when there is no assignment possible. | ||
|
||
See :ref:`AAA01: no Act block found in test - Correct code 2 <aaa01-correct-code-2>`. | ||
|
||
Disabling Flake8-AAA selectively | ||
-------------------------------- | ||
|
||
When invoked via Flake8, Flake8 will filter any errors raised when lines are | ||
marked with the ``# noqa`` syntax. You can turn off all errors from Flake8-AAA | ||
by marking a line with ``# noqa: AAA`` and other Flake8 errors will still be | ||
returned. | ||
|
||
If you just want to ignore a particular error, then you can use the more | ||
specific code and indicate the exact error to be ignored. For example, to | ||
ignore the check for a space before the Act block, we can mark the Act block | ||
with ``# noqa: AAA03``:: | ||
|
||
def test(): | ||
x = 1 | ||
result = x + 1 # noqa: AAA03 | ||
|
||
assert result == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Options and configuration | ||
========================= | ||
|
||
Flake8 can be invoked with ``--`` options *and* can read values from project | ||
configuration files. | ||
|
||
All names of Flake8-AAA's options and configuration values are prefixed with | ||
"aaa". E.g. ``--aaa-act-block-style``. | ||
|
||
Act block style | ||
--------------- | ||
|
||
Command line flag | ||
``--aaa-act-block-style`` | ||
|
||
Configuration option | ||
``aaa_act_block_style`` | ||
|
||
The Act block style option adjusts how Flake8-AAA builds the Act block from the | ||
Act node. | ||
|
||
The allowed value is "default". | ||
|
||
In default mode the Act block is the single Act node, best demonstrated by | ||
example: | ||
|
||
.. code-block:: python | ||
result = do_thing() | ||
Or... | ||
|
||
.. code-block:: python | ||
with pytest.raises(ValueError): | ||
do_thing() | ||
The important feature of default Act blocks is that they do not contain any | ||
context managers other than pytest or unittest ones. | ||
|
||
.. code-block:: python | ||
def test_with(): | ||
a_class = AClass() | ||
with freeze_time("2021-02-02 12:00:02"): | ||
result = a_class.action('test') | ||
assert result == 'test' | ||
In the example above, Flake8-AAA considers the ``with freeze_time()`` context | ||
manager to be in the Arrange block. It therefore expects a blank line between | ||
it and the ``result =`` Act block. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
def test_specific(): # noqa: AAA01 | ||
import pathlib | ||
|
||
|
||
def test_specific() -> None: # noqa: AAA01 | ||
assert 1 + 1 == 2 | ||
|
||
|
||
def test_multi_line_args_specific(math_fixture, *args, **kwargs): # noqa: AAA01 | ||
def test_multi_line_args_specific( # noqa: AAA01 | ||
tmp_path: pathlib.Path, | ||
*args, | ||
**kwargs, | ||
) -> None: | ||
assert 1 + 1 == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
def test_specific(): # noqa: AAA01 | ||
import pathlib | ||
|
||
|
||
def test_specific() -> None: # noqa: AAA01 | ||
assert 1 + 1 == 2 | ||
|
||
|
||
def test_multi_line_args_specific( # noqa: AAA01 | ||
math_fixture, | ||
tmp_path: pathlib.Path, | ||
*args, | ||
**kwargs | ||
): | ||
**kwargs, | ||
) -> None: | ||
assert 1 + 1 == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.