Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-71339: Use new assertion methods in test_logging#128828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletionsLib/test/test_logging.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1134,7 +1134,7 @@ def test_basic(self):
self.assertEqual(mailfrom, 'me')
self.assertEqual(rcpttos, ['you'])
self.assertIn('\nSubject: Log\n', data)
self.assertTrue(data.endswith('\n\nHello \u2713'))
self.assertEndsWith(data,'\n\nHello \u2713')
h.close()

def process_message(self, *args):
Expand DownExpand Up@@ -3524,7 +3524,7 @@ def test_config14_ok(self):
self.assertEqual(h.foo, 'bar')
self.assertEqual(h.terminator, '!\n')
logging.warning('Exclamation')
self.assertTrue(output.getvalue().endswith('Exclamation!\n'))
self.assertEndsWith(output.getvalue(),'Exclamation!\n')

def test_config15_ok(self):

Expand DownExpand Up@@ -4281,7 +4281,7 @@ def test_queue_handler(self):
msg = self.next_message()
self.que_logger.warning(msg)
data = self.queue.get_nowait()
self.assertTrue(isinstance(data, logging.LogRecord))
self.assertIsInstance(data, logging.LogRecord)
self.assertEqual(data.name, self.que_logger.name)
self.assertEqual((data.msg, data.args), (msg, None))

Expand DownExpand Up@@ -4879,14 +4879,14 @@ def test_formatting(self):
r.removeHandler(h)
h.close()
r = h.records[0]
self.assertTrue(r.exc_text.startswith('Traceback (most recent '
'call last):\n'))
self.assertTrue(r.exc_text.endswith('\nRuntimeError: '
'deliberate mistake'))
self.assertTrue(r.stack_info.startswith('Stack (most recent '
'call last):\n'))
self.assertTrue(r.stack_info.endswith('logging.exception(\'failed\', '
'stack_info=True)'))
self.assertStartsWith(r.exc_text,
'Traceback (most recentcall last):\n')
self.assertEndsWith(r.exc_text,
'\nRuntimeError:deliberate mistake')
self.assertStartsWith(r.stack_info,
'Stack (most recentcall last):\n')
self.assertEndsWith(r.stack_info,
"logging.exception('failed',stack_info=True)")


class LastResortTest(BaseTest):
Expand DownExpand Up@@ -5229,8 +5229,8 @@ class LogRecordTest(BaseTest):
def test_str_rep(self):
r = logging.makeLogRecord({})
s = str(r)
self.assertTrue(s.startswith('<LogRecord: '))
self.assertTrue(s.endswith('>'))
self.assertStartsWith(s,'<LogRecord: ')
self.assertEndsWith(s,'>')

def test_dict_arg(self):
h = RecordingHandler()
Expand DownExpand Up@@ -5880,14 +5880,14 @@ def test_extra_in_records(self):
self.adapter.critical('foo should be here')
self.assertEqual(len(self.recording.records), 1)
record = self.recording.records[0]
self.assertTrue(hasattr(record, 'foo'))
self.assertHasAttr(record, 'foo')
self.assertEqual(record.foo, '1')

def test_extra_not_merged_by_default(self):
self.adapter.critical('foo should NOT be here', extra={'foo': 'nope'})
self.assertEqual(len(self.recording.records), 1)
record = self.recording.records[0]
self.assertFalse(hasattr(record, 'foo'))
self.assertNotHasAttr(record, 'foo')

def test_extra_merged(self):
self.adapter = logging.LoggerAdapter(logger=self.logger,
Expand All@@ -5897,8 +5897,8 @@ def test_extra_merged(self):
self.adapter.critical('foo and bar should be here', extra={'bar': '2'})
self.assertEqual(len(self.recording.records), 1)
record = self.recording.records[0]
self.assertTrue(hasattr(record, 'foo'))
self.assertTrue(hasattr(record, 'bar'))
self.assertHasAttr(record, 'foo')
self.assertHasAttr(record, 'bar')
self.assertEqual(record.foo, '1')
self.assertEqual(record.bar, '2')

Expand All@@ -5910,7 +5910,7 @@ def test_extra_merged_log_call_has_precedence(self):
self.adapter.critical('foo shall be min', extra={'foo': '2'})
self.assertEqual(len(self.recording.records), 1)
record = self.recording.records[0]
self.assertTrue(hasattr(record, 'foo'))
self.assertHasAttr(record, 'foo')
self.assertEqual(record.foo, '2')


Expand DownExpand Up@@ -6624,18 +6624,19 @@ def namer(filename):
p = '%s.log.' % prefix
for c in candidates:
d, fn = os.path.split(c)
self.assertTrue(fn.startswith(p))
self.assertStartsWith(fn, p)
elif prefix.startswith('d.e'):
for c in candidates:
d, fn = os.path.split(c)
self.assertTrue(fn.endswith('.log'), fn)
self.assertTrue(fn.startswith(prefix + '.') and
fn[len(prefix) + 2].isdigit())
self.assertEndsWith(fn,'.log')
self.assertStartsWith(fn,prefix + '.')
self.assertTrue(fn[len(prefix) + 2].isdigit())
elif prefix == 'g':
for c in candidates:
d, fn = os.path.split(c)
self.assertTrue(fn.endswith('.oldlog'))
self.assertTrue(fn.startswith('g') and fn[1].isdigit())
self.assertEndsWith(fn, '.oldlog')
self.assertStartsWith(fn, 'g')
self.assertTrue(fn[1].isdigit())

def test_compute_files_to_delete_same_filename_different_extensions(self):
# See GH-93205 for background
Expand DownExpand Up@@ -6673,7 +6674,7 @@ def test_compute_files_to_delete_same_filename_different_extensions(self):
matcher = re.compile(r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\Z")
for c in candidates:
d, fn = os.path.split(c)
self.assertTrue(fn.startswith(prefix+'.'))
self.assertStartsWith(fn,prefix+'.')
suffix = fn[(len(prefix)+1):]
self.assertRegex(suffix, matcher)

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp