Skip to content

Commit 55bfc10

Browse files
authored
Add pycodestyle and pydocstyle to CI (#38)
* Add pycodestyle and pydocstyle to CI - Fixed existing PEP8 and docstring violations - Added pycodestyle and pydocstyle to GitHub Actions workflow - Enforce strict style checks on delayed_assert/ package Fixes #28 * Trigger CI
1 parent 16e30a0 commit 55bfc10

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

.github/workflows/python-package.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ jobs:
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
30-
python -m pip install flake8 pytest pytest-xdist
30+
python -m pip install flake8 pytest pytest-xdist pycodestyle pydocstyle
3131
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3232
- name: Lint with flake8
3333
run: |
3434
# stop the build if there are Python syntax errors or undefined names
3535
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3636
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3737
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38+
- name: Lint with pycodestyle and pydocstyle
39+
run: |
40+
pycodestyle delayed_assert/
41+
pydocstyle delayed_assert/
3842
- name: Run test
3943
run: |
4044
pytest -n auto

delayed_assert/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Expose public API for delayed-assert."""
12
from .delayed_assert import (
23
expect, assert_expectations,
34
test_case,

delayed_assert/delayed_assert.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def test_should_fail():
3737
# Global flag to control colorization
3838
# Can be controlled via environment variable DELAYED_ASSERT_ENABLE_COLOR
3939
# or programmatically via set_color_enabled()
40-
_color_enabled = os.environ.get('DELAYED_ASSERT_ENABLE_COLOR', '1').lower() not in ('0', 'false', 'no', 'off')
40+
_color_enabled = os.environ.get(
41+
'DELAYED_ASSERT_ENABLE_COLOR', '1'
42+
).lower() not in ('0', 'false', 'no', 'off')
4143

4244

4345
class Color:
@@ -55,7 +57,7 @@ class Color:
5557

5658

5759
class NoColor:
58-
"""No-color definition - all attributes return empty strings."""
60+
"""Colors definition without ANSI escape codes (for disabled colors)."""
5961

6062
HEADER = ''
6163
OKBLUE = ''
@@ -69,14 +71,14 @@ class NoColor:
6971

7072

7173
def _get_color_instance():
72-
"""Get the appropriate color instance based on the enabled flag."""
74+
"""Return the appropriate Color class based on _color_enabled flag."""
7375
return Color if _color_enabled else NoColor
7476

7577

7678
def set_color_enabled(enabled):
7779
"""
7880
Enable or disable color output.
79-
81+
8082
Args:
8183
enabled (bool): True to enable colors, False to disable
8284
"""
@@ -87,7 +89,7 @@ def set_color_enabled(enabled):
8789
def get_color_enabled():
8890
"""
8991
Get the current color enabled status.
90-
92+
9193
Returns:
9294
bool: True if colors are enabled, False otherwise
9395
"""
@@ -97,13 +99,15 @@ def get_color_enabled():
9799
# Global flag to control caller verification
98100
# Can be controlled via environment variable DELAYED_ASSERT_CHECK_CALLER
99101
# or programmatically via set_check_caller()
100-
_check_caller = os.environ.get('DELAYED_ASSERT_CHECK_CALLER', '1').lower() not in ('0', 'false', 'no', 'off')
102+
_check_caller = os.environ.get(
103+
'DELAYED_ASSERT_CHECK_CALLER', '1'
104+
).lower() not in ('0', 'false', 'no', 'off')
101105

102106

103107
def set_check_caller(enabled):
104108
"""
105109
Enable or disable caller verification.
106-
110+
107111
Args:
108112
enabled (bool): True to enable caller verification, False to disable
109113
"""
@@ -114,7 +118,7 @@ def set_check_caller(enabled):
114118
def get_check_caller():
115119
"""
116120
Get the current caller verification status.
117-
121+
118122
Returns:
119123
bool: True if caller verification is enabled, False otherwise
120124
"""
@@ -127,6 +131,7 @@ def get_check_caller():
127131
def test_case(func):
128132
"""
129133
Decorator to mark a function as a test case.
134+
130135
This allows using expect() in functions that don't start with 'test'.
131136
"""
132137
@functools.wraps(func)
@@ -151,9 +156,9 @@ def _log_failure(msg=None):
151156
file_path, line, funcname, contextlist = inspect.stack()[2][1:5]
152157
context = contextlist[0]
153158
_failed_expectations.append(
154-
color.FAIL+'Failed at "' + color.ENDC + color.OKBLUE + color.UNDERLINE
155-
+ '%s:%s' % (file_path, line) + color.ENDC + color.FAIL +
156-
'", in %s()%s\n%s' % (
159+
color.FAIL + 'Failed at "' + color.ENDC + color.OKBLUE +
160+
color.UNDERLINE + '%s:%s' % (file_path, line) + color.ENDC +
161+
color.FAIL + '", in %s()%s\n%s' % (
157162
funcname,
158163
('\n\t' + color.BOLD + color.UNDERLINE + 'ErrorMessage:' +
159164
color.ENDC + color.FAIL + '\t%s' % msg + color.ENDC),
@@ -201,8 +206,8 @@ def expect(expr, msg=None):
201206
if caller == '':
202207
if _check_caller:
203208
raise Exception(
204-
'Could not identify test method, make sure the call for "expect" '
205-
'method is originated with "test" method')
209+
'Could not identify test method, make sure the call for '
210+
'"expect" method is originated with "test" method')
206211

207212
if _is_first_call.get(caller, True):
208213
_failed_expectations = []
@@ -213,8 +218,8 @@ def expect(expr, msg=None):
213218
if isinstance(expr, types.FunctionType):
214219
try:
215220
expr()
216-
except Exception as exc:
217-
_log_failure(exc)
221+
except Exception as e:
222+
_log_failure(e)
218223
elif not expr:
219224
_log_failure(msg)
220225

0 commit comments

Comments
 (0)