Skip to content

Commit

Permalink
Merge pull request #14 from jamescooke/first-raises-only
Browse files Browse the repository at this point in the history
Allow `pytest.raises` in Assert blocks
  • Loading branch information
jamescooke committed May 27, 2018
2 parents 8822185 + 645d000 commit 47893db
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
6 changes: 6 additions & 0 deletions flake8_aaa/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def parse(self):
except NotActionBlock:
continue

# Allow `pytest.raises` in assert blocks
if len(self.act_blocks) > 1:
self.act_blocks = [self.act_blocks[0]] + list(
filter(lambda ab: ab.block_type != ActBlock.PYTEST_RAISES, self.act_blocks[1:])
)

self.parsed = True
return len(self.act_blocks)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ not_skip=__init__.py
max-line-length = 120

[yapf]
# coalesce_brackets = true
dedent_closing_brackets = true
column_limit = 120
19 changes: 16 additions & 3 deletions tests/function/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@ def test_noop(function):
assert result == []


@pytest.mark.parametrize('code_str', ['''
@pytest.mark.parametrize(
'code_str', [
'''
def test():
result = 1
assert result == 1
'''])
''',
'''
def test(existing_user):
result = existing_user.delete()
assert result is True
assert result.retrieved is False
with pytest.raises(DoesNotExist):
result.retrieve()
''',
]
)
def test_result_assigned(function):
function.parse()

Expand Down Expand Up @@ -51,7 +64,7 @@ def test():
x = 1 + 1 # act
assert x == 2
'''])
def test_no_qa(function):
def test_act(function):
function.parse()

result = function.check()
Expand Down
24 changes: 24 additions & 0 deletions tests/function/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from flake8_aaa.act_block import ActBlock


@pytest.mark.parametrize('code_str', ['def test():\n pass'])
def test_none(function):
Expand Down Expand Up @@ -45,3 +47,25 @@ def test_multi(function):
assert result == 2
assert function.parsed is True
assert function.is_noop is False


@pytest.mark.parametrize(
'code_str', [
'''
def test(existing_user):
result = existing_user.delete()
assert result is True
assert result.retrieved is False
with pytest.raises(DoesNotExist):
result.retrieve()
'''
]
)
def test(function):
result = function.parse()

assert result == 1
assert function.parsed is True
assert function.is_noop is False
assert function.act_blocks[0].block_type == ActBlock.RESULT_ASSIGNMENT
8 changes: 8 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@

# Some unicode text: Réne has £10 - ensure that this file is loaded with Python 2

import os

import pytest

from flake8_aaa.__about__ import __version__

skip_not_tox = pytest.mark.skipif(not os.getenv('IN_TOX', False), reason='Not running inside Tox')


@skip_not_tox
def test_installed(flake8dir):
result = flake8dir.run_flake8(extra_args=['--version'])

assert 'aaa: {}'.format(__version__) in result.out


@skip_not_tox
def test(flake8dir):
flake8dir.make_py_files(
test_plus='''
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ commands =
install: flake8 --version
test: pytest
lint: make lint
setenv = IN_TOX = 1
whitelist_externals = make

0 comments on commit 47893db

Please sign in to comment.