5656from .snapshot import SnapshotMixin
5757from .string import StringMixin
5858
59- __version__ = ' 2.0.0'
59+ __version__ = " 2.0.0"
6060
6161__tracebackhide__ = True # clean tracebacks via py.test integration
6262contextlib .__tracebackhide__ = True # monkey patch contextlib with clean py.test tracebacks
6363
6464# assertpy files
65- ASSERTPY_FILES = [os .path .join ('assertpy2' , file ) for file in [
66- 'assertpy.py' ,
67- 'base.py' ,
68- 'collection.py' ,
69- 'contains.py' ,
70- 'date.py' ,
71- 'dict.py' ,
72- 'dynamic.py' ,
73- 'exception.py' ,
74- 'extracting.py' ,
75- 'file.py' ,
76- 'helpers.py' ,
77- 'numeric.py' ,
78- 'snapshot.py' ,
79- 'string.py'
80- ]]
65+ ASSERTPY_FILES = [
66+ os .path .join ("assertpy2" , file )
67+ for file in [
68+ "assertpy.py" ,
69+ "base.py" ,
70+ "collection.py" ,
71+ "contains.py" ,
72+ "date.py" ,
73+ "dict.py" ,
74+ "dynamic.py" ,
75+ "exception.py" ,
76+ "extracting.py" ,
77+ "file.py" ,
78+ "helpers.py" ,
79+ "numeric.py" ,
80+ "snapshot.py" ,
81+ "string.py" ,
82+ ]
83+ ]
8184
8285# soft assertions
8386_soft_ctx = 0
@@ -136,13 +139,13 @@ def soft_assertions() -> Iterator[None]:
136139 _soft_ctx -= 1
137140
138141 if _soft_err and _soft_ctx == 0 :
139- out = ' soft assertion failures:\n ' + ' \n ' .join (' %d. %s' % (i + 1 , msg ) for i , msg in enumerate (_soft_err ))
142+ out = " soft assertion failures:\n " + " \n " .join (" %d. %s" % (i + 1 , msg ) for i , msg in enumerate (_soft_err ))
140143 _soft_err = []
141144 raise AssertionError (out )
142145
143146
144147# factory methods
145- def assert_that (val , description = '' ):
148+ def assert_that (val , description = "" ):
146149 """Set the value to be tested, plus an optional description, and allow assertions to be called.
147150
148151 This is a factory method for the :class:`AssertionBuilder`, and the single most important
@@ -165,11 +168,11 @@ def test_something():
165168 """
166169 global _soft_ctx
167170 if _soft_ctx :
168- return _builder (val , description , ' soft' )
171+ return _builder (val , description , " soft" )
169172 return _builder (val , description )
170173
171174
172- def assert_warn (val , description = '' , logger = None ):
175+ def assert_warn (val , description = "" , logger = None ):
173176 """Set the value to be tested, and optional description and logger, and allow assertions to be
174177 called, but never fail, only log warnings.
175178
@@ -211,10 +214,10 @@ def assert_warn(val, description='', logger=None):
211214 Use :meth:`assert_warn` if and only if you have a *really* good reason to log assertion
212215 failures instead of failing.
213216 """
214- return _builder (val , description , ' warn' , logger = logger )
217+ return _builder (val , description , " warn" , logger = logger )
215218
216219
217- def fail (msg = '' ):
220+ def fail (msg = "" ):
218221 """Force immediate test failure with the given message.
219222
220223 Args:
@@ -239,10 +242,10 @@ def test_adder_bad_arg():
239242 except TypeError as e:
240243 assert_that(str(e)).contains('unsupported operand')
241244 """
242- raise AssertionError (' Fail: %s!' % msg if msg else ' Fail!' )
245+ raise AssertionError (" Fail: %s!" % msg if msg else " Fail!" )
243246
244247
245- def soft_fail (msg = '' ):
248+ def soft_fail (msg = "" ):
246249 """Within a :meth:`soft_assertions` context, append the failure message to the soft error list,
247250 but do not halt test execution.
248251
@@ -273,7 +276,7 @@ def soft_fail(msg=''):
273276 global _soft_ctx
274277 if _soft_ctx :
275278 global _soft_err
276- _soft_err .append (' Fail: %s!' % msg if msg else ' Fail!' )
279+ _soft_err .append (" Fail: %s!" % msg if msg else " Fail!" )
277280 return
278281 fail (msg )
279282
@@ -311,7 +314,7 @@ def test_6():
311314 # 6 is NOT 5!
312315 """
313316 if not callable (func ):
314- raise TypeError (' func must be callable' )
317+ raise TypeError (" func must be callable" )
315318 _extensions [func .__name__ ] = func
316319
317320
@@ -329,12 +332,12 @@ def remove_extension(func):
329332 remove_extension(is_5)
330333 """
331334 if not callable (func ):
332- raise TypeError (' func must be callable' )
335+ raise TypeError (" func must be callable" )
333336 if func .__name__ in _extensions :
334337 del _extensions [func .__name__ ]
335338
336339
337- def _builder (val , description = '' , kind = None , expected = None , logger = None ):
340+ def _builder (val , description = "" , kind = None , expected = None , logger = None ):
338341 """Internal helper to build a new :class:`AssertionBuilder` instance and glue on any extension methods."""
339342 ab = AssertionBuilder (val , description , kind , expected , logger )
340343 if _extensions :
@@ -366,13 +369,13 @@ def _unwind(frame):
366369 prev = frame
367370
368371 filename , lineno = _unwind (inspect .currentframe ())
369- return ' [%s:%d]: %s' % (os .path .basename (filename ), lineno , msg ), kwargs
372+ return " [%s:%d]: %s" % (os .path .basename (filename ), lineno , msg ), kwargs
370373
371374
372- _logger = logging .getLogger (' assertpy2' )
375+ _logger = logging .getLogger (" assertpy2" )
373376_handler = logging .StreamHandler (sys .stdout )
374377_handler .setLevel (logging .WARNING )
375- _format = logging .Formatter (' %(asctime)s %(levelname)s %(message)s' , datefmt = ' %Y-%m-%d %H:%M:%S' )
378+ _format = logging .Formatter (" %(asctime)s %(levelname)s %(message)s" , datefmt = " %Y-%m-%d %H:%M:%S" )
376379_handler .setFormatter (_format )
377380_logger .addHandler (_handler )
378381_default_logger = WarningLoggingAdapter (_logger , None )
@@ -391,7 +394,7 @@ class AssertionBuilder(
391394 DateMixin ,
392395 ContainsMixin ,
393396 CollectionMixin ,
394- BaseMixin
397+ BaseMixin ,
395398):
396399 """The main assertion class. Never call the constructor directly, always use the
397400 :meth:`assert_that` helper instead. Or if you just want warning messages, use the
@@ -407,15 +410,15 @@ class AssertionBuilder(
407410 logger (Logger, optional): the logger for warning messages. Defaults to ``None``
408411 """
409412
410- def __init__ (self , val , description = '' , kind = None , expected = None , logger = None ):
413+ def __init__ (self , val , description = "" , kind = None , expected = None , logger = None ):
411414 """Never call this constructor directly."""
412415 self .val = val
413416 self .description = description
414417 self .kind = kind
415418 self .expected = expected
416419 self .logger = logger if logger else _default_logger
417420
418- def builder (self , val , description = '' , kind = None , expected = None , logger = None ):
421+ def builder (self , val , description = "" , kind = None , expected = None , logger = None ):
419422 """Helper to build a new :class:`AssertionBuilder` instance. Use this only if not chaining to ``self``.
420423
421424 Args:
@@ -453,11 +456,11 @@ def error(self, msg) -> Self:
453456 AssertionBuilder: returns this instance to chain to the next assertion, but only when
454457 ``AssertionError`` is not raised, as is the case when ``kind`` is ``warn`` or ``soft``.
455458 """
456- out = ' %s%s' % (' [%s] ' % self .description if len (self .description ) > 0 else '' , msg )
457- if self .kind == ' warn' :
459+ out = " %s%s" % (" [%s] " % self .description if len (self .description ) > 0 else "" , msg )
460+ if self .kind == " warn" :
458461 self .logger .warning (out )
459462 return self
460- elif self .kind == ' soft' :
463+ elif self .kind == " soft" :
461464 global _soft_err
462465 _soft_err .append (out )
463466 return self
0 commit comments