From 5cb46f572d722b313e2e2e22b60ae069f7792d95 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 4 Jun 2022 17:08:29 -0700 Subject: [PATCH] fix more tests --- jrnl/install.py | 8 ++++++- jrnl/upgrade.py | 1 - tests/bdd/features/encrypt.feature | 6 +++--- tests/bdd/features/format.feature | 2 +- tests/bdd/features/multiple_journals.feature | 2 +- tests/bdd/features/star.feature | 3 ++- tests/bdd/features/upgrade.feature | 2 +- tests/bdd/features/write.feature | 14 ++++++------- tests/lib/fixtures.py | 22 ++++++++++++++------ tests/lib/then_steps.py | 6 +++--- 10 files changed, 40 insertions(+), 26 deletions(-) diff --git a/jrnl/install.py b/jrnl/install.py index 4aff7cac..d119787c 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -110,7 +110,13 @@ def install(): # Where to create the journal? default_journal_path = get_default_journal_path() user_given_path = print_msg( - Message(MsgText.InstallJournalPathQuestion, MsgStyle.PROMPT), + Message( + MsgText.InstallJournalPathQuestion, + MsgStyle.PROMPT, + params={ + "default_journal_path": default_journal_path, + }, + ), get_input=True, ) journal_path = os.path.abspath(user_given_path or default_journal_path) diff --git a/jrnl/upgrade.py b/jrnl/upgrade.py index fc8c581e..4108272d 100644 --- a/jrnl/upgrade.py +++ b/jrnl/upgrade.py @@ -83,7 +83,6 @@ def upgrade_jrnl(config_path): kwargs = { # longest journal name "pad": max([len(journal) for journal in config["journals"]]), - "version": __version__, } _print_journal_summary( diff --git a/tests/bdd/features/encrypt.feature b/tests/bdd/features/encrypt.feature index 7f466c1d..5d415248 100644 --- a/tests/bdd/features/encrypt.feature +++ b/tests/bdd/features/encrypt.feature @@ -2,8 +2,8 @@ Feature: Encrypting and decrypting journals Scenario: Decrypting a journal Given we use the config "encrypted.yaml" - # And we use the password "bad doggie no biscuit" if prompted - When we run "jrnl --decrypt" and enter "bad doggie no biscuit" + And we use the password "bad doggie no biscuit" if prompted + When we run "jrnl --decrypt" Then the output should contain "Journal decrypted" And the config for journal "default" should contain "encrypt: false" When we run "jrnl -99 --short" @@ -46,7 +46,7 @@ Feature: Encrypting and decrypting journals Scenario Outline: Running jrnl with encrypt: true on unencryptable journals Given we use the config "" When we run "jrnl --config-override encrypt true here is a new entry" - Then the error output should contain "this type of journal can't be encrypted" + Then the error output should contain "journal can't be encrypted" Examples: configs | config_file | diff --git a/tests/bdd/features/format.feature b/tests/bdd/features/format.feature index 3f0decb2..b1c120ad 100644 --- a/tests/bdd/features/format.feature +++ b/tests/bdd/features/format.feature @@ -429,7 +429,7 @@ Feature: Custom formats Given we use the config "" And we use the password "test" if prompted When we run "jrnl --export yaml --file nonexistent_dir" - Then the output should contain "YAML export must be to individual files" + Then the output should contain "YAML export must be to a directory" And the output should not contain "Traceback" Examples: configs diff --git a/tests/bdd/features/multiple_journals.feature b/tests/bdd/features/multiple_journals.feature index 35df069b..09bd71fd 100644 --- a/tests/bdd/features/multiple_journals.feature +++ b/tests/bdd/features/multiple_journals.feature @@ -87,7 +87,7 @@ Feature: Multiple journals these three eyes these three eyes n - Then the output should contain "Encrypted journal 'new_encrypted' created" + Then the output should contain "Journal 'new_encrypted' created at" Scenario: Read and write to journal with emoji name Given we use the config "multiple.yaml" diff --git a/tests/bdd/features/star.feature b/tests/bdd/features/star.feature index f1340f7b..f59a7ecc 100644 --- a/tests/bdd/features/star.feature +++ b/tests/bdd/features/star.feature @@ -29,7 +29,8 @@ Feature: Starring entries Scenario: Starring an entry will mark it in an encrypted journal Given we use the config "encrypted.yaml" - When we run "jrnl 20 july 2013 *: Best day of my life!" and enter "bad doggie no biscuit" + And we use the password "bad doggie no biscuit" if prompted + When we run "jrnl 20 july 2013 *: Best day of my life!" Then the output should contain "Entry added" When we run "jrnl -on 2013-07-20 -starred" and enter "bad doggie no biscuit" Then the output should contain "2013-07-20 09:00 Best day of my life!" diff --git a/tests/bdd/features/upgrade.feature b/tests/bdd/features/upgrade.feature index e5714a82..23628eb7 100644 --- a/tests/bdd/features/upgrade.feature +++ b/tests/bdd/features/upgrade.feature @@ -49,6 +49,6 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x When we run "jrnl --list" and enter Y bad doggie no biscuit - Then the output should contain "Error: features/journals/missing.journal does not exist." + Then the output should contain "features/journals/missing.journal does not exist." And the output should contain "We're all done" And we should get no error diff --git a/tests/bdd/features/write.feature b/tests/bdd/features/write.feature index 608bc772..64931960 100644 --- a/tests/bdd/features/write.feature +++ b/tests/bdd/features/write.feature @@ -233,8 +233,7 @@ Feature: Writing new entries. And we append to the editor if opened [2021-11-13] worked on jrnl tests When we run "jrnl --edit" - Then the output should contain - [1 entry added] + Then the output should contain "1 entry added" Examples: configs | config_file | @@ -252,8 +251,7 @@ Feature: Writing new entries. [2021-11-12] worked on jrnl tests again [2021-11-13] worked on jrnl tests a little bit more When we run "jrnl --edit" - Then the output should contain - [3 entries added] + Then the error output should contain "3 entries added" Examples: configs | config_file | @@ -269,8 +267,8 @@ Feature: Writing new entries. And we write to the editor if opened [2021-11-13] I am replacing my whole journal with this entry When we run "jrnl --edit" - Then the output should contain - [2 entries deleted, 1 entry modified] + Then the output should contain "2 entries deleted" + Then the output should contain "1 entry modified" Examples: configs | config_file | @@ -287,7 +285,7 @@ Feature: Writing new entries. [2021-11-13] I am replacing the last entry with this entry When we run "jrnl --edit -1" Then the output should contain - [1 entry modified] + 1 entry modified Examples: configs | config_file | @@ -304,7 +302,7 @@ Feature: Writing new entries. This is a small addendum to my latest entry. When we run "jrnl --edit" Then the output should contain - [1 entry modified] + 1 entry modified Examples: configs | config_file | diff --git a/tests/lib/fixtures.py b/tests/lib/fixtures.py index c843eacf..109782ee 100644 --- a/tests/lib/fixtures.py +++ b/tests/lib/fixtures.py @@ -201,6 +201,8 @@ def should_not(): return False +# @todo is this named properly? does it need to be merged with user_input? does +# it only mock piped input? or also user input? @fixture def mock_piped_input(request, is_tty): def _mock_piped_input(): @@ -209,7 +211,7 @@ def mock_piped_input(request, is_tty): if piped_input is None: piped_input = Exception("Unexpected call for piped input") else: - piped_input = piped_input.splitlines() + piped_input = [piped_input] if is_tty: piped_input = [] @@ -225,21 +227,29 @@ def mock_user_input(request): from rich.console import Console user_input = get_fixture(request, "all_input", None) + password_input = get_fixture(request, "password", None) if user_input is None: user_input = Exception("Unexpected call for user input") else: - user_input = user_input.splitlines() + user_input = iter(user_input.splitlines()) + + if password_input is None: + password_input = Exception("Unexpected call for password input") + + def mock_console_input(**kwargs): + if kwargs["password"]: + return password_input + else: + return next(user_input) mock_console = Mock(wraps=Console(stderr=True)) mock_console.input = Mock() - mock_console.input.side_effect = user_input + mock_console.input = mock_console_input return patch("jrnl.output._get_console", return_value=mock_console) - return { - "user_input": _mock_user_input - } + return {"user_input": _mock_user_input} @fixture diff --git a/tests/lib/then_steps.py b/tests/lib/then_steps.py index f13d27bf..a3b1c9a7 100644 --- a/tests/lib/then_steps.py +++ b/tests/lib/then_steps.py @@ -167,12 +167,12 @@ def config_var_in_memory( @then("we should be prompted for a password") def password_was_called(cli_run): - assert cli_run["mocks"]["rich_console_input"].called + assert cli_run["mocks"]["user_input"].called @then("we should not be prompted for a password") def password_was_not_called(cli_run): - assert not cli_run["mocks"]["rich_console_input"].called + assert not cli_run["mocks"]["user_input"].called @then(parse("the cache directory should contain the files\n{file_list}")) @@ -364,7 +364,7 @@ def count_editor_args(num_args, cli_run, editor_state, should_or_should_not): def stdin_prompt_called(cli_run, should_or_should_not): we_should = parse_should_or_should_not(should_or_should_not) - assert cli_run["mocks"]["stdin"].called == we_should + assert cli_run["mocks"]["piped_input"].called == we_should @then(parse('the editor filename should end with "{suffix}"'))