From d5bef3f81060aec74b1bfdb04fb643af38e92d80 Mon Sep 17 00:00:00 2001 From: Darren Dormer Date: Mon, 29 Jul 2019 16:43:25 +0200 Subject: [PATCH 1/7] Prevent dry-run log message from being printed with --quiet option. --- piptools/scripts/compile.py | 2 +- tests/test_cli_compile.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index b2fb4a9c4..b1dcbf388 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -415,4 +415,4 @@ def cli( ) if dry_run: - log.warning("Dry-run, so nothing updated.") + log.info("Dry-run, so nothing updated.") diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 868018a5c..0e88f37a3 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -459,7 +459,27 @@ def test_quiet_option(runner): pass out = runner.invoke(cli, ["--quiet", "-n", "requirements"]) # Pinned requirements result has not been written to output - assert "Dry-run, so nothing updated." == out.stderr.strip() + assert "" == out.stderr.strip() + + +def test_dry_run_noisy_option(runner): + with open("requirements", "w"): + pass + out = runner.invoke(cli, ["--dry-run", "-n", "requirements"]) + # Dry-run massage has been written to output + assert "Dry-run, so nothing updated." in out.stderr.strip() + + +def test_dry_run_quiet_option(runner): + with open("requirements", "w"): + pass + out = runner.invoke(cli, ["--dry-run", "--quiet", "-n", "requirements"]) + # Dry-run massage has not been written to output. (An empty out.stderr + # results in a ValueError raised by Click) + try: + assert "Dry-run, so nothing updated." not in out.stderr.strip() + except ValueError: + pass def test_generate_hashes_with_editable(runner): From 86dfdc4c4b09a00f87e8c0a9bd22b9f35c6d80e2 Mon Sep 17 00:00:00 2001 From: Darren Dormer Date: Mon, 29 Jul 2019 17:01:18 +0200 Subject: [PATCH 2/7] Catch ValueError in test_cli_compile when out.stderr has no value. --- tests/test_cli_compile.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 0e88f37a3..d4e3062b8 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -458,8 +458,12 @@ def test_quiet_option(runner): with open("requirements", "w"): pass out = runner.invoke(cli, ["--quiet", "-n", "requirements"]) - # Pinned requirements result has not been written to output - assert "" == out.stderr.strip() + # Pinned requirements result has not been written to output. (An empty + # out.stderr results in a ValueError raised by Click) + try: + assert "" == out.stderr.strip() + except ValueError: + pass def test_dry_run_noisy_option(runner): From f6d999d82a80eee75f936f1c0f928e66b4a85639 Mon Sep 17 00:00:00 2001 From: Darren Dormer Date: Mon, 12 Aug 2019 14:17:19 +0200 Subject: [PATCH 3/7] Improve test logic for test_quiet_option and test_dry_run_noisy_option. --- tests/test_cli_compile.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index d4e3062b8..cce28ceaf 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -458,12 +458,8 @@ def test_quiet_option(runner): with open("requirements", "w"): pass out = runner.invoke(cli, ["--quiet", "-n", "requirements"]) - # Pinned requirements result has not been written to output. (An empty - # out.stderr results in a ValueError raised by Click) - try: - assert "" == out.stderr.strip() - except ValueError: - pass + # Pinned requirements result has not been written to output. + assert b"" == out.stderr_bytes def test_dry_run_noisy_option(runner): @@ -478,12 +474,8 @@ def test_dry_run_quiet_option(runner): with open("requirements", "w"): pass out = runner.invoke(cli, ["--dry-run", "--quiet", "-n", "requirements"]) - # Dry-run massage has not been written to output. (An empty out.stderr - # results in a ValueError raised by Click) - try: - assert "Dry-run, so nothing updated." not in out.stderr.strip() - except ValueError: - pass + # Dry-run message has not been written to output. + assert b"" == out.stderr_bytes def test_generate_hashes_with_editable(runner): From 35a84335937827c9323b2f4db6e509a0329d3612 Mon Sep 17 00:00:00 2001 From: Darren Dormer Date: Mon, 12 Aug 2019 14:18:17 +0200 Subject: [PATCH 4/7] Remove redundant cli parameter from dry-run tests. --- tests/test_cli_compile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index cce28ceaf..f1fdd7cc6 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -465,15 +465,15 @@ def test_quiet_option(runner): def test_dry_run_noisy_option(runner): with open("requirements", "w"): pass - out = runner.invoke(cli, ["--dry-run", "-n", "requirements"]) # Dry-run massage has been written to output assert "Dry-run, so nothing updated." in out.stderr.strip() + out = runner.invoke(cli, ["--dry-run", "requirements"]) def test_dry_run_quiet_option(runner): with open("requirements", "w"): pass - out = runner.invoke(cli, ["--dry-run", "--quiet", "-n", "requirements"]) + out = runner.invoke(cli, ["--dry-run", "--quiet", "requirements"]) # Dry-run message has not been written to output. assert b"" == out.stderr_bytes From b25239ce5496154178a521bd5858c2b877306b16 Mon Sep 17 00:00:00 2001 From: Darren Dormer Date: Mon, 12 Aug 2019 14:19:18 +0200 Subject: [PATCH 5/7] Improve test by prefering splitlines over strip. --- tests/test_cli_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index f1fdd7cc6..559b92359 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -466,8 +466,8 @@ def test_dry_run_noisy_option(runner): with open("requirements", "w"): pass # Dry-run massage has been written to output - assert "Dry-run, so nothing updated." in out.stderr.strip() out = runner.invoke(cli, ["--dry-run", "requirements"]) + assert "Dry-run, so nothing updated." in out.stderr.splitlines() def test_dry_run_quiet_option(runner): From 52f53e46004bfe84aa215eae43a5e29c072c7bf2 Mon Sep 17 00:00:00 2001 From: Darren Dormer Date: Mon, 12 Aug 2019 14:19:51 +0200 Subject: [PATCH 6/7] Fix typo. --- tests/test_cli_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 559b92359..63cca46b6 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -465,8 +465,8 @@ def test_quiet_option(runner): def test_dry_run_noisy_option(runner): with open("requirements", "w"): pass - # Dry-run massage has been written to output out = runner.invoke(cli, ["--dry-run", "requirements"]) + # Dry-run message has been written to output assert "Dry-run, so nothing updated." in out.stderr.splitlines() From fba810d70f3aca20e99936fb1b35b48b15de590f Mon Sep 17 00:00:00 2001 From: Darren Dormer Date: Mon, 12 Aug 2019 14:28:40 +0200 Subject: [PATCH 7/7] Minor improvement to test assertion. --- tests/test_cli_compile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 63cca46b6..5895ff67f 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -459,7 +459,7 @@ def test_quiet_option(runner): pass out = runner.invoke(cli, ["--quiet", "-n", "requirements"]) # Pinned requirements result has not been written to output. - assert b"" == out.stderr_bytes + assert not out.stderr_bytes def test_dry_run_noisy_option(runner): @@ -475,7 +475,7 @@ def test_dry_run_quiet_option(runner): pass out = runner.invoke(cli, ["--dry-run", "--quiet", "requirements"]) # Dry-run message has not been written to output. - assert b"" == out.stderr_bytes + assert not out.stderr_bytes def test_generate_hashes_with_editable(runner):