1616]
1717
1818import operator
19- from pprint import pformat
2019import re
20+ from pprint import pformat
2121
2222from ..compat import (
2323 text_repr ,
3434
3535
3636def _format (thing ):
37- """
38- Blocks of text with newlines are formatted as triple-quote
37+ """Blocks of text with newlines are formatted as triple-quote
3938 strings. Everything else is pretty-printed.
4039 """
4140 if isinstance (thing , (str , bytes )):
@@ -74,8 +73,10 @@ def describe(self):
7473 actual = repr (self ._actual )
7574 reference = repr (self ._reference )
7675 if len (actual ) + len (reference ) > 70 :
77- return "{}:\n reference = {}\n actual = {}\n " .format (
78- self ._mismatch_string , _format (self ._reference ), _format (self ._actual )
76+ return (
77+ f"{ self ._mismatch_string } :\n "
78+ f"reference = { _format (self ._reference )} \n "
79+ f"actual = { _format (self ._actual )} \n "
7980 )
8081 else :
8182 if self ._reference_on_right :
@@ -164,8 +165,9 @@ def match(self, observed):
164165 if expected_only == observed_only == []:
165166 return
166167 return PostfixedMismatch (
167- "\n missing: {}\n extra: {}" .format (
168- _format (expected_only ), _format (observed_only )
168+ (
169+ f"\n missing: { _format (expected_only )} \n "
170+ f"extra: { _format (observed_only )} "
169171 ),
170172 _BinaryMismatch (observed , "elements differ" , self .expected ),
171173 )
@@ -182,8 +184,8 @@ def __init__(self, matchee, expected):
182184 self .expected = expected
183185
184186 def describe (self ):
185- return "{} does not start with {}." . format (
186- text_repr (self .matchee ), text_repr (self .expected )
187+ return (
188+ f" { text_repr (self .matchee )} does not start with { text_repr (self .expected )} ."
187189 )
188190
189191
@@ -217,8 +219,8 @@ def __init__(self, matchee, expected):
217219 self .expected = expected
218220
219221 def describe (self ):
220- return "{} does not end with {}." . format (
221- text_repr (self .matchee ), text_repr (self .expected )
222+ return (
223+ f" { text_repr (self .matchee )} does not end with { text_repr (self .expected )} ."
222224 )
223225
224226
@@ -272,7 +274,9 @@ def describe(self):
272274 if len (self .types ) == 1 :
273275 typestr = self .types [0 ].__name__
274276 else :
275- typestr = "any of (%s)" % ", " .join (type .__name__ for type in self .types )
277+ typestr = "any of ({})" .format (
278+ ", " .join (type .__name__ for type in self .types )
279+ )
276280 return f"'{ self .matchee } ' is not an instance of { typestr } "
277281
278282
@@ -321,13 +325,13 @@ def __init__(self, pattern, flags=0):
321325 self .flags = flags
322326
323327 def __str__ (self ):
324- args = ["%r" % self .pattern ]
328+ args = [f" { self .pattern !r } " ]
325329 flag_arg = []
326330 # dir() sorts the attributes for us, so we don't need to do it again.
327331 for flag in dir (re ):
328332 if len (flag ) == 1 :
329333 if self .flags & getattr (re , flag ):
330- flag_arg .append ("re.%s" % flag )
334+ flag_arg .append (f "re.{ flag } " )
331335 if flag_arg :
332336 args .append ("|" .join (flag_arg ))
333337 return "{}({})" .format (self .__class__ .__name__ , ", " .join (args ))
0 commit comments