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

Method test_encoding_plain_file

Lib/test/test_logging.py:2291–2314  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2289
2290class EncodingTest(BaseTest):
2291 def test_encoding_plain_file(self):
2292 # In Python 2.x, a plain file object is treated as having no encoding.
2293 log = logging.getLogger("test")
2294 fn = make_temp_file(".log", "test_logging-1-")
2295 # the non-ascii data we write to the log.
2296 data = "foo\x80"
2297 try:
2298 handler = logging.FileHandler(fn, encoding="utf-8")
2299 log.addHandler(handler)
2300 try:
2301 # write non-ascii data to the log.
2302 log.warning(data)
2303 finally:
2304 log.removeHandler(handler)
2305 handler.close()
2306 # check we wrote exactly those bytes, ignoring trailing \n etc
2307 f = open(fn, encoding="utf-8")
2308 try:
2309 self.assertEqual(f.read().rstrip(), data)
2310 finally:
2311 f.close()
2312 finally:
2313 if os.path.isfile(fn):
2314 os.remove(fn)
2315
2316 def test_encoding_cyrillic_unicode(self):
2317 log = logging.getLogger("test")

Callers

nothing calls this directly

Calls 13

closeMethod · 0.95
make_temp_fileFunction · 0.85
getLoggerMethod · 0.80
addHandlerMethod · 0.80
removeHandlerMethod · 0.80
openFunction · 0.50
warningMethod · 0.45
assertEqualMethod · 0.45
rstripMethod · 0.45
readMethod · 0.45
closeMethod · 0.45
isfileMethod · 0.45

Tested by

no test coverage detected