Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_imp fails on OS X; filename normalization issue. #52380

Closed
mdickinson opened this issue Mar 13, 2010 · 11 comments
Closed

test_imp fails on OS X; filename normalization issue. #52380

mdickinson opened this issue Mar 13, 2010 · 11 comments
Assignees
Labels
OS-mac release-blocker topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@mdickinson
Copy link
Member

BPO 8133
Nosy @brettcannon, @mdickinson, @benjaminp, @ned-deily, @ezio-melotti, @florentx
Files
  • issue8133_test_imp.diff: Patch, apply to 3.x
  • 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 = 'https://github.com/florentx'
    closed_at = <Date 2010-03-23.11:50:09.464>
    created_at = <Date 2010-03-13.20:02:24.005>
    labels = ['OS-mac', 'type-bug', 'expert-unicode', 'release-blocker']
    title = 'test_imp fails on OS X; filename normalization issue.'
    updated_at = <Date 2010-03-23.11:50:09.463>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2010-03-23.11:50:09.463>
    actor = 'flox'
    assignee = 'flox'
    closed = True
    closed_date = <Date 2010-03-23.11:50:09.464>
    closer = 'flox'
    components = ['macOS', 'Unicode']
    creation = <Date 2010-03-13.20:02:24.005>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['16601']
    hgrepos = []
    issue_num = 8133
    keywords = ['patch']
    message_count = 11.0
    messages = ['101018', '101019', '101180', '101186', '101253', '101344', '101378', '101382', '101383', '101392', '101396']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'mark.dickinson', 'benjamin.peterson', 'ned.deily', 'ezio.melotti', 'flox']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8133'
    versions = ['Python 3.1', 'Python 3.2']

    @mdickinson
    Copy link
    Member Author

    test_issue5604 from test_imp is currently failing on OS X !0.6 (py3k branch), with the following output:

    ======================================================================
    ERROR: test_issue5604 (main.ImportTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "Lib/test/test_imp.py", line 121, in test_issue5604
        file, filename, info = imp.find_module(temp_mod_name)
    ImportError: No module named test_imp_helper_ä

    I think this has something to do with the platform automatically
    using NFD normalization for filenames. Here's an interactive session:

    Python 3.2a0 (py3k:78936, Mar 13 2010, 19:42:52) 
    [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import imp, unicodedata
    >>> fname = 'test' + b'\xc3\xa4'.decode('utf-8')
    >>> with open(fname+'.py', 'w') as file: file.write('a = 1\n')
    ... 
    6
    >>> imp.find_module(fname)   # expected this to succeed
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named testä
    >>> imp.find_module(unicodedata.normalize('NFD', fname))
    (<_io.TextIOWrapper name=4 encoding='utf-8'>, 'testä.py', ('.py', 'U', 1))

    In contrast, a simple 'open' doesn't seem to care about normalization:

    >>> open(fname+'.py')
    <_io.TextIOWrapper name='testä.py' encoding='UTF-8'>
    [50305 refs]
    >>> open(unicodedata.normalize('NFD', fname)+'.py')
    <_io.TextIOWrapper name='testä.py' encoding='UTF-8'>
    [50305 refs]

    @mdickinson mdickinson added the type-bug An unexpected behavior, bug, or error label Mar 13, 2010
    @mdickinson
    Copy link
    Member Author

    Also affects 3.1.

    @mdickinson
    Copy link
    Member Author

    Brett: any thoughts on this? Should imp.find_module automatically apply NFD normalization to the given string on OS X?

    It seems to me that doing this properly is a bit nasty, since the correct condition isn't that the OS is OS X, but that the relevant filesystem is HFS+; presumably a single call to imp.find_module could end up checking directories with differing filesystems.

    @brettcannon
    Copy link
    Member

    Trying to get this right is nasty as mixed filesystem stuff is always tricky, especially since NFD is still UTF-8 as is NFC so sys.getdefaultencoding() doesn't help.

    Without some way to get that extra bit of info about what form of UTF-8 encoding is being used for the filesystem, I think the test should be modified to use os.listdir() to find the name as encoded by the filesystem and use that as the argument to imp.find_module() instead of assuming the filesystem didn't tweak what it was given.

    @ned-deily
    Copy link
    Member

    Test failing on 3.1.2rc1. Should this be considered a release blocker? Perhaps just disable temporarily?

    @ned-deily
    Copy link
    Member

    (BTW, the problem exists on other versions of OS X, not just 10.6.)

    @ned-deily ned-deily changed the title test_imp fails on OS X 10.6; filename normalization issue. test_imp fails on OS X; filename normalization issue. Mar 19, 2010
    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Mar 20, 2010

    Note: issue bpo-8180 is related to the same NFC/NFD issue.
    http://developer.apple.com/mac/library/qa/qa2001/qa1173.html

    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Mar 20, 2010

    Could you tell if the patch fix the issue?

    @mdickinson
    Copy link
    Member Author

    That patch works for me.

    (You should probably commit the comment fix in the patch separately though, rather than mixing it up with this issue.)

    @brettcannon
    Copy link
    Member

    Patch works for me as well. Go ahead and commit it, Florent, with the comment fix as a separate commit as Mark suggested.

    @brettcannon brettcannon assigned florentx and unassigned brettcannon Mar 20, 2010
    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Mar 20, 2010

    Fixed with r79144 on 3.x and r79146 on 3.1.

    @florentx florentx mannequin closed this as completed Mar 23, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-mac release-blocker topic-unicode type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants