mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Move remaining tests from behave to pytest (#1346)
* add newer tests to pytest (from behave) * remove 'lib' from gitignore (since we're using it) * fix capitalization in some steps * add 'the editor should not have been called' step * comment out config override step in pytest-bdd since it's not implemented yet * remove test that didn't really test anything * implement some missing steps in pytest-bdd * change comment to match other tests
This commit is contained in:
parent
593245f3fd
commit
7d8823da6d
5 changed files with 167 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -16,7 +16,6 @@ var
|
||||||
sdist
|
sdist
|
||||||
develop-eggs
|
develop-eggs
|
||||||
.installed.cfg
|
.installed.cfg
|
||||||
lib
|
|
||||||
lib64
|
lib64
|
||||||
.python-version
|
.python-version
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,33 @@
|
||||||
Feature: Custom formats
|
Feature: Custom formats
|
||||||
|
|
||||||
|
Scenario Outline: Short printing via --format flag
|
||||||
|
Given we use the config "<config_file>"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --format short -3"
|
||||||
|
Then we should get no error
|
||||||
|
|
||||||
|
Examples: configs
|
||||||
|
| config_file |
|
||||||
|
| basic_onefile.yaml |
|
||||||
|
| basic_encrypted.yaml |
|
||||||
|
| basic_folder.yaml |
|
||||||
|
| basic_dayone.yaml |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario Outline: Pretty Printing aka the Default
|
||||||
|
Given we use the config "<config_file>"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --format pretty -3"
|
||||||
|
Then we should get no error
|
||||||
|
|
||||||
|
Examples: configs
|
||||||
|
| config_file |
|
||||||
|
| basic_onefile.yaml |
|
||||||
|
| basic_encrypted.yaml |
|
||||||
|
| basic_folder.yaml |
|
||||||
|
| basic_dayone.yaml |
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: JSON format
|
Scenario Outline: JSON format
|
||||||
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
|
||||||
|
@ -296,6 +324,22 @@ Feature: Custom formats
|
||||||
| basic_folder.yaml |
|
| basic_folder.yaml |
|
||||||
| basic_dayone.yaml |
|
| basic_dayone.yaml |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario Outline: Export fancy with small linewrap
|
||||||
|
Given we use the config "<config_file>"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --config-override linewrap 35 --format fancy -3"
|
||||||
|
Then we should get no error
|
||||||
|
And the output should be 35 columns wide
|
||||||
|
|
||||||
|
Examples: configs
|
||||||
|
| config_file |
|
||||||
|
| basic_onefile.yaml |
|
||||||
|
| basic_encrypted.yaml |
|
||||||
|
| basic_folder.yaml |
|
||||||
|
| basic_dayone.yaml |
|
||||||
|
|
||||||
|
|
||||||
@todo
|
@todo
|
||||||
Scenario Outline: Exporting fancy
|
Scenario Outline: Exporting fancy
|
||||||
# Needs better emoji support
|
# Needs better emoji support
|
||||||
|
|
91
tests/bdd/features/override.feature
Normal file
91
tests/bdd/features/override.feature
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
Feature: Implementing Runtime Overrides for Select Configuration Keys
|
||||||
|
|
||||||
|
Scenario: Override configured editor with built-in input === editor:''
|
||||||
|
Given we use the config "basic_encrypted.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --config-override editor ''"
|
||||||
|
Then the stdin prompt should have been called
|
||||||
|
And the editor should not have been called
|
||||||
|
|
||||||
|
|
||||||
|
# @todo implement this step in pytest (doesn't currently support overrides)
|
||||||
|
@skip
|
||||||
|
Scenario: Postconfig commands with overrides
|
||||||
|
Given we use the config "basic_encrypted.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --decrypt --config-override highlight false --config-override editor nano"
|
||||||
|
Then the config should contain "highlight: false"
|
||||||
|
Then the editor should not have been called
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Override configured linewrap with a value of 23
|
||||||
|
Given we use the config "simple.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl -2 --config-override linewrap 23 --format fancy"
|
||||||
|
Then the output should be
|
||||||
|
┎─────╮2013-06-09 15:39
|
||||||
|
┃ My ╘═══════════════╕
|
||||||
|
┃ fir st ent ry. │
|
||||||
|
┠╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
||||||
|
┃ Everything is │
|
||||||
|
┃ alright │
|
||||||
|
┖─────────────────────┘
|
||||||
|
┎─────╮2013-06-10 15:40
|
||||||
|
┃ Lif ╘═══════════════╕
|
||||||
|
┃ e is goo d. │
|
||||||
|
┠╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
||||||
|
┃ But I'm better. │
|
||||||
|
┖─────────────────────┘
|
||||||
|
|
||||||
|
|
||||||
|
# @todo implement this step in pytest (doesn't currently support overrides)
|
||||||
|
@skip
|
||||||
|
Scenario: Override color selections with runtime overrides
|
||||||
|
Given we use the config "basic_encrypted.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl -1 --config-override colors.body blue"
|
||||||
|
Then the config should have "colors.body" set to "blue"
|
||||||
|
|
||||||
|
|
||||||
|
# @todo implement this step in pytest (doesn't currently support overrides)
|
||||||
|
@skip
|
||||||
|
Scenario: Apply multiple config overrides
|
||||||
|
Given we use the config "basic_encrypted.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl -1 --config-override colors.body green --config-override editor 'nano'"
|
||||||
|
Then the config should have "colors.body" set to "green"
|
||||||
|
And the config should have "editor" set to "nano"
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Override default journal
|
||||||
|
Given we use the config "basic_dayone.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --config-override journals.default features/journals/simple.journal 20 Mar 2000: The rain in Spain comes from clouds"
|
||||||
|
Then we should get no error
|
||||||
|
And we should see the message "Entry added"
|
||||||
|
When we run "jrnl -3 --config-override journals.default features/journals/simple.journal"
|
||||||
|
Then the output should be
|
||||||
|
2000-03-20 09:00 The rain in Spain comes from clouds
|
||||||
|
|
||||||
|
2013-06-09 15:39 My first entry.
|
||||||
|
| Everything is alright
|
||||||
|
|
||||||
|
2013-06-10 15:40 Life is good.
|
||||||
|
| But I'm better.
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Make an entry into an overridden journal
|
||||||
|
Given we use the config "basic_dayone.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --config-override journals.temp features/journals/simple.journal temp Sep 06 1969: @say Ni"
|
||||||
|
Then we should get no error
|
||||||
|
And we should see the message "Entry added"
|
||||||
|
When we run "jrnl --config-override journals.temp features/journals/simple.journal temp -3"
|
||||||
|
Then the output should be
|
||||||
|
1969-09-06 09:00 @say Ni
|
||||||
|
|
||||||
|
2013-06-09 15:39 My first entry.
|
||||||
|
| Everything is alright
|
||||||
|
|
||||||
|
2013-06-10 15:40 Life is good.
|
||||||
|
| But I'm better.
|
|
@ -9,6 +9,7 @@ scenarios("features/file_storage.feature")
|
||||||
scenarios("features/format.feature")
|
scenarios("features/format.feature")
|
||||||
scenarios("features/import.feature")
|
scenarios("features/import.feature")
|
||||||
scenarios("features/multiple_journals.feature")
|
scenarios("features/multiple_journals.feature")
|
||||||
|
scenarios("features/override.feature")
|
||||||
scenarios("features/password.feature")
|
scenarios("features/password.feature")
|
||||||
scenarios("features/search.feature")
|
scenarios("features/search.feature")
|
||||||
scenarios("features/star.feature")
|
scenarios("features/star.feature")
|
||||||
|
|
|
@ -84,6 +84,14 @@ def output_should_contain_version(cli_run, toml_version):
|
||||||
assert toml_version in out, toml_version
|
assert toml_version in out, toml_version
|
||||||
|
|
||||||
|
|
||||||
|
@then(parse("the output should be {width:d} columns wide"))
|
||||||
|
def output_should_be_columns_wide(cli_run, width):
|
||||||
|
out = cli_run["stdout"]
|
||||||
|
out_lines = out.splitlines()
|
||||||
|
for line in out_lines:
|
||||||
|
assert len(line) <= width
|
||||||
|
|
||||||
|
|
||||||
@then(parse('we should see the message "{text}"'))
|
@then(parse('we should see the message "{text}"'))
|
||||||
def should_see_the_message(text, cli_run):
|
def should_see_the_message(text, cli_run):
|
||||||
out = cli_run["stderr"]
|
out = cli_run["stderr"]
|
||||||
|
@ -301,15 +309,34 @@ def count_elements(number, item, cli_run):
|
||||||
assert len(xml_tree.findall(".//" + item)) == number
|
assert len(xml_tree.findall(".//" + item)) == number
|
||||||
|
|
||||||
|
|
||||||
@then(parse("the editor should have been called"))
|
@then(parse("the editor {should_or_should_not} have been called"))
|
||||||
@then(parse("the editor should have been called with {num_args} arguments"))
|
@then(
|
||||||
def count_editor_args(num_args, cli_run, editor_state):
|
parse(
|
||||||
assert cli_run["mocks"]["editor"].called
|
"the editor {should_or_should_not} have been called with {num_args} arguments"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
def count_editor_args(num_args, cli_run, editor_state, should_or_should_not):
|
||||||
|
we_should = parse_should_or_should_not(should_or_should_not)
|
||||||
|
|
||||||
|
if we_should:
|
||||||
|
assert cli_run["mocks"]["editor"].called
|
||||||
|
else:
|
||||||
|
assert not cli_run["mocks"]["editor"].called
|
||||||
|
|
||||||
if isinstance(num_args, int):
|
if isinstance(num_args, int):
|
||||||
assert len(editor_state["command"]) == int(num_args)
|
assert len(editor_state["command"]) == int(num_args)
|
||||||
|
|
||||||
|
|
||||||
|
@then(parse("the stdin prompt {should_or_should_not} have been called"))
|
||||||
|
def stdin_prompt_called(cli_run, should_or_should_not):
|
||||||
|
we_should = parse_should_or_should_not(should_or_should_not)
|
||||||
|
|
||||||
|
if we_should:
|
||||||
|
assert cli_run["mocks"]["stdin"].called
|
||||||
|
else:
|
||||||
|
assert not cli_run["mocks"]["stdin"].called
|
||||||
|
|
||||||
|
|
||||||
@then(parse('the editor filename should end with "{suffix}"'))
|
@then(parse('the editor filename should end with "{suffix}"'))
|
||||||
def editor_filename_suffix(suffix, editor_state):
|
def editor_filename_suffix(suffix, editor_state):
|
||||||
editor_filename = editor_state["tmpfile"]["name"]
|
editor_filename = editor_state["tmpfile"]["name"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue