You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-06-21.11:04:15.601>labels= ['3.7', '3.8', '3.9', '3.10', 'type-feature', 'tests']
title='Avoid using the locale encoding for open() in tests'updated_at=<Date2020-06-28.16:23:08.646>user='https://github.com/serhiy-storchaka'
Many tests use open() with the locale encoding for writing or reading files. They are passed because the written and read data a ASCII, and file paths are ASCII. But they do not test the case of non-ASCII data and file paths. In general, most of uses of the locale encoding should be changed.
In some cases it is enough to open the file in binary mode. For example when create an empty file, or use just fileno of the opened file.
In some cases the file should be opened in binary mode. For example, when compile the content of the file or parse it as XML, because the correct encoding is determined by the content (BOM, encoding coockie, XML declaration).
tokenize.open() or tokenize.detect_encoding() should be used when we read a Python source as a text.
os.fsdecode() and os.fsencode() may be used if the test file contains file paths and is read by bash or other external program.
encoding='ascii' should be specified if the test data always ASCII-only.
encoding='utf-8' should be specified if the test data can contain arbitrary Unicode characters.
Encoding different from 'ascii', 'latin1' and 'utf-8' should be used if arbitrary encodings should be supported.
Implicit locale encoding should be only used if the test is purposed to test the implicit encoding.
It is preferable to add non-ASCII characters in the test data.
I am working on a large patch for this (>50% is ready). Some parts of it may be extracted as separate PRs, and the rest will be exposed as a large PR. If changes are required not only in tests. separate issues will be opened.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: