(self)
| 2289 | |
| 2290 | class 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") |
nothing calls this directly
no test coverage detected