-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from jamescooke/aaa03
AAA03 (space between Arrange and Act)
- Loading branch information
Showing
19 changed files
with
367 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ArrangeBlock: | ||
""" | ||
Attributes: | ||
nodes (list (ast Node)) | ||
""" | ||
|
||
def __init__(self): | ||
self.nodes = [] | ||
|
||
def add_node(self, node): | ||
self.nodes.append(node) |
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
Empty file.
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,16 @@ | ||
import pytest | ||
|
||
from flake8_aaa.arrange_block import ArrangeBlock | ||
|
||
|
||
@pytest.mark.parametrize('code_str', [''' | ||
def test(): | ||
pass | ||
''']) | ||
def test(first_node_with_tokens): | ||
arrange_block = ArrangeBlock() | ||
|
||
result = arrange_block.add_node(first_node_with_tokens) | ||
|
||
assert result is None | ||
assert arrange_block.nodes == [first_node_with_tokens] |
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,7 @@ | ||
from flake8_aaa.arrange_block import ArrangeBlock | ||
|
||
|
||
def test(): | ||
result = ArrangeBlock() | ||
|
||
assert result.nodes == [] |
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
Empty file.
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,16 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize('code_str', [""" | ||
def test(): | ||
pass | ||
"""]) | ||
def test_lines(lines): | ||
result = lines | ||
|
||
assert result == [ | ||
'\n', | ||
'def test():\n', | ||
' pass\n', | ||
'\n', | ||
] |
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,61 @@ | ||
import pytest | ||
|
||
from flake8_aaa.exceptions import ValidationError | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code_str', | ||
[''' | ||
def test(): | ||
result = 1 | ||
assert result == 1 | ||
'''], | ||
ids=['no arrange'], | ||
) | ||
def test_no_arrange(function_with_arrange_act_blocks): | ||
result = function_with_arrange_act_blocks.check_act_arrange_spacing() | ||
|
||
assert result is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code_str', | ||
[''' | ||
def test(): | ||
x = 1 | ||
y = 2 | ||
result = x + y | ||
assert result == 3 | ||
'''], | ||
ids=['well spaced test'], | ||
) | ||
def test_has_act_block_good_spacing(function_with_arrange_act_blocks): | ||
result = function_with_arrange_act_blocks.check_act_arrange_spacing() | ||
|
||
assert result is None | ||
|
||
|
||
# --- FAILURES --- | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code_str', | ||
[''' | ||
def test(): | ||
x = 1 | ||
y = 2 | ||
result = x + y | ||
assert result == 3 | ||
'''], | ||
ids=['compact test'], | ||
) | ||
def test_missing_leading_space(function_with_arrange_act_blocks): | ||
with pytest.raises(ValidationError) as excinfo: | ||
function_with_arrange_act_blocks.check_act_arrange_spacing() | ||
|
||
assert excinfo.value.line_number == 5 | ||
assert excinfo.value.offset == 4 | ||
assert excinfo.value.text.startswith('AAA03 ') |
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,13 +1,46 @@ | ||
import pytest | ||
|
||
from flake8_aaa.exceptions import ValidationError | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code_str', [ | ||
'code_str', | ||
[ | ||
'def test():\n pass', | ||
'def test_docstring():\n """This test will work great"""', | ||
] | ||
], | ||
ids=['pass', 'docstring'], | ||
) | ||
def test_noop(function): | ||
result = function.check_all() | ||
|
||
assert result is None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code_str', | ||
[ | ||
''' | ||
def test(file_resource): | ||
file_resource.connect() | ||
result = file_resource.retrieve() | ||
assert result.success is True | ||
''', | ||
''' | ||
def test_push(queue): | ||
item = Document() | ||
queue.push(item) # act | ||
assert queue.pop() == item | ||
''', | ||
], | ||
ids=['no line before result= act', 'no line before marked act'], | ||
) | ||
def test_missing_space_before_act(function): | ||
with pytest.raises(ValidationError) as excinfo: | ||
function.check_all() | ||
|
||
assert excinfo.value.line_number == 4 | ||
assert excinfo.value.offset == 4 | ||
assert excinfo.value.text == 'AAA03 expected 1 blank line before Act block, found none' |
Oops, something went wrong.