| 
									
										
										
										
											2010-05-19 17:15:50 +00:00
										 |  |  |  | """Tests for distutils.log""" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-23 14:10:07 +03:00
										 |  |  |  | import io | 
					
						
							| 
									
										
										
										
											2010-05-19 17:15:50 +00:00
										 |  |  |  | import sys | 
					
						
							|  |  |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2018-09-23 09:12:59 +03:00
										 |  |  |  | from test.support import swap_attr, run_unittest | 
					
						
							| 
									
										
										
										
											2010-05-19 17:15:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | from distutils import log | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | class TestLog(unittest.TestCase): | 
					
						
							|  |  |  |  |     def test_non_ascii(self): | 
					
						
							| 
									
										
										
										
											2018-09-23 09:12:59 +03:00
										 |  |  |  |         # Issues #8663, #34421: test that non-encodable text is escaped with | 
					
						
							|  |  |  |  |         # backslashreplace error handler and encodable non-ASCII text is | 
					
						
							|  |  |  |  |         # output as is. | 
					
						
							|  |  |  |  |         for errors in ('strict', 'backslashreplace', 'surrogateescape', | 
					
						
							|  |  |  |  |                        'replace', 'ignore'): | 
					
						
							| 
									
										
										
										
											2018-09-23 14:10:07 +03:00
										 |  |  |  |             with self.subTest(errors=errors): | 
					
						
							|  |  |  |  |                 stdout = io.TextIOWrapper(io.BytesIO(), | 
					
						
							|  |  |  |  |                                           encoding='cp437', errors=errors) | 
					
						
							|  |  |  |  |                 stderr = io.TextIOWrapper(io.BytesIO(), | 
					
						
							|  |  |  |  |                                           encoding='cp437', errors=errors) | 
					
						
							| 
									
										
										
										
											2018-09-23 09:12:59 +03:00
										 |  |  |  |                 old_threshold = log.set_threshold(log.DEBUG) | 
					
						
							|  |  |  |  |                 try: | 
					
						
							|  |  |  |  |                     with swap_attr(sys, 'stdout', stdout), \ | 
					
						
							|  |  |  |  |                          swap_attr(sys, 'stderr', stderr): | 
					
						
							|  |  |  |  |                         log.debug('Dεbug\tMėssãge') | 
					
						
							|  |  |  |  |                         log.fatal('Fαtal\tÈrrōr') | 
					
						
							|  |  |  |  |                 finally: | 
					
						
							|  |  |  |  |                     log.set_threshold(old_threshold) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-19 17:15:50 +00:00
										 |  |  |  |                 stdout.seek(0) | 
					
						
							| 
									
										
										
										
											2018-09-23 09:12:59 +03:00
										 |  |  |  |                 self.assertEqual(stdout.read().rstrip(), | 
					
						
							|  |  |  |  |                         'Dεbug\tM?ss?ge' if errors == 'replace' else | 
					
						
							|  |  |  |  |                         'Dεbug\tMssge' if errors == 'ignore' else | 
					
						
							|  |  |  |  |                         'Dεbug\tM\\u0117ss\\xe3ge') | 
					
						
							| 
									
										
										
										
											2010-05-19 17:15:50 +00:00
										 |  |  |  |                 stderr.seek(0) | 
					
						
							| 
									
										
										
										
											2018-09-23 09:12:59 +03:00
										 |  |  |  |                 self.assertEqual(stderr.read().rstrip(), | 
					
						
							|  |  |  |  |                         'Fαtal\t?rr?r' if errors == 'replace' else | 
					
						
							|  |  |  |  |                         'Fαtal\trrr' if errors == 'ignore' else | 
					
						
							|  |  |  |  |                         'Fαtal\t\\xc8rr\\u014dr') | 
					
						
							| 
									
										
										
										
											2010-05-19 17:15:50 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | def test_suite(): | 
					
						
							|  |  |  |  |     return unittest.makeSuite(TestLog) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | if __name__ == "__main__": | 
					
						
							| 
									
										
										
										
											2010-11-06 02:44:43 +00:00
										 |  |  |  |     run_unittest(test_suite()) |