From 752c4f9b3462ab92fc6a134ad25b22ebd84cdf43 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 2 Aug 2021 13:08:52 -0500 Subject: [PATCH 01/37] Return a better error message if a file is not found Print better error messages if the file/URL is not found. --- src/pip/_internal/network/session.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py index e2916ca8198..ee1872e6a88 100644 --- a/src/pip/_internal/network/session.py +++ b/src/pip/_internal/network/session.py @@ -207,8 +207,11 @@ def send( try: stats = os.stat(pathname) except OSError as exc: + # format the exception raised as a io.BytesIO object, + # to return a better error message: resp.status_code = 404 - resp.raw = exc + error_message = f"{type(exc).__name__}: {exc}" + resp.raw = io.BytesIO(error_message.encode("utf8")) else: modified = email.utils.formatdate(stats.st_mtime, usegmt=True) content_type = mimetypes.guess_type(pathname)[0] or "text/plain" From 5afb103baac59dc45b3e1a8feee1ddea0d111008 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 2 Aug 2021 13:12:59 -0500 Subject: [PATCH 02/37] Create 10263.bugfix.rst The news entry for my pull request. --- news/10263.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/10263.bugfix.rst diff --git a/news/10263.bugfix.rst b/news/10263.bugfix.rst new file mode 100644 index 00000000000..572f1941e95 --- /dev/null +++ b/news/10263.bugfix.rst @@ -0,0 +1 @@ +Return better error messages if a file/URL is not found. From 6854c25e28cdcd5e5d53959440d3f29ef2d979eb Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 2 Aug 2021 13:14:44 -0500 Subject: [PATCH 03/37] Format the error message Make it look like the common Python tracebacks. --- src/pip/_internal/network/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py index ee1872e6a88..5d19c5607bd 100644 --- a/src/pip/_internal/network/session.py +++ b/src/pip/_internal/network/session.py @@ -210,7 +210,7 @@ def send( # format the exception raised as a io.BytesIO object, # to return a better error message: resp.status_code = 404 - error_message = f"{type(exc).__name__}: {exc}" + error_message = f"{type(exc).__name__}: {str(exc)}" resp.raw = io.BytesIO(error_message.encode("utf8")) else: modified = email.utils.formatdate(stats.st_mtime, usegmt=True) From d1c19ed1d4653046fee293c8a903e4b70d3e8d74 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 2 Aug 2021 13:16:51 -0500 Subject: [PATCH 04/37] Fix an ImportError I forgot to import a standard module before using it. --- src/pip/_internal/network/session.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py index 5d19c5607bd..3aea68ac2ee 100644 --- a/src/pip/_internal/network/session.py +++ b/src/pip/_internal/network/session.py @@ -3,6 +3,7 @@ """ import email.utils +import io import ipaddress import json import logging From 447387083efffbfc0f0df913fd3ac640e201fa1d Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 5 Aug 2021 14:39:30 -0500 Subject: [PATCH 05/37] Adjust the error message Set "requests.Request.reason" to get cleaner error messages. --- src/pip/_internal/network/session.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py index 3aea68ac2ee..77f145fc55d 100644 --- a/src/pip/_internal/network/session.py +++ b/src/pip/_internal/network/session.py @@ -212,6 +212,7 @@ def send( # to return a better error message: resp.status_code = 404 error_message = f"{type(exc).__name__}: {str(exc)}" + resp.reason = error_message resp.raw = io.BytesIO(error_message.encode("utf8")) else: modified = email.utils.formatdate(stats.st_mtime, usegmt=True) From f0086ac0d1861840184f412782a13c97071f3737 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 5 Aug 2021 17:28:03 -0500 Subject: [PATCH 06/37] Update the error message Make a simple modification. --- src/pip/_internal/network/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py index 77f145fc55d..36e97a64140 100644 --- a/src/pip/_internal/network/session.py +++ b/src/pip/_internal/network/session.py @@ -211,7 +211,7 @@ def send( # format the exception raised as a io.BytesIO object, # to return a better error message: resp.status_code = 404 - error_message = f"{type(exc).__name__}: {str(exc)}" + error_message = f"\"{type(exc).__name__}: {str(exc)}\"" resp.reason = error_message resp.raw = io.BytesIO(error_message.encode("utf8")) else: From 538fb0da62a032d6bb0d730f4116dc5f819ba7d1 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 5 Aug 2021 20:31:53 -0500 Subject: [PATCH 07/37] Update the error message Use a prettier string. --- src/pip/_internal/network/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py index 36e97a64140..e1e8cfcf2a4 100644 --- a/src/pip/_internal/network/session.py +++ b/src/pip/_internal/network/session.py @@ -211,7 +211,7 @@ def send( # format the exception raised as a io.BytesIO object, # to return a better error message: resp.status_code = 404 - error_message = f"\"{type(exc).__name__}: {str(exc)}\"" + error_message = f'"{type(exc).__name__}: {str(exc)}"' resp.reason = error_message resp.raw = io.BytesIO(error_message.encode("utf8")) else: From 1b674e65d8ec88e2199849afb6d27f1468bcac96 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Fri, 6 Aug 2021 18:27:26 -0500 Subject: [PATCH 08/37] Update the error message Remove a duplicated path. Co-authored-by: Tzu-ping Chung --- src/pip/_internal/network/session.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py index e1e8cfcf2a4..cbe743ba6a1 100644 --- a/src/pip/_internal/network/session.py +++ b/src/pip/_internal/network/session.py @@ -211,9 +211,8 @@ def send( # format the exception raised as a io.BytesIO object, # to return a better error message: resp.status_code = 404 - error_message = f'"{type(exc).__name__}: {str(exc)}"' - resp.reason = error_message - resp.raw = io.BytesIO(error_message.encode("utf8")) + resp.reason = type(exc).__name__ + resp.raw = io.BytesIO(f"{resp.reason}: {exc}".encode("utf8")) else: modified = email.utils.formatdate(stats.st_mtime, usegmt=True) content_type = mimetypes.guess_type(pathname)[0] or "text/plain" From 1a0fb4239c0ec9f11fe20697482f6783b3d88250 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 09:11:38 -0500 Subject: [PATCH 09/37] Create test_bad_url.py A test for this new error message. --- tests/functional/test_bad_url.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/functional/test_bad_url.py diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py new file mode 100644 index 00000000000..b37332a6fca --- /dev/null +++ b/tests/functional/test_bad_url.py @@ -0,0 +1,28 @@ +import subprocess +import random +from typing import List, Tuple + +def get_url_error_message(cmd: List[str]) -> Tuple[str, str]: + # this makes pip to react using + # subprocess. It must fail, so then + # we can test the error message. + proc = subprocess.run(cmd, capture_output=True, text=True) + expected_message = "ERROR: 404 Client Error: FileNotFoundError for url: " + return proc.stderr, expected_message + +def get_random_pathname() -> str: + "create a random, impossible pathname." + base = "random_impossible_pathname_" + alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" + name = base + "".join(random.choice(alphabet)) for _ in range(10) + return name + +def test_bad_url_error_message() -> None: + """ + Test the error message returned when using a bad "file:" URL. + """ + file = get_random_pathname() + command = ["pip", "install", "file:%s"%file] + msg, expected = get_url_error_message(command) + # assert that "msg" starts with "expected" + assert msg.startswith(expected) From 8c72c9b9ce4151d4bc972614ccf22160b4e8f36f Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 09:28:44 -0500 Subject: [PATCH 10/37] Style fixes to `test_bad_url.py` Fix a SyntaxError, an isort warning, and flake8 style errors. --- tests/functional/test_bad_url.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index b37332a6fca..bff3fd90312 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -1,7 +1,8 @@ -import subprocess import random +import subprocess from typing import List, Tuple + def get_url_error_message(cmd: List[str]) -> Tuple[str, str]: # this makes pip to react using # subprocess. It must fail, so then @@ -10,17 +11,17 @@ def get_url_error_message(cmd: List[str]) -> Tuple[str, str]: expected_message = "ERROR: 404 Client Error: FileNotFoundError for url: " return proc.stderr, expected_message + def get_random_pathname() -> str: "create a random, impossible pathname." base = "random_impossible_pathname_" alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" - name = base + "".join(random.choice(alphabet)) for _ in range(10) + name = base + "".join(random.choice(alphabet) for _ in range(10) return name + def test_bad_url_error_message() -> None: - """ - Test the error message returned when using a bad "file:" URL. - """ + "Test the error message returned when using a bad 'file:' URL." file = get_random_pathname() command = ["pip", "install", "file:%s"%file] msg, expected = get_url_error_message(command) From 99a316be20fea4ef4c70060f4670e3353cf606d5 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 09:38:19 -0500 Subject: [PATCH 11/37] Update test_bad_url.py Make some style fixes. --- tests/functional/test_bad_url.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index bff3fd90312..f6a913b4b29 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -1,3 +1,6 @@ +# test the error message returned by pip when +# a bad "file:" URL is passed to it. + import random import subprocess from typing import List, Tuple @@ -16,8 +19,7 @@ def get_random_pathname() -> str: "create a random, impossible pathname." base = "random_impossible_pathname_" alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" - name = base + "".join(random.choice(alphabet) for _ in range(10) - return name + return base + "".join(random.choice(alphabet) for _ in range(10) def test_bad_url_error_message() -> None: From 1eac21ed18f48507e00fc2d2eb2791dba5e9f39f Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 09:44:26 -0500 Subject: [PATCH 12/37] Update test_bad_url.py Just change the function name. --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index f6a913b4b29..ce12f6eb5c1 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -22,7 +22,7 @@ def get_random_pathname() -> str: return base + "".join(random.choice(alphabet) for _ in range(10) -def test_bad_url_error_message() -> None: +def test_filenotfound_error_message() -> None: "Test the error message returned when using a bad 'file:' URL." file = get_random_pathname() command = ["pip", "install", "file:%s"%file] From 7141432da1301ffd6859ac8fd35c955ee86f200e Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 10:06:30 -0500 Subject: [PATCH 13/37] Update test_bad_url.py Add a missing parenthesis. --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index ce12f6eb5c1..fda7295e343 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -19,7 +19,7 @@ def get_random_pathname() -> str: "create a random, impossible pathname." base = "random_impossible_pathname_" alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" - return base + "".join(random.choice(alphabet) for _ in range(10) + return base + "".join(random.choice(alphabet)) for _ in range(10) def test_filenotfound_error_message() -> None: From 27031191c8c15685468efd8d0a80af9d09fa6612 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 10:12:09 -0500 Subject: [PATCH 14/37] Update test_bad_url.py Fix a SyntaxError. --- tests/functional/test_bad_url.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index fda7295e343..7ed4541346b 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -19,11 +19,13 @@ def get_random_pathname() -> str: "create a random, impossible pathname." base = "random_impossible_pathname_" alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" - return base + "".join(random.choice(alphabet)) for _ in range(10) + for _ in range(10) + name = base + "".join(random.choice(alphabet)) + return name def test_filenotfound_error_message() -> None: - "Test the error message returned when using a bad 'file:' URL." + # Test the error message returned when using a bad 'file:' URL. file = get_random_pathname() command = ["pip", "install", "file:%s"%file] msg, expected = get_url_error_message(command) From b6e66ced480109af0ab5e11221fa0a83b52df74f Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 10:20:15 -0500 Subject: [PATCH 15/37] Update test_bad_url.py Fix another syntax error. --- tests/functional/test_bad_url.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 7ed4541346b..c0755b71797 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -19,7 +19,7 @@ def get_random_pathname() -> str: "create a random, impossible pathname." base = "random_impossible_pathname_" alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" - for _ in range(10) + for _ in range(10): name = base + "".join(random.choice(alphabet)) return name @@ -27,7 +27,9 @@ def get_random_pathname() -> str: def test_filenotfound_error_message() -> None: # Test the error message returned when using a bad 'file:' URL. file = get_random_pathname() + # generate a command command = ["pip", "install", "file:%s"%file] + # make it fail to get an error message msg, expected = get_url_error_message(command) # assert that "msg" starts with "expected" assert msg.startswith(expected) From fa0312234a3d080a14fe625b296297b251499df3 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 10:38:55 -0500 Subject: [PATCH 16/37] Update test_bad_url.py Use the correct way to generate an impossible path. --- tests/functional/test_bad_url.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index c0755b71797..dce66afdc53 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -19,8 +19,7 @@ def get_random_pathname() -> str: "create a random, impossible pathname." base = "random_impossible_pathname_" alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" - for _ in range(10): - name = base + "".join(random.choice(alphabet)) + name = base + "".join(random.choice(alphabet) for _ in range(10)) return name From b3a62afb1037760e5114e0e222c41edfafe1b51d Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 11:00:51 -0500 Subject: [PATCH 17/37] Update test_bad_url.py Use f-strings instead of modulo operator. --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index dce66afdc53..31ca735c3b3 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -27,7 +27,7 @@ def test_filenotfound_error_message() -> None: # Test the error message returned when using a bad 'file:' URL. file = get_random_pathname() # generate a command - command = ["pip", "install", "file:%s"%file] + command = ["pip", "install", f"file:{file}"] # make it fail to get an error message msg, expected = get_url_error_message(command) # assert that "msg" starts with "expected" From 4f6eb30f4e2eaee53815edb9b5800813482e5269 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 11:17:28 -0500 Subject: [PATCH 18/37] Update test_bad_url.py Modify the command passed to the test. --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 31ca735c3b3..5fce6eec24f 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -27,7 +27,7 @@ def test_filenotfound_error_message() -> None: # Test the error message returned when using a bad 'file:' URL. file = get_random_pathname() # generate a command - command = ["pip", "install", f"file:{file}"] + command = ["pip", "install", "-r, f"file:{file}"] # make it fail to get an error message msg, expected = get_url_error_message(command) # assert that "msg" starts with "expected" From aceefdcfa999869a4c33bd3d94af8d5bda9c733b Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 16 Aug 2021 11:19:49 -0500 Subject: [PATCH 19/37] Update test_bad_url.py Fix a syntax error. --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 5fce6eec24f..136c3d5ee8e 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -27,7 +27,7 @@ def test_filenotfound_error_message() -> None: # Test the error message returned when using a bad 'file:' URL. file = get_random_pathname() # generate a command - command = ["pip", "install", "-r, f"file:{file}"] + command = ["pip", "install", "-r", f"file:{file}"] # make it fail to get an error message msg, expected = get_url_error_message(command) # assert that "msg" starts with "expected" From de0452f0ec3493a39ed89d21d888e5721b366090 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 08:06:29 -0500 Subject: [PATCH 20/37] Update test_bad_url.py * Simplify the imaginary pathname. * Modify the way to test, use a "script.pip" instead of subprocess. --- tests/functional/test_bad_url.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 136c3d5ee8e..0421af1744e 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -1,34 +1,24 @@ # test the error message returned by pip when # a bad "file:" URL is passed to it. -import random -import subprocess -from typing import List, Tuple +from typing import Tuple -def get_url_error_message(cmd: List[str]) -> Tuple[str, str]: +def get_url_error_message(script: Any, fake_file: str) -> Tuple[str, str, int]: # this makes pip to react using # subprocess. It must fail, so then # we can test the error message. - proc = subprocess.run(cmd, capture_output=True, text=True) + proc = script.pip("install", "-r", fake_file, expect_error=True) expected_message = "ERROR: 404 Client Error: FileNotFoundError for url: " - return proc.stderr, expected_message + return proc.stderr, expected_message, proc.returncode -def get_random_pathname() -> str: - "create a random, impossible pathname." - base = "random_impossible_pathname_" - alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" - name = base + "".join(random.choice(alphabet) for _ in range(10)) - return name - - -def test_filenotfound_error_message() -> None: +def test_filenotfound_error_message(script: Any) -> None: # Test the error message returned when using a bad 'file:' URL. file = get_random_pathname() # generate a command - command = ["pip", "install", "-r", f"file:{file}"] - # make it fail to get an error message - msg, expected = get_url_error_message(command) + # make it fail to get an error message by running "pip install -r nonexistent_file" + msg, expected, code = get_url_error_message(script, "nonexistent_file") # assert that "msg" starts with "expected" + assert code == 1 assert msg.startswith(expected) From 029a11365c2dec6ee0b1427627e576c8fb1f1126 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 08:08:40 -0500 Subject: [PATCH 21/37] Update test_bad_url.py Add "Any" when importing "typing". --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 0421af1744e..38aed4af04e 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -1,7 +1,7 @@ # test the error message returned by pip when # a bad "file:" URL is passed to it. -from typing import Tuple +from typing import Any, Tuple def get_url_error_message(script: Any, fake_file: str) -> Tuple[str, str, int]: From 51274d4fb604d11fbb64c1e046a24cbadc61cbe3 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 08:11:53 -0500 Subject: [PATCH 22/37] Update test_bad_url.py Remove a deleted function. --- tests/functional/test_bad_url.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 38aed4af04e..e9940fea408 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -15,9 +15,7 @@ def get_url_error_message(script: Any, fake_file: str) -> Tuple[str, str, int]: def test_filenotfound_error_message(script: Any) -> None: # Test the error message returned when using a bad 'file:' URL. - file = get_random_pathname() - # generate a command - # make it fail to get an error message by running "pip install -r nonexistent_file" + # make pip to fail and get an error message by running "pip install -r nonexistent_file" msg, expected, code = get_url_error_message(script, "nonexistent_file") # assert that "msg" starts with "expected" assert code == 1 From 12971f4583ca3c2d0dc7aae645184e84fdea3020 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 08:15:18 -0500 Subject: [PATCH 23/37] Update test_bad_url.py Just change a long line. --- tests/functional/test_bad_url.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index e9940fea408..4ed0730557e 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -15,7 +15,8 @@ def get_url_error_message(script: Any, fake_file: str) -> Tuple[str, str, int]: def test_filenotfound_error_message(script: Any) -> None: # Test the error message returned when using a bad 'file:' URL. - # make pip to fail and get an error message by running "pip install -r nonexistent_file" + # make pip to fail and get an error message + # by running "pip install -r nonexistent_file" msg, expected, code = get_url_error_message(script, "nonexistent_file") # assert that "msg" starts with "expected" assert code == 1 From b7bce7c4d31e4742f03c605b0bd6ef5730cc1d90 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 09:01:50 -0500 Subject: [PATCH 24/37] Update test_bad_url.py Modify the way to test the requirements file, to avoid an AssertionError. --- tests/functional/test_bad_url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 4ed0730557e..7be20b264b2 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -8,7 +8,7 @@ def get_url_error_message(script: Any, fake_file: str) -> Tuple[str, str, int]: # this makes pip to react using # subprocess. It must fail, so then # we can test the error message. - proc = script.pip("install", "-r", fake_file, expect_error=True) + proc = script.pip("install", "-r", f"file:{fake_file}", expect_error=True) expected_message = "ERROR: 404 Client Error: FileNotFoundError for url: " return proc.stderr, expected_message, proc.returncode @@ -16,7 +16,7 @@ def get_url_error_message(script: Any, fake_file: str) -> Tuple[str, str, int]: def test_filenotfound_error_message(script: Any) -> None: # Test the error message returned when using a bad 'file:' URL. # make pip to fail and get an error message - # by running "pip install -r nonexistent_file" + # by running "pip install -r file:nonexistent_file" msg, expected, code = get_url_error_message(script, "nonexistent_file") # assert that "msg" starts with "expected" assert code == 1 From 9faf241097abfaac600de1a70c600e94d4472299 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 09:31:58 -0500 Subject: [PATCH 25/37] Update test_bad_url.py Squash all the test into a single function. --- tests/functional/test_bad_url.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 7be20b264b2..7796cf7ae01 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -4,20 +4,13 @@ from typing import Any, Tuple -def get_url_error_message(script: Any, fake_file: str) -> Tuple[str, str, int]: - # this makes pip to react using - # subprocess. It must fail, so then - # we can test the error message. - proc = script.pip("install", "-r", f"file:{fake_file}", expect_error=True) - expected_message = "ERROR: 404 Client Error: FileNotFoundError for url: " - return proc.stderr, expected_message, proc.returncode - - def test_filenotfound_error_message(script: Any) -> None: # Test the error message returned when using a bad 'file:' URL. # make pip to fail and get an error message # by running "pip install -r file:nonexistent_file" - msg, expected, code = get_url_error_message(script, "nonexistent_file") + proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) + expected = "ERROR: 404 Client Error: FileNotFoundError for url: " + msg, code = proc.stderr, proc.returncode # assert that "msg" starts with "expected" assert code == 1 assert msg.startswith(expected) From e7ca41e7fdc326b0131700c436e799ab446dedc4 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 09:35:30 -0500 Subject: [PATCH 26/37] Update test_bad_url.py Remove the unused "typing.Tuple". --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 7796cf7ae01..569908a0bd1 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -1,7 +1,7 @@ # test the error message returned by pip when # a bad "file:" URL is passed to it. -from typing import Any, Tuple +from typing import Any def test_filenotfound_error_message(script: Any) -> None: From 5877fbb2eae415c5809e6e36101e7bfe3b1c575c Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 09:36:37 -0500 Subject: [PATCH 27/37] Update tests/functional/test_bad_url.py Co-authored-by: Tzu-ping Chung --- tests/functional/test_bad_url.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 569908a0bd1..dacdccd1ef9 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -9,8 +9,6 @@ def test_filenotfound_error_message(script: Any) -> None: # make pip to fail and get an error message # by running "pip install -r file:nonexistent_file" proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) + assert proc.returncode == 1 expected = "ERROR: 404 Client Error: FileNotFoundError for url: " - msg, code = proc.stderr, proc.returncode - # assert that "msg" starts with "expected" - assert code == 1 - assert msg.startswith(expected) + assert proc.stderr.startswith(expected) From 5147c2cfb35e5699943fe9175ce769a20f986be3 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 10:11:56 -0500 Subject: [PATCH 28/37] Update test_bad_url.py Use a more accurate test. --- tests/functional/test_bad_url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index dacdccd1ef9..7ec182cc30e 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -10,5 +10,5 @@ def test_filenotfound_error_message(script: Any) -> None: # by running "pip install -r file:nonexistent_file" proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) assert proc.returncode == 1 - expected = "ERROR: 404 Client Error: FileNotFoundError for url: " - assert proc.stderr.startswith(expected) + expected = "ERROR: 404 Client Error: FileNotFoundError for url: unexistent_file" + assert proc.stderr == expected From 086b1c0fd48132101eaaa17baf359c44df2051cb Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 10:26:00 -0500 Subject: [PATCH 29/37] Update test_bad_url.py Modify the test catching. --- tests/functional/test_bad_url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 7ec182cc30e..d45104e65f4 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -10,5 +10,5 @@ def test_filenotfound_error_message(script: Any) -> None: # by running "pip install -r file:nonexistent_file" proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) assert proc.returncode == 1 - expected = "ERROR: 404 Client Error: FileNotFoundError for url: unexistent_file" - assert proc.stderr == expected + expected = "ERROR: 404 Client Error: FileNotFoundError for url: file:///unexistent_file" + assert proc.stderr == expected.rstrip() From 2f1227b306dd45cf9d770b53d6b53ea87d821982 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 10:30:28 -0500 Subject: [PATCH 30/37] Update test_bad_url.py Change the line length. --- tests/functional/test_bad_url.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index d45104e65f4..92d10ceede6 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -10,5 +10,6 @@ def test_filenotfound_error_message(script: Any) -> None: # by running "pip install -r file:nonexistent_file" proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) assert proc.returncode == 1 - expected = "ERROR: 404 Client Error: FileNotFoundError for url: file:///unexistent_file" - assert proc.stderr == expected.rstrip() + file = "file:///unexistent_file" + expect = f"ERROR: 404 Client Error: FileNotFoundError for url: {file}" + assert proc.stderr == expect.rstrip() From 48884de814d7dd30ffa31789905852be3354e0ca Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 10:43:53 -0500 Subject: [PATCH 31/37] Update test_bad_url.py Remove a failing method. --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 92d10ceede6..b3562d231d2 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -12,4 +12,4 @@ def test_filenotfound_error_message(script: Any) -> None: assert proc.returncode == 1 file = "file:///unexistent_file" expect = f"ERROR: 404 Client Error: FileNotFoundError for url: {file}" - assert proc.stderr == expect.rstrip() + assert proc.stderr == expect From e14674c55818206a7dd3d86990b82459762aa04f Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 17 Aug 2021 11:00:29 -0500 Subject: [PATCH 32/37] Update test_bad_url.py Modify the tests. --- tests/functional/test_bad_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index b3562d231d2..241eee92143 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -12,4 +12,4 @@ def test_filenotfound_error_message(script: Any) -> None: assert proc.returncode == 1 file = "file:///unexistent_file" expect = f"ERROR: 404 Client Error: FileNotFoundError for url: {file}" - assert proc.stderr == expect + assert proc.stderr.rstrip() == expect From 79a65071627589559ca037365df7c9f08a57aa38 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 19 Aug 2021 07:51:55 -0500 Subject: [PATCH 33/37] Update test_bad_url.py Reduce the string sizes. --- tests/functional/test_bad_url.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index 241eee92143..eee81840f99 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -10,6 +10,8 @@ def test_filenotfound_error_message(script: Any) -> None: # by running "pip install -r file:nonexistent_file" proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) assert proc.returncode == 1 - file = "file:///unexistent_file" - expect = f"ERROR: 404 Client Error: FileNotFoundError for url: {file}" + expect = ( + "ERROR: 404 Client Error: FileNotFoundError for url: " + "file:///unexistent_file" + ) assert proc.stderr.rstrip() == expect From 6f0369c8d67698317cbe0176e97541907c903464 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 19 Aug 2021 07:55:07 -0500 Subject: [PATCH 34/37] Update test_bad_url.py Add some indentations to the string formatting. --- tests/functional/test_bad_url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index eee81840f99..bbd19098464 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -11,7 +11,7 @@ def test_filenotfound_error_message(script: Any) -> None: proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) assert proc.returncode == 1 expect = ( - "ERROR: 404 Client Error: FileNotFoundError for url: " - "file:///unexistent_file" + "ERROR: 404 Client Error: FileNotFoundError for url: " + "file:///unexistent_file" ) assert proc.stderr.rstrip() == expect From 37242e0209fb05baa9cde053fb0272d131ce127c Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 21 Sep 2021 14:31:56 -0500 Subject: [PATCH 35/37] Update test_bad_url.py Adjust the expected error message. --- tests/functional/test_bad_url.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/functional/test_bad_url.py b/tests/functional/test_bad_url.py index bbd19098464..bc3a987e6f2 100644 --- a/tests/functional/test_bad_url.py +++ b/tests/functional/test_bad_url.py @@ -11,7 +11,6 @@ def test_filenotfound_error_message(script: Any) -> None: proc = script.pip("install", "-r", "file:unexistent_file", expect_error=True) assert proc.returncode == 1 expect = ( - "ERROR: 404 Client Error: FileNotFoundError for url: " - "file:///unexistent_file" + "ERROR: 404 Client Error: FileNotFoundError for url: file:///unexistent_file" ) assert proc.stderr.rstrip() == expect From dee894b7bf2feb6a2a52d65b3f81935af68bd28a Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Fri, 8 Oct 2021 12:16:00 +0100 Subject: [PATCH 36/37] Update news/10263.bugfix.rst --- news/10263.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/10263.bugfix.rst b/news/10263.bugfix.rst index 572f1941e95..f2e2929a5bc 100644 --- a/news/10263.bugfix.rst +++ b/news/10263.bugfix.rst @@ -1 +1 @@ -Return better error messages if a file/URL is not found. +Present a better error message, when a `file:` URL is not found. From dd1103fb9e23518bac71c2fff026bee605c3836b Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Fri, 8 Oct 2021 12:58:33 +0100 Subject: [PATCH 37/37] Update news/10263.bugfix.rst --- news/10263.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/10263.bugfix.rst b/news/10263.bugfix.rst index f2e2929a5bc..83e29f6bc0a 100644 --- a/news/10263.bugfix.rst +++ b/news/10263.bugfix.rst @@ -1 +1 @@ -Present a better error message, when a `file:` URL is not found. +Present a better error message, when a ``file:`` URL is not found.