python / python/cpython

`test_file` failed on Windows with a longer repo path in `test_urllib2`

オープン
#133,448 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

OS-windows tests type-bug
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

On Windows, when the CPython repository is cloned to a slightly longer path, for example, C:\Users\xxxxx\Source\cpython — this test case will fail:

ERROR: test_file (test.test_urllib2.HandlerTests.test_file)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\xxxxx\Source\cpython\Lib\encodings\idna.py", line 219, in encode
    result.extend(ToASCII(label))
                  ~~~~~~~^^^^^^^
  File "C:\Users\xxxxx\Source\cpython\Lib\encodings\idna.py", line 115, in ToASCII
    raise UnicodeEncodeError("idna", label, 0, len(label), "label too long")
UnicodeEncodeError: 'idna' codec can't encode characters in position 0-64: label too long

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxxxx\Source\cpython\Lib\test\test_urllib2.py", line 872, in test_file
    self.assertRaises(urllib.error.URLError,
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
                      h.file_open, Request(url))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxxx\Source\cpython\Lib\unittest\case.py", line 813, in assertRaises
    return context.handle('assertRaises', args, kwargs)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxxx\Source\cpython\Lib\unittest\case.py", line 247, in handle
    callable_obj(*args, **kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxxx\Source\cpython\Lib\urllib\request.py", line 1469, in open_local_file
    localfile = url2pathname(req.full_url, require_scheme=True)
  File "C:\Users\xxxxx\Source\cpython\Lib\urllib\request.py", line 1658, in url2pathname
    if not _is_local_authority(authority):
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "C:\Users\xxxxx\Source\cpython\Lib\urllib\request.py", line 1498, in _is_local_authority
    address = socket.gethostbyname(authority)
  File "C:\Users\xxxxx\Source\cpython\Lib\encodings\idna.py", line 222, in encode
    raise UnicodeEncodeError(
    ...<5 lines>...
    )
UnicodeEncodeError: 'idna' codec can't encode characters in position 8-72: label too long
encoding with 'idna' codec failed

See:
https://github.com/python/cpython/blob/c336f1c3126203fd6c38050df94e9fe8c0d7f2e2/Lib/test/test_urllib2.py#L857-L860

These two URLs will become:

  • file://127.0.0.1:80C:\Users\xxxxx\Source\cpython\build\test_python_worker_17208æ/@test_17208_tmpæ
  • file://somerandomhost.ontheinternet.comC:\Users\xxxxx\Source\cpython\build\test_python_worker_4676æ/@test_4676_tmpæ

Here, 127.0.0.1:80C:\Users\xxxxx\Source\cpython\build\test_python_worker_17208æ is treated as the domain and passed to socket.gethostbyname. However, the part 1:80C:\Users\xxxxx\Source\cpython\build\test_python_worker_17208æ is too long to be a valid domain label. As a result, the idna codec raises an exception, indicating the label is too long.

A patch is on the way.

Linked PRs
  • gh-133449

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/test/test_urllib2.py の test_file 付近から始め、特に 857-860 行付近の URL の設定と 872 行付近の assertion を確認します。Windows でより長い checkout パスを使用して test.test_urllib2.HandlerTests.test_file を実行し、結果の URL と exception を比較します。その環境でテストが失敗しなくなり、意図された URLError assertion が維持されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
testing-qa
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
15/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。