From 899dd5037b684f8f5f24eec7adb9e1960a372c00 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 19 Sep 2020 12:50:58 -0700 Subject: [PATCH] update version tests, add new regex match behave step --- features/core.feature | 14 ++++++++++---- features/steps/core.py | 28 +++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/features/core.feature b/features/core.feature index 94d3c2b8..941deefc 100644 --- a/features/core.feature +++ b/features/core.feature @@ -1,15 +1,21 @@ -Feature: Core functionality of jrnl outside of actually handling journals +Feature: Functionality of jrnl outside of actually handling journals + + Scenario: Displaying the version number + Given we use the config "basic.yaml" + When we run "jrnl --version" + Then we should get no error + Then the output should match "^jrnl version v\d+\.\d+\.\d+(-(alpha|beta))?$" Scenario: Displaying the version number Given we use the config "basic.yaml" When we run "jrnl -v" Then we should get no error - Then the output should contain "version" + Then the output should match "^jrnl version v\d+\.\d+\.\d+(-(alpha|beta))?$" - Scenario: --diagnostic runs without exceptions + Scenario: Running the diagnostic command When we run "jrnl --diagnostic" Then the output should contain "jrnl" And the output should contain "Python" @todo - Scenario: --list outputs to user without exceptions + Scenario: Listing available journals diff --git a/features/steps/core.py b/features/steps/core.py index 5117dd5f..52ada25c 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -203,7 +203,7 @@ def contains_editor_arg(context, arg): @then('one editor argument should match "{regex}"') def matches_editor_arg(context, regex): args = context.editor_command - matches = list(filter(lambda x: re.match(regex, x), args)) + matches = list(filter(lambda x: re.search(regex, x), args)) assert ( len(matches) == 1 ), f"\nRegex didn't match exactly 1 time:\n{regex}\n{str(args)}" @@ -406,6 +406,26 @@ def check_error_output_inline(context, text=None, text2=None): assert text in out or text2 in out, text or text2 +@then('the output should match "{regex}"') +@then('the output should match "{regex}" {num} times') +def matches_std_output(context, regex, num=1): + out = context.stdout_capture.getvalue() + matches = re.findall(regex, out) + assert ( + matches and len(matches) == num + ), f"\nRegex didn't match exactly {num} time(s):\n{regex}\n{str(out)}\n{str(matches)}" + + +@then('the error output should match "{regex}"') +@then('the error output should match "{regex}" {num} times') +def matches_err_ouput(context, regex, num=1): + out = context.stderr_capture.getvalue() + matches = re.findall(regex, out) + assert ( + matches and len(matches) == num + ), f"\nRegex didn't match exactly {num} time(s):\n{regex}\n{str(out)}\n{str(matches)}" + + @then('the output should not contain "{text}"') def check_output_not_inline(context, text): out = context.stdout_capture.getvalue() @@ -438,7 +458,7 @@ def check_not_journal_content(context, text, journal_name="default"): assert text not in journal, journal -@then('the journal should not exist') +@then("the journal should not exist") @then('journal "{journal_name}" should not exist') def journal_doesnt_exist(context, journal_name="default"): config = load_config(install.CONFIG_FILE_PATH) @@ -446,7 +466,8 @@ def journal_doesnt_exist(context, journal_name="default"): journal_path = config["journals"][journal_name] assert not os.path.exists(journal_path) -@then('the journal should exist') + +@then("the journal should exist") @then('journal "{journal_name}" should exist') def journal_exists(context, journal_name="default"): config = load_config(install.CONFIG_FILE_PATH) @@ -454,6 +475,7 @@ def journal_exists(context, journal_name="default"): journal_path = config["journals"][journal_name] assert os.path.exists(journal_path) + @then('the config should have "{key}" set to') @then('the config should have "{key}" set to "{value}"') @then('the config for journal "{journal}" should have "{key}" set to "{value}"')