From 7d8823da6df9f89bebd232babb2ef157f86c35cb Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 2 Oct 2021 13:31:21 -0700 Subject: [PATCH] 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 --- .gitignore | 1 - tests/bdd/features/format.feature | 44 ++++++++++++++ tests/bdd/features/override.feature | 91 +++++++++++++++++++++++++++++ tests/bdd/test_features.py | 1 + tests/lib/then_steps.py | 35 +++++++++-- 5 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 tests/bdd/features/override.feature diff --git a/.gitignore b/.gitignore index 374deb4b..41d2df7b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ var sdist develop-eggs .installed.cfg -lib lib64 .python-version diff --git a/tests/bdd/features/format.feature b/tests/bdd/features/format.feature index b9e2e384..36a89747 100644 --- a/tests/bdd/features/format.feature +++ b/tests/bdd/features/format.feature @@ -1,5 +1,33 @@ Feature: Custom formats + Scenario Outline: Short printing via --format flag + Given we use the config "" + 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 "" + 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 Given we use the config "" And we use the password "test" if prompted @@ -296,6 +324,22 @@ Feature: Custom formats | basic_folder.yaml | | basic_dayone.yaml | + + Scenario Outline: Export fancy with small linewrap + Given we use the config "" + 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 Scenario Outline: Exporting fancy # Needs better emoji support diff --git a/tests/bdd/features/override.feature b/tests/bdd/features/override.feature new file mode 100644 index 00000000..3d9fb27f --- /dev/null +++ b/tests/bdd/features/override.feature @@ -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. diff --git a/tests/bdd/test_features.py b/tests/bdd/test_features.py index b824df39..1509e92d 100644 --- a/tests/bdd/test_features.py +++ b/tests/bdd/test_features.py @@ -9,6 +9,7 @@ scenarios("features/file_storage.feature") scenarios("features/format.feature") scenarios("features/import.feature") scenarios("features/multiple_journals.feature") +scenarios("features/override.feature") scenarios("features/password.feature") scenarios("features/search.feature") scenarios("features/star.feature") diff --git a/tests/lib/then_steps.py b/tests/lib/then_steps.py index b56c203f..2dadf82e 100644 --- a/tests/lib/then_steps.py +++ b/tests/lib/then_steps.py @@ -84,6 +84,14 @@ def output_should_contain_version(cli_run, 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}"')) def should_see_the_message(text, cli_run): out = cli_run["stderr"] @@ -301,15 +309,34 @@ def count_elements(number, item, cli_run): assert len(xml_tree.findall(".//" + item)) == number -@then(parse("the editor should have been called")) -@then(parse("the editor should have been called with {num_args} arguments")) -def count_editor_args(num_args, cli_run, editor_state): - assert cli_run["mocks"]["editor"].called +@then(parse("the editor {should_or_should_not} have been called")) +@then( + parse( + "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): 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}"')) def editor_filename_suffix(suffix, editor_state): editor_filename = editor_state["tmpfile"]["name"]