From 4001d673a10342cbf177e96e4ac7fde120061c79 Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Tue, 12 Jan 2021 13:32:13 +0100 Subject: [PATCH 1/4] Test various usages of allow_dirty in config Currently, this one fails: test_dirty_work_dir_with_allow_dirty_false_in_config_file_fails_with_warning --- tests/test_cli.py | 49 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 748d4860..6a940a1c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -579,14 +579,12 @@ def test_bump_version_missing_part(tmpdir): main(['bugfix', '--current-version', '1.0.0', 'file5']) -def test_dirty_work_dir(tmpdir, vcs): +def test_dirty_work_dir_without_allow_dirty_fails_with_warning(tmpdir, vcs): tmpdir.chdir() check_call([vcs, "init"]) tmpdir.join("dirty").write("i'm dirty") check_call([vcs, "add", "dirty"]) - vcs_name = "Mercurial" if vcs == "hg" else "Git" - vcs_output = "A dirty" if vcs == "hg" else "A dirty" with pytest.raises(exceptions.WorkingDirectoryIsDirtyException): with LogCapture() as log_capture: @@ -600,14 +598,41 @@ def test_dirty_work_dir(tmpdir, vcs): "{}\n" "\n" "Use --allow-dirty to override this if you know what you're doing.".format( - vcs_name, - vcs_output + "Mercurial" if vcs == "hg" else "Git", + "A dirty" if vcs == "hg" else "A dirty", ) ) ) -def test_force_dirty_work_dir(tmpdir, vcs): +def test_dirty_work_dir_with_allow_dirty_false_in_config_file_fails_with_warning(tmpdir, vcs): + tmpdir.chdir() + check_call([vcs, "init"]) + tmpdir.join(".bumpversion.cfg").write("[bumpversion]\nallow_dirty = False\ncurrent_version = 1.0.0") + tmpdir.join("dirty").write("dirty file version 1.0.0") + + check_call([vcs, "add", "dirty"]) + + with pytest.raises(exceptions.WorkingDirectoryIsDirtyException): + with LogCapture() as log_capture: + main(['patch', '--new-version', '2.0.0', 'dirty']) + + log_capture.check_present( + ( + 'bumpversion.cli', + 'WARNING', + "{} working directory is not clean:\n" + "{}\n" + "\n" + "Use --allow-dirty to override this if you know what you're doing.".format( + "Mercurial" if vcs == "hg" else "Git", + "A dirty" if vcs == "hg" else "A dirty", + ) + ) + ) + + +def test_dirty_work_dir_with_allow_dirty_argument_passes(tmpdir, vcs): tmpdir.chdir() check_call([vcs, "init"]) tmpdir.join("dirty2").write("i'm dirty! 1.1.1") @@ -625,6 +650,18 @@ def test_force_dirty_work_dir(tmpdir, vcs): assert "i'm dirty! 1.1.2" == tmpdir.join("dirty2").read() +def test_dirty_work_with_allow_dirty_true_in_config_file_passes(tmpdir, vcs): + tmpdir.chdir() + check_call([vcs, "init"]) + tmpdir.join(".bumpversion.cfg").write("[bumpversion]\nallow_dirty = True\ncurrent_version = 1.0.0") + tmpdir.join("dirty").write("dirty file version 1.0.0") + + check_call([vcs, "add", "dirty"]) + + main(['patch', '--new-version', '2.0.0', 'dirty']) + assert "dirty file version 2.0.0" == tmpdir.join("dirty").read() + + def test_bump_major(tmpdir): tmpdir.join("fileMAJORBUMP").write("4.2.8") tmpdir.chdir() From 926048aa8b6da11baa94dca448ddb4c45882eba9 Mon Sep 17 00:00:00 2001 From: "Reynolds, AJ (ar380v)" Date: Fri, 1 Jan 2021 14:57:14 -0600 Subject: [PATCH 2/4] Corrected issues with the boolean operators in the config file being treated as strings. --- bumpversion/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index b107e10d..621b9a2f 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -294,7 +294,7 @@ def _load_configuration(config_file, explicit_config, defaults): except NoOptionError: pass # no default value then ;) - for boolvaluename in ("commit", "tag", "dry_run"): + for boolvaluename in ("commit", "tag", "dry_run", "allow-dirty", "push", "sign_tags"): try: defaults[boolvaluename] = config.getboolean( "bumpversion", boolvaluename From 7062a18408f5c107bf835c81ca8fedf5262e27e2 Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Tue, 12 Jan 2021 21:19:58 +0100 Subject: [PATCH 3/4] Fix typo This test now passes: test_dirty_work_dir_with_allow_dirty_false_in_config_file_fails_with_warning --- bumpversion/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index 621b9a2f..a236f8bf 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -294,7 +294,7 @@ def _load_configuration(config_file, explicit_config, defaults): except NoOptionError: pass # no default value then ;) - for boolvaluename in ("commit", "tag", "dry_run", "allow-dirty", "push", "sign_tags"): + for boolvaluename in ("commit", "tag", "dry_run", "allow_dirty", "push", "sign_tags"): try: defaults[boolvaluename] = config.getboolean( "bumpversion", boolvaluename From 5ad4534a3539fc3740876fe32a5299c123067a9e Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Tue, 12 Jan 2021 21:31:51 +0100 Subject: [PATCH 4/4] Move list of FLAG_ARGUMENTS to a constant --- bumpversion/cli.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index a236f8bf..5e471f89 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -59,6 +59,14 @@ time_context = {"now": datetime.now(), "utcnow": datetime.utcnow()} special_char_context = {c: c for c in ("#", ";")} +FLAG_ARGUMENTS = [ + "commit", + "tag", + "dry_run", + "allow_dirty", + "push", + "sign_tags", +] OPTIONAL_ARGUMENTS_THAT_TAKE_VALUES = [ "--config-file", @@ -294,13 +302,13 @@ def _load_configuration(config_file, explicit_config, defaults): except NoOptionError: pass # no default value then ;) - for boolvaluename in ("commit", "tag", "dry_run", "allow_dirty", "push", "sign_tags"): + for flag_argument in FLAG_ARGUMENTS: try: - defaults[boolvaluename] = config.getboolean( - "bumpversion", boolvaluename + defaults[flag_argument] = config.getboolean( + "bumpversion", flag_argument ) except NoOptionError: - pass # no default value then ;) + pass # no default value then (like, False-y) part_configs = {} files = []