Skip to content

Commit

Permalink
Additional Pycodestyle Checker Tests - E304, 303, 301, 275, 266 (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
lana-w committed May 30, 2024
1 parent 921a9ea commit 92e5acd
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ list only contains the Pylint checkers enabled by default in PythonTA.
- Updated changelog and pull request template formats
- Added unit tests for PEP8 errors E115, E122, E125, E127, E129, E131 for `PycodestyleChecker`
- Added unit tests for PEP8 errors E223, E224, E227, E228, E265 for `PycodestyleChecker`
- Added unit tests for PEP8 errors E266, E275, E301, E303, E304 for `PycodestyleChecker`
- Updated `README.md` to reflect updated folder structure

## [2.7.0] - 2024-12-14
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Alexey Strokach,
Sophy Sun,
Utku Egemen Umut,
Sarah Wang,
Lana Wehbeh,
Jasmine Wu,
Raine Yang,
Philippe Yu,
Expand Down
1 change: 1 addition & 0 deletions examples/custom_checkers/e9989_pycodestyle/e266_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## This is a comment with too many leading '#'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a comment without too many leading '#'
1 change: 1 addition & 0 deletions examples/custom_checkers/e9989_pycodestyle/e275_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from math import(lcm)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from math import lcm
6 changes: 6 additions & 0 deletions examples/custom_checkers/e9989_pycodestyle/e301_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Example:

def getTrue(self):
return True
def getFalse(self):
return False
7 changes: 7 additions & 0 deletions examples/custom_checkers/e9989_pycodestyle/e301_no_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Example:

def getTrue(self):
return True

def getFalse(self):
return False
7 changes: 7 additions & 0 deletions examples/custom_checkers/e9989_pycodestyle/e303_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def func1():
return True



def func2():
return False
6 changes: 6 additions & 0 deletions examples/custom_checkers/e9989_pycodestyle/e303_no_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def func1():
return True


def func2():
return False
13 changes: 13 additions & 0 deletions examples/custom_checkers/e9989_pycodestyle/e304_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

def decor(func):
def inner():
x = func()
return 2 * x

return inner


@decor

def num():
return 10
12 changes: 12 additions & 0 deletions examples/custom_checkers/e9989_pycodestyle/e304_no_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

def decor(func):
def inner():
x = func()
return 2 * x

return inner


@decor
def num():
return 10
100 changes: 100 additions & 0 deletions tests/test_custom_checkers/test_pycodestyle_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,103 @@ def test_no_error_e129(self) -> None:
mod = MANAGER.ast_from_file(DIR_PATH + "e129_no_error.py")
with self.assertNoMessages():
self.checker.process_module(mod)

def test_error_e266(self) -> None:
"""Test that PEP8 error E266 (too many leading '#' for block comment) triggers"""
mod = MANAGER.ast_from_file(DIR_PATH + "e266_error.py")
with self.assertAddsMessages(
pylint.testutils.MessageTest(
msg_id="pep8-errors",
line=1,
node=None,
args=("E266", "line 1, column 0: too many leading '#' for block comment"),
),
ignore_position=True,
):
self.checker.process_module(mod)

def test_no_error_e266(self) -> None:
"""Test that PEP8 error E266 (too many leading '#' for block comment) is not triggered"""
mod = MANAGER.ast_from_file(DIR_PATH + "e266_no_error.py")
with self.assertNoMessages():
self.checker.process_module(mod)

def test_error_e275(self) -> None:
"""Test that PEP8 error E275 (missing whitespace after keyword) triggers"""
mod = MANAGER.ast_from_file(DIR_PATH + "e275_error.py")
with self.assertAddsMessages(
pylint.testutils.MessageTest(
msg_id="pep8-errors",
line=1,
node=None,
args=("E275", "line 1, column 16: missing whitespace after keyword"),
),
ignore_position=True,
):
self.checker.process_module(mod)

def test_no_error_e275(self) -> None:
"""Test that PEP8 error E275 (missing whitespace after keyword) is not triggered"""
mod = MANAGER.ast_from_file(DIR_PATH + "e275_no_error.py")
with self.assertNoMessages():
self.checker.process_module(mod)

def test_error_e301(self) -> None:
"""Test that PEP8 error E301 (expected 1 blank line, found 0) triggers"""
mod = MANAGER.ast_from_file(DIR_PATH + "e301_error.py")
with self.assertAddsMessages(
pylint.testutils.MessageTest(
msg_id="pep8-errors",
line=6,
node=None,
args=("E301", "line 5, column 4: expected 1 blank line, found 0"),
),
ignore_position=True,
):
self.checker.process_module(mod)

def test_no_error_e301(self) -> None:
"""Test that PEP8 error E301 (expected 1 blank line, found 0) is not triggered"""
mod = MANAGER.ast_from_file(DIR_PATH + "e301_no_error.py")
with self.assertNoMessages():
self.checker.process_module(mod)

def test_error_e303(self) -> None:
"""Test that PEP8 error E303 (Too many blank lines (3)) triggers"""
mod = MANAGER.ast_from_file(DIR_PATH + "e303_error.py")
with self.assertAddsMessages(
pylint.testutils.MessageTest(
msg_id="pep8-errors",
line=6,
node=None,
args=("E303", "line 6, column 0: too many blank lines (3)"),
),
ignore_position=True,
):
self.checker.process_module(mod)

def test_no_error_e303(self) -> None:
"""Test that PEP8 error E303 (too many blank lines (3)) is not triggered"""
mod = MANAGER.ast_from_file(DIR_PATH + "e303_no_error.py")
with self.assertNoMessages():
self.checker.process_module(mod)

def test_error_e304(self) -> None:
"""Test that PEP8 error E304 (Blank line found after function decorator) triggers"""
mod = MANAGER.ast_from_file(DIR_PATH + "e304_error.py")
with self.assertAddsMessages(
pylint.testutils.MessageTest(
msg_id="pep8-errors",
line=12,
node=None,
args=("E304", "line 12, column 0: blank lines found after function decorator"),
),
ignore_position=True,
):
self.checker.process_module(mod)

def test_no_error_e304(self) -> None:
"""Test that PEP8 error E304 (Blank line found after function decorator) is not triggered"""
mod = MANAGER.ast_from_file(DIR_PATH + "e304_no_error.py")
with self.assertNoMessages():
self.checker.process_module(mod)

0 comments on commit 92e5acd

Please sign in to comment.