MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_encoding_plain_file

Method test_encoding_plain_file

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

Source from the content-addressed store, hash-verified

2263
2264class EncodingTest(BaseTest):
2265 def test_encoding_plain_file(self):
2266 # In Python 2.x, a plain file object is treated as having no encoding.
2267 log = logging.getLogger("test")
2268 fn = make_temp_file(".log", "test_logging-1-")
2269 # the non-ascii data we write to the log.
2270 data = "foo\x80"
2271 try:
2272 handler = logging.FileHandler(fn, encoding="utf-8")
2273 log.addHandler(handler)
2274 try:
2275 # write non-ascii data to the log.
2276 log.warning(data)
2277 finally:
2278 log.removeHandler(handler)
2279 handler.close()
2280 # check we wrote exactly those bytes, ignoring trailing \n etc
2281 f = open(fn, encoding="utf-8")
2282 try:
2283 self.assertEqual(f.read().rstrip(), data)
2284 finally:
2285 f.close()
2286 finally:
2287 if os.path.isfile(fn):
2288 os.remove(fn)
2289
2290 def test_encoding_cyrillic_unicode(self):
2291 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