@@ -1134,7 +1134,7 @@ def test_basic(self):
1134
1134
self .assertEqual (mailfrom , 'me' )
1135
1135
self .assertEqual (rcpttos , ['you' ])
1136
1136
self .assertIn ('\n Subject: Log\n ' , data )
1137
- self .assertTrue (data . endswith ( '\n \n Hello \u2713 ' ) )
1137
+ self .assertEndsWith (data , '\n \n Hello \u2713 ' )
1138
1138
h .close ()
1139
1139
1140
1140
def process_message (self , * args ):
@@ -3524,7 +3524,7 @@ def test_config14_ok(self):
3524
3524
self .assertEqual (h .foo , 'bar' )
3525
3525
self .assertEqual (h .terminator , '!\n ' )
3526
3526
logging .warning ('Exclamation' )
3527
- self .assertTrue (output .getvalue (). endswith ( 'Exclamation!\n ' ) )
3527
+ self .assertEndsWith (output .getvalue (), 'Exclamation!\n ' )
3528
3528
3529
3529
def test_config15_ok (self ):
3530
3530
@@ -4281,7 +4281,7 @@ def test_queue_handler(self):
4281
4281
msg = self .next_message ()
4282
4282
self .que_logger .warning (msg )
4283
4283
data = self .queue .get_nowait ()
4284
- self .assertTrue ( isinstance ( data , logging .LogRecord ) )
4284
+ self .assertIsInstance ( data , logging .LogRecord )
4285
4285
self .assertEqual (data .name , self .que_logger .name )
4286
4286
self .assertEqual ((data .msg , data .args ), (msg , None ))
4287
4287
@@ -4879,14 +4879,14 @@ def test_formatting(self):
4879
4879
r .removeHandler (h )
4880
4880
h .close ()
4881
4881
r = h .records [0 ]
4882
- self .assertTrue (r .exc_text . startswith ( 'Traceback (most recent '
4883
- ' call last):\n ') )
4884
- self .assertTrue (r .exc_text . endswith ( ' \n RuntimeError: '
4885
- ' deliberate mistake') )
4886
- self .assertTrue (r .stack_info . startswith ( 'Stack (most recent '
4887
- ' call last):\n ') )
4888
- self .assertTrue (r .stack_info . endswith ( 'logging.exception( \' failed \' , '
4889
- ' stack_info=True)' ) )
4882
+ self .assertStartsWith (r .exc_text ,
4883
+ 'Traceback (most recent call last):\n ' )
4884
+ self .assertEndsWith (r .exc_text ,
4885
+ ' \n RuntimeError: deliberate mistake' )
4886
+ self .assertStartsWith (r .stack_info ,
4887
+ 'Stack (most recent call last):\n ' )
4888
+ self .assertEndsWith (r .stack_info ,
4889
+ "logging.exception('failed', stack_info=True)" )
4890
4890
4891
4891
4892
4892
class LastResortTest (BaseTest ):
@@ -5229,8 +5229,8 @@ class LogRecordTest(BaseTest):
5229
5229
def test_str_rep (self ):
5230
5230
r = logging .makeLogRecord ({})
5231
5231
s = str (r )
5232
- self .assertTrue ( s . startswith ( '<LogRecord: ' ) )
5233
- self .assertTrue ( s . endswith ( '>' ) )
5232
+ self .assertStartsWith ( s , '<LogRecord: ' )
5233
+ self .assertEndsWith ( s , '>' )
5234
5234
5235
5235
def test_dict_arg (self ):
5236
5236
h = RecordingHandler ()
@@ -5880,14 +5880,14 @@ def test_extra_in_records(self):
5880
5880
self .adapter .critical ('foo should be here' )
5881
5881
self .assertEqual (len (self .recording .records ), 1 )
5882
5882
record = self .recording .records [0 ]
5883
- self .assertTrue ( hasattr ( record , 'foo' ) )
5883
+ self .assertHasAttr ( record , 'foo' )
5884
5884
self .assertEqual (record .foo , '1' )
5885
5885
5886
5886
def test_extra_not_merged_by_default (self ):
5887
5887
self .adapter .critical ('foo should NOT be here' , extra = {'foo' : 'nope' })
5888
5888
self .assertEqual (len (self .recording .records ), 1 )
5889
5889
record = self .recording .records [0 ]
5890
- self .assertFalse ( hasattr ( record , 'foo' ) )
5890
+ self .assertNotHasAttr ( record , 'foo' )
5891
5891
5892
5892
def test_extra_merged (self ):
5893
5893
self .adapter = logging .LoggerAdapter (logger = self .logger ,
@@ -5897,8 +5897,8 @@ def test_extra_merged(self):
5897
5897
self .adapter .critical ('foo and bar should be here' , extra = {'bar' : '2' })
5898
5898
self .assertEqual (len (self .recording .records ), 1 )
5899
5899
record = self .recording .records [0 ]
5900
- self .assertTrue ( hasattr ( record , 'foo' ) )
5901
- self .assertTrue ( hasattr ( record , 'bar' ) )
5900
+ self .assertHasAttr ( record , 'foo' )
5901
+ self .assertHasAttr ( record , 'bar' )
5902
5902
self .assertEqual (record .foo , '1' )
5903
5903
self .assertEqual (record .bar , '2' )
5904
5904
@@ -5910,7 +5910,7 @@ def test_extra_merged_log_call_has_precedence(self):
5910
5910
self .adapter .critical ('foo shall be min' , extra = {'foo' : '2' })
5911
5911
self .assertEqual (len (self .recording .records ), 1 )
5912
5912
record = self .recording .records [0 ]
5913
- self .assertTrue ( hasattr ( record , 'foo' ) )
5913
+ self .assertHasAttr ( record , 'foo' )
5914
5914
self .assertEqual (record .foo , '2' )
5915
5915
5916
5916
@@ -6624,18 +6624,19 @@ def namer(filename):
6624
6624
p = '%s.log.' % prefix
6625
6625
for c in candidates :
6626
6626
d , fn = os .path .split (c )
6627
- self .assertTrue (fn . startswith ( p ) )
6627
+ self .assertStartsWith (fn , p )
6628
6628
elif prefix .startswith ('d.e' ):
6629
6629
for c in candidates :
6630
6630
d , fn = os .path .split (c )
6631
- self .assertTrue (fn . endswith ( '.log' ), fn )
6632
- self .assertTrue (fn . startswith ( prefix + '.' ) and
6633
- fn [len (prefix ) + 2 ].isdigit ())
6631
+ self .assertEndsWith (fn , '.log' )
6632
+ self .assertStartsWith (fn , prefix + '.' )
6633
+ self . assertTrue ( fn [len (prefix ) + 2 ].isdigit ())
6634
6634
elif prefix == 'g' :
6635
6635
for c in candidates :
6636
6636
d , fn = os .path .split (c )
6637
- self .assertTrue (fn .endswith ('.oldlog' ))
6638
- self .assertTrue (fn .startswith ('g' ) and fn [1 ].isdigit ())
6637
+ self .assertEndsWith (fn , '.oldlog' )
6638
+ self .assertStartsWith (fn , 'g' )
6639
+ self .assertTrue (fn [1 ].isdigit ())
6639
6640
6640
6641
def test_compute_files_to_delete_same_filename_different_extensions (self ):
6641
6642
# See GH-93205 for background
@@ -6673,7 +6674,7 @@ def test_compute_files_to_delete_same_filename_different_extensions(self):
6673
6674
matcher = re .compile (r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\Z" )
6674
6675
for c in candidates :
6675
6676
d , fn = os .path .split (c )
6676
- self .assertTrue (fn . startswith ( prefix + '.' ) )
6677
+ self .assertStartsWith (fn , prefix + '.' )
6677
6678
suffix = fn [(len (prefix )+ 1 ):]
6678
6679
self .assertRegex (suffix , matcher )
6679
6680
0 commit comments