mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
fix more tests
This commit is contained in:
parent
c325ba38ea
commit
5cb46f572d
10 changed files with 40 additions and 26 deletions
|
@ -110,7 +110,13 @@ def install():
|
||||||
# Where to create the journal?
|
# Where to create the journal?
|
||||||
default_journal_path = get_default_journal_path()
|
default_journal_path = get_default_journal_path()
|
||||||
user_given_path = print_msg(
|
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,
|
get_input=True,
|
||||||
)
|
)
|
||||||
journal_path = os.path.abspath(user_given_path or default_journal_path)
|
journal_path = os.path.abspath(user_given_path or default_journal_path)
|
||||||
|
|
|
@ -83,7 +83,6 @@ def upgrade_jrnl(config_path):
|
||||||
kwargs = {
|
kwargs = {
|
||||||
# longest journal name
|
# longest journal name
|
||||||
"pad": max([len(journal) for journal in config["journals"]]),
|
"pad": max([len(journal) for journal in config["journals"]]),
|
||||||
"version": __version__,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_print_journal_summary(
|
_print_journal_summary(
|
||||||
|
|
|
@ -2,8 +2,8 @@ Feature: Encrypting and decrypting journals
|
||||||
|
|
||||||
Scenario: Decrypting a journal
|
Scenario: Decrypting a journal
|
||||||
Given we use the config "encrypted.yaml"
|
Given we use the config "encrypted.yaml"
|
||||||
# And we use the password "bad doggie no biscuit" if prompted
|
And we use the password "bad doggie no biscuit" if prompted
|
||||||
When we run "jrnl --decrypt" and enter "bad doggie no biscuit"
|
When we run "jrnl --decrypt"
|
||||||
Then the output should contain "Journal decrypted"
|
Then the output should contain "Journal decrypted"
|
||||||
And the config for journal "default" should contain "encrypt: false"
|
And the config for journal "default" should contain "encrypt: false"
|
||||||
When we run "jrnl -99 --short"
|
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
|
Scenario Outline: Running jrnl with encrypt: true on unencryptable journals
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
When we run "jrnl --config-override encrypt true here is a new entry"
|
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
|
Examples: configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
|
|
@ -429,7 +429,7 @@ Feature: Custom formats
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
When we run "jrnl --export yaml --file nonexistent_dir"
|
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"
|
And the output should not contain "Traceback"
|
||||||
|
|
||||||
Examples: configs
|
Examples: configs
|
||||||
|
|
|
@ -87,7 +87,7 @@ Feature: Multiple journals
|
||||||
these three eyes
|
these three eyes
|
||||||
these three eyes
|
these three eyes
|
||||||
n
|
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
|
Scenario: Read and write to journal with emoji name
|
||||||
Given we use the config "multiple.yaml"
|
Given we use the config "multiple.yaml"
|
||||||
|
|
|
@ -29,7 +29,8 @@ Feature: Starring entries
|
||||||
|
|
||||||
Scenario: Starring an entry will mark it in an encrypted journal
|
Scenario: Starring an entry will mark it in an encrypted journal
|
||||||
Given we use the config "encrypted.yaml"
|
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"
|
Then the output should contain "Entry added"
|
||||||
When we run "jrnl -on 2013-07-20 -starred" and enter "bad doggie no biscuit"
|
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!"
|
Then the output should contain "2013-07-20 09:00 Best day of my life!"
|
||||||
|
|
|
@ -49,6 +49,6 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
|
||||||
When we run "jrnl --list" and enter
|
When we run "jrnl --list" and enter
|
||||||
Y
|
Y
|
||||||
bad doggie no biscuit
|
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 the output should contain "We're all done"
|
||||||
And we should get no error
|
And we should get no error
|
||||||
|
|
|
@ -233,8 +233,7 @@ Feature: Writing new entries.
|
||||||
And we append to the editor if opened
|
And we append to the editor if opened
|
||||||
[2021-11-13] worked on jrnl tests
|
[2021-11-13] worked on jrnl tests
|
||||||
When we run "jrnl --edit"
|
When we run "jrnl --edit"
|
||||||
Then the output should contain
|
Then the output should contain "1 entry added"
|
||||||
[1 entry added]
|
|
||||||
|
|
||||||
Examples: configs
|
Examples: configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
@ -252,8 +251,7 @@ Feature: Writing new entries.
|
||||||
[2021-11-12] worked on jrnl tests again
|
[2021-11-12] worked on jrnl tests again
|
||||||
[2021-11-13] worked on jrnl tests a little bit more
|
[2021-11-13] worked on jrnl tests a little bit more
|
||||||
When we run "jrnl --edit"
|
When we run "jrnl --edit"
|
||||||
Then the output should contain
|
Then the error output should contain "3 entries added"
|
||||||
[3 entries added]
|
|
||||||
|
|
||||||
Examples: configs
|
Examples: configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
@ -269,8 +267,8 @@ Feature: Writing new entries.
|
||||||
And we write to the editor if opened
|
And we write to the editor if opened
|
||||||
[2021-11-13] I am replacing my whole journal with this entry
|
[2021-11-13] I am replacing my whole journal with this entry
|
||||||
When we run "jrnl --edit"
|
When we run "jrnl --edit"
|
||||||
Then the output should contain
|
Then the output should contain "2 entries deleted"
|
||||||
[2 entries deleted, 1 entry modified]
|
Then the output should contain "1 entry modified"
|
||||||
|
|
||||||
Examples: configs
|
Examples: configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
@ -287,7 +285,7 @@ Feature: Writing new entries.
|
||||||
[2021-11-13] I am replacing the last entry with this entry
|
[2021-11-13] I am replacing the last entry with this entry
|
||||||
When we run "jrnl --edit -1"
|
When we run "jrnl --edit -1"
|
||||||
Then the output should contain
|
Then the output should contain
|
||||||
[1 entry modified]
|
1 entry modified
|
||||||
|
|
||||||
Examples: configs
|
Examples: configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
@ -304,7 +302,7 @@ Feature: Writing new entries.
|
||||||
This is a small addendum to my latest entry.
|
This is a small addendum to my latest entry.
|
||||||
When we run "jrnl --edit"
|
When we run "jrnl --edit"
|
||||||
Then the output should contain
|
Then the output should contain
|
||||||
[1 entry modified]
|
1 entry modified
|
||||||
|
|
||||||
Examples: configs
|
Examples: configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
|
|
@ -201,6 +201,8 @@ def should_not():
|
||||||
return False
|
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
|
@fixture
|
||||||
def mock_piped_input(request, is_tty):
|
def mock_piped_input(request, is_tty):
|
||||||
def _mock_piped_input():
|
def _mock_piped_input():
|
||||||
|
@ -209,7 +211,7 @@ def mock_piped_input(request, is_tty):
|
||||||
if piped_input is None:
|
if piped_input is None:
|
||||||
piped_input = Exception("Unexpected call for piped input")
|
piped_input = Exception("Unexpected call for piped input")
|
||||||
else:
|
else:
|
||||||
piped_input = piped_input.splitlines()
|
piped_input = [piped_input]
|
||||||
|
|
||||||
if is_tty:
|
if is_tty:
|
||||||
piped_input = []
|
piped_input = []
|
||||||
|
@ -225,21 +227,29 @@ def mock_user_input(request):
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
user_input = get_fixture(request, "all_input", None)
|
user_input = get_fixture(request, "all_input", None)
|
||||||
|
password_input = get_fixture(request, "password", None)
|
||||||
|
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
user_input = Exception("Unexpected call for user input")
|
user_input = Exception("Unexpected call for user input")
|
||||||
else:
|
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 = Mock(wraps=Console(stderr=True))
|
||||||
mock_console.input = Mock()
|
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 patch("jrnl.output._get_console", return_value=mock_console)
|
||||||
|
|
||||||
return {
|
return {"user_input": _mock_user_input}
|
||||||
"user_input": _mock_user_input
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
|
|
|
@ -167,12 +167,12 @@ def config_var_in_memory(
|
||||||
|
|
||||||
@then("we should be prompted for a password")
|
@then("we should be prompted for a password")
|
||||||
def password_was_called(cli_run):
|
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")
|
@then("we should not be prompted for a password")
|
||||||
def password_was_not_called(cli_run):
|
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}"))
|
@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):
|
def stdin_prompt_called(cli_run, should_or_should_not):
|
||||||
we_should = parse_should_or_should_not(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}"'))
|
@then(parse('the editor filename should end with "{suffix}"'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue