@@ -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
4345class Color :
@@ -55,7 +57,7 @@ class Color:
5557
5658
5759class 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
7173def _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
7678def 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):
8789def 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
103107def 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):
114118def 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():
127131def 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