MCPcopy Index your code
hub / github.com/python/cpython / test_showwarning

Method test_showwarning

Lib/test/test_warnings/__init__.py:1235–1254  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1233 category, file_name, line_num, file_line))
1234
1235 def test_showwarning(self):
1236 file_name = os.path.splitext(warning_tests.__file__)[0] + '.py'
1237 line_num = 3
1238 expected_file_line = linecache.getline(file_name, line_num).strip()
1239 message = 'msg'
1240 category = Warning
1241 file_object = StringIO()
1242 expect = self.module.formatwarning(message, category, file_name,
1243 line_num)
1244 self.module.showwarning(message, category, file_name, line_num,
1245 file_object)
1246 self.assertEqual(file_object.getvalue(), expect)
1247 # Test 'line' argument.
1248 expected_file_line += "for the win!"
1249 expect = self.module.formatwarning(message, category, file_name,
1250 line_num, expected_file_line)
1251 file_object = StringIO()
1252 self.module.showwarning(message, category, file_name, line_num,
1253 file_object, expected_file_line)
1254 self.assertEqual(expect, file_object.getvalue())
1255
1256 def test_formatwarning_override(self):
1257 # bpo-35178: Test that a custom formatwarning function gets the 'line'

Callers

nothing calls this directly

Calls 7

getvalueMethod · 0.95
StringIOClass · 0.90
splitextMethod · 0.80
showwarningMethod · 0.80
stripMethod · 0.45
getlineMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected