1
1
import difflib
2
2
import doctest
3
- import sys
4
3
import traceback
5
4
6
5
7
6
def text (arg ):
8
- if sys .version_info < (3 ,):
9
- if isinstance (arg , str ):
10
- arg = arg .decode ('utf-8' )
11
- else :
12
- if not isinstance (arg , str ):
13
- arg = arg .decode ('utf-8' )
7
+ if not isinstance (arg , str ):
8
+ arg = arg .decode ('utf-8' )
14
9
return arg
15
10
16
11
@@ -24,7 +19,7 @@ def ellipsis_match(expected, actual):
24
19
return doctest ._ellipsis_match (norm_expected , norm_actual )
25
20
26
21
27
- class Ellipsis ( object ) :
22
+ class Ellipsis :
28
23
"""Assertion helper that provides doctest-style ellipsis matching.
29
24
30
25
Inherit from this class in additition to unittest.TestCase.
@@ -47,7 +42,7 @@ def assertNotEllipsis(self, expected, actual):
47
42
'Value unexpectedly matches expression %r.' % expected )
48
43
49
44
50
- class Exceptions ( object ) :
45
+ class Exceptions :
51
46
52
47
def assertNothingRaised (self , callable = None , * args , ** kw ):
53
48
context = AssertNothingRaisedContext (self )
@@ -57,7 +52,7 @@ def assertNothingRaised(self, callable=None, *args, **kw):
57
52
callable (* args , ** kw )
58
53
59
54
60
- class AssertNothingRaisedContext ( object ) :
55
+ class AssertNothingRaisedContext :
61
56
62
57
def __init__ (self , test_case ):
63
58
self .failureException = test_case .failureException
@@ -76,16 +71,16 @@ def __exit__(self, exc_type, exc_value, tb):
76
71
# message, since we're printing that ourselves
77
72
stack = '' .join (
78
73
traceback .format_exception (exc_type , exc_value , tb )[1 :- 1 ])
79
- text = message + stack + 'Unexpected %s: %s' % ( exc_name , exc_value )
74
+ text = message + stack + f 'Unexpected { exc_name } : { exc_value } '
80
75
raise self .failureException (text )
81
76
82
77
83
- class String ( object ) :
78
+ class String :
84
79
85
80
def assertStartsWith (self , needle , haystack ):
86
81
if not haystack .startswith (needle ):
87
- self .fail ('%r does not start with %r.' % ( haystack , needle ) )
82
+ self .fail (f' { haystack !r } does not start with { needle !r } .' )
88
83
89
84
def assertEndsWith (self , needle , haystack ):
90
85
if not haystack .endswith (needle ):
91
- self .fail ('%r does not end with %r.' % ( haystack , needle ) )
86
+ self .fail (f' { haystack !r } does not end with { needle !r } .' )
0 commit comments