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