diff options
author | Srinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి) <thatiparthysreenivas@gmail.com> | 2021-07-08 07:16:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-08 07:16:08 (GMT) |
commit | 58248d94379b202ccce3e45b1d1830ca47683273 (patch) | |
tree | e96253619faf7e782cff59a7b1e9b9173ef22782 /Lib/test/test_pdb.py | |
parent | fed2fc4443235fa9669b73817827fd6da88e3417 (diff) | |
download | cpython-58248d94379b202ccce3e45b1d1830ca47683273.zip cpython-58248d94379b202ccce3e45b1d1830ca47683273.tar.gz cpython-58248d94379b202ccce3e45b1d1830ca47683273.tar.bz2 |
bpo-41137: Use utf-8 encoding while reading .pdbrc files (GH-21263)
Diffstat (limited to 'Lib/test/test_pdb.py')
-rw-r--r-- | Lib/test/test_pdb.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 63afb81..17634c7 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1627,6 +1627,40 @@ def bœr(): if save_home is not None: os.environ["HOME"] = save_home + def test_read_pdbrc_with_ascii_encoding(self): + script = textwrap.dedent(""" + import pdb; pdb.Pdb().set_trace() + print('hello') + """) + save_home = os.environ.pop('HOME', None) + try: + with os_helper.temp_cwd(): + with open('.pdbrc', 'w', encoding='utf-8') as f: + f.write("Fran\u00E7ais") + + with open('main.py', 'w', encoding='utf-8') as f: + f.write(script) + + cmd = [sys.executable, 'main.py'] + env = {'PYTHONIOENCODING': 'ascii'} + if sys.platform == 'win32': + env['PYTHONLEGACYWINDOWSSTDIO'] = 'non-empty-string' + proc = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.PIPE, + env={**os.environ, **env} + ) + with proc: + stdout, stderr = proc.communicate(b'c\n') + self.assertIn(b"UnicodeEncodeError: \'ascii\' codec can\'t encode character " + b"\'\\xe7\' in position 21: ordinal not in range(128)", stderr) + + finally: + if save_home is not None: + os.environ['HOME'] = save_home + def test_header(self): stdout = StringIO() header = 'Nobody expects... blah, blah, blah' |