From 3956b7569848c52203405c378b70d3178af7357c Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 25 Feb 2023 14:57:51 -0800 Subject: [PATCH] fix get_fixture function --- jrnl/journals/Journal.py | 4 +++- tests/bdd/features/change_time.feature | 9 ++++++--- tests/lib/fixtures.py | 6 ++++-- tests/lib/helpers.py | 8 ++++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/jrnl/journals/Journal.py b/jrnl/journals/Journal.py index 994e0098..9d74669b 100644 --- a/jrnl/journals/Journal.py +++ b/jrnl/journals/Journal.py @@ -262,7 +262,9 @@ class Journal: start_date = time.parse(start_date) # If strict mode is on, all tags have to be present in entry - has_tags = self.search_tags.issubset if strict else self.search_tags.intersection + has_tags = ( + self.search_tags.issubset if strict else self.search_tags.intersection + ) def excluded(tags): return 0 < len([tag for tag in tags if tag in excluded_tags]) diff --git a/tests/bdd/features/change_time.feature b/tests/bdd/features/change_time.feature index 603dfd44..2b1ca397 100644 --- a/tests/bdd/features/change_time.feature +++ b/tests/bdd/features/change_time.feature @@ -25,13 +25,16 @@ Feature: Change entry times in journal Scenario Outline: Change flag changes prompted entries Given we use the config "" And we use the password "test" if prompted - When we run "jrnl -1" - Then the output should contain "2020-09-24 09:14 The third entry finally" + When we run "jrnl --short" + Then the output should be + 2020-08-29 11:11 Entry the first. + 2020-08-31 14:32 A second entry in what I hope to be a long series. + 2020-09-24 09:14 The third entry finally after weeks without writing. When we run "jrnl --change-time '2022-04-23 10:30'" and enter Y N Y - When we run "jrnl -99 --short" + When we run "jrnl --short" Then the output should be 2020-08-31 14:32 A second entry in what I hope to be a long series. 2022-04-23 10:30 Entry the first. diff --git a/tests/lib/fixtures.py b/tests/lib/fixtures.py index 74630a02..22c11d54 100644 --- a/tests/lib/fixtures.py +++ b/tests/lib/fixtures.py @@ -231,13 +231,15 @@ def mock_user_input(request, password_input, stdin_input): def _mock_user_input(): # user_input needs to be here because we don't know it until cli_run starts user_input = get_fixture(request, "all_input", None) + if user_input is None: user_input = Exception("Unexpected call for user input") else: user_input = iter(user_input.splitlines()) def mock_console_input(**kwargs): - if kwargs["password"] and not isinstance(password_input, Exception): + pw = kwargs.get("password", False) + if pw and not isinstance(password_input, Exception): return password_input if isinstance(user_input, Iterable): @@ -246,7 +248,7 @@ def mock_user_input(request, password_input, stdin_input): return "" if input_line == r"\n" else input_line # exceptions - return user_input if not kwargs["password"] else password_input + return user_input if not pw else password_input mock_console = Mock(wraps=Console(stderr=True)) mock_console.input = Mock(side_effect=mock_console_input) diff --git a/tests/lib/helpers.py b/tests/lib/helpers.py index f691782d..c91633d1 100644 --- a/tests/lib/helpers.py +++ b/tests/lib/helpers.py @@ -77,7 +77,7 @@ def spy_wrapper(wrapped_function): def get_fixture(request, name, default=None): - result = default - if name in request.node.fixturenames: - result = request.getfixturevalue(name) - return result + try: + return request.getfixturevalue(name) + except LookupError: + return default