From 6120700485428bd626a3a06e6a515094ba55ba45 Mon Sep 17 00:00:00 2001 From: Vikram Jayanthi Date: Thu, 16 Jul 2020 13:03:54 -0700 Subject: [PATCH 1/6] Logged config location with f-strings --- tests/test_utils.py | 2 +- twine/utils.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index e6d890eb..dec34b92 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -295,7 +295,7 @@ def test_check_status_code_for_missing_status_code( captured = capsys.readouterr() if verbose: - assert captured.out == "Content received from server:\nForbidden\n" + assert "Content received from server:\nForbidden\n" in captured.out else: assert captured.out == "NOTE: Try --verbose to see response content.\n" diff --git a/twine/utils.py b/twine/utils.py index 113b427c..cc12801c 100644 --- a/twine/utils.py +++ b/twine/utils.py @@ -64,6 +64,8 @@ def get_config(path: str = "~/.pypirc") -> Dict[str, RepositoryConfig]: # Expand user strings in the path path = os.path.expanduser(path) + logger.info(f"Config Location: {path}") + # Parse the rc file if os.path.isfile(path): parser.read(path) From 00ea32ee27aca1db29fe5de7b2ad042585165780 Mon Sep 17 00:00:00 2001 From: Vikram Jayanthi Date: Fri, 24 Jul 2020 15:56:04 -0700 Subject: [PATCH 2/6] capsys.disabled erroring/not working --- tests/test_utils.py | 22 ++++++++++++++++++++-- twine/utils.py | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index dec34b92..5477b123 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -50,6 +50,23 @@ def test_get_config(tmpdir): }, } +@pytest.mark.parametrize( + "verbose", [True, False], +) +def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): + """Log the location of the .pypirc config used by the user.""" + pypirc = os.path.join(str(tmpdir), ".pypirc") + + with capsys.disabled(): + make_settings(verbose=verbose) + + utils.get_config(pypirc) + + captured = capsys.readouterr() + if verbose: + assert captured.out == f"Using configuration from {pypirc}\n" + else: + assert captured.out == "" def test_get_config_no_distutils(tmpdir): """Upload by default to PyPI if an index server is not set in .pypirc.""" @@ -287,7 +304,8 @@ def test_check_status_code_for_missing_status_code( text="Forbidden", ) - make_settings(verbose=verbose) + with capsys.disabled(): + make_settings(verbose=verbose) with pytest.raises(requests.HTTPError): utils.check_status_code(response, verbose) @@ -295,7 +313,7 @@ def test_check_status_code_for_missing_status_code( captured = capsys.readouterr() if verbose: - assert "Content received from server:\nForbidden\n" in captured.out + assert captured.out == "Content received from server:\nForbidden\n" else: assert captured.out == "NOTE: Try --verbose to see response content.\n" diff --git a/twine/utils.py b/twine/utils.py index cc12801c..14a9e06b 100644 --- a/twine/utils.py +++ b/twine/utils.py @@ -64,7 +64,7 @@ def get_config(path: str = "~/.pypirc") -> Dict[str, RepositoryConfig]: # Expand user strings in the path path = os.path.expanduser(path) - logger.info(f"Config Location: {path}") + logger.info(f"Using configuration from {path}") # Parse the rc file if os.path.isfile(path): From d4112af35d85e2ba848e95e873bf04ab0754927b Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Thu, 30 Jul 2020 05:35:43 -0400 Subject: [PATCH 3/6] Fix failing output capture --- tests/test_utils.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 5477b123..aedb1020 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -50,6 +50,7 @@ def test_get_config(tmpdir): }, } + @pytest.mark.parametrize( "verbose", [True, False], ) @@ -57,10 +58,7 @@ def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): """Log the location of the .pypirc config used by the user.""" pypirc = os.path.join(str(tmpdir), ".pypirc") - with capsys.disabled(): - make_settings(verbose=verbose) - - utils.get_config(pypirc) + make_settings(verbose=verbose) captured = capsys.readouterr() if verbose: @@ -68,6 +66,7 @@ def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): else: assert captured.out == "" + def test_get_config_no_distutils(tmpdir): """Upload by default to PyPI if an index server is not set in .pypirc.""" pypirc = os.path.join(str(tmpdir), ".pypirc") @@ -304,8 +303,7 @@ def test_check_status_code_for_missing_status_code( text="Forbidden", ) - with capsys.disabled(): - make_settings(verbose=verbose) + make_settings(verbose=verbose) with pytest.raises(requests.HTTPError): utils.check_status_code(response, verbose) @@ -313,9 +311,9 @@ def test_check_status_code_for_missing_status_code( captured = capsys.readouterr() if verbose: - assert captured.out == "Content received from server:\nForbidden\n" + assert captured.out.count("Content received from server:\nForbidden\n") == 1 else: - assert captured.out == "NOTE: Try --verbose to see response content.\n" + assert captured.out.count("NOTE: Try --verbose to see response content.\n") == 1 @pytest.mark.parametrize( From a67e9bf7aa15e0769bf078facecdcc10f3a8bd0b Mon Sep 17 00:00:00 2001 From: Vikram Jayanthi Date: Mon, 3 Aug 2020 11:52:15 -0700 Subject: [PATCH 4/6] Added config location test to test_settings.py --- tests/test_settings.py | 17 +++++++++++++++++ tests/test_utils.py | 28 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index 972b8c76..5ebaf489 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -68,6 +68,23 @@ def test_setup_logging(verbose, log_level): assert logger.level == log_level +@pytest.mark.parametrize( + "verbose", [True, False], +) +def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): + """Log the location of the .pypirc config used by the user.""" + pypirc = os.path.join(str(tmpdir), ".pypirc") + + make_settings(verbose=verbose) + + captured = capsys.readouterr() + + if verbose: + assert captured.out == f"Using configuration from {pypirc}\n" + else: + assert captured.out == "" + + def test_identity_requires_sign(): """Raise an exception when user provides identity but doesn't require sigining.""" with pytest.raises(exceptions.InvalidSigningConfiguration): diff --git a/tests/test_utils.py b/tests/test_utils.py index aedb1020..e109e0c9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -51,20 +51,20 @@ def test_get_config(tmpdir): } -@pytest.mark.parametrize( - "verbose", [True, False], -) -def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): - """Log the location of the .pypirc config used by the user.""" - pypirc = os.path.join(str(tmpdir), ".pypirc") - - make_settings(verbose=verbose) - - captured = capsys.readouterr() - if verbose: - assert captured.out == f"Using configuration from {pypirc}\n" - else: - assert captured.out == "" +# @pytest.mark.parametrize( +# "verbose", [True, False], +# ) +# def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): +# """Log the location of the .pypirc config used by the user.""" +# pypirc = os.path.join(str(tmpdir), ".pypirc") + +# make_settings(verbose=verbose) + +# captured = capsys.readouterr() +# if verbose: +# assert captured.out == f"Using configuration from {pypirc}\n" +# else: +# assert captured.out == "" def test_get_config_no_distutils(tmpdir): From 189b61f771d31f80860fbd10d60670b79e37e123 Mon Sep 17 00:00:00 2001 From: Vikram Jayanthi Date: Mon, 3 Aug 2020 15:36:24 -0700 Subject: [PATCH 5/6] Removed commented out test --- tests/test_utils.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index e109e0c9..d4ba8914 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -51,22 +51,6 @@ def test_get_config(tmpdir): } -# @pytest.mark.parametrize( -# "verbose", [True, False], -# ) -# def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): -# """Log the location of the .pypirc config used by the user.""" -# pypirc = os.path.join(str(tmpdir), ".pypirc") - -# make_settings(verbose=verbose) - -# captured = capsys.readouterr() -# if verbose: -# assert captured.out == f"Using configuration from {pypirc}\n" -# else: -# assert captured.out == "" - - def test_get_config_no_distutils(tmpdir): """Upload by default to PyPI if an index server is not set in .pypirc.""" pypirc = os.path.join(str(tmpdir), ".pypirc") From f4f690df62c812a98b7542dfaa6bfbf0a59acfa7 Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Tue, 4 Aug 2020 09:05:33 -0400 Subject: [PATCH 6/6] Update tests/test_settings.py --- tests/test_settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index 5ebaf489..a17ff388 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -71,8 +71,8 @@ def test_setup_logging(verbose, log_level): @pytest.mark.parametrize( "verbose", [True, False], ) -def test_get_config_log_location(tmpdir, capsys, make_settings, verbose): - """Log the location of the .pypirc config used by the user.""" +def test_print_config_path_if_verbose(tmpdir, capsys, make_settings, verbose): + """Print the location of the .pypirc config used by the user.""" pypirc = os.path.join(str(tmpdir), ".pypirc") make_settings(verbose=verbose)