fix get_fixture function

This commit is contained in:
Jonathan Wren 2023-02-25 14:57:51 -08:00
parent 9bb92707d0
commit 3956b75698
No known key found for this signature in database
4 changed files with 17 additions and 10 deletions

View file

@ -262,7 +262,9 @@ class Journal:
start_date = time.parse(start_date) start_date = time.parse(start_date)
# If strict mode is on, all tags have to be present in entry # 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): def excluded(tags):
return 0 < len([tag for tag in tags if tag in excluded_tags]) return 0 < len([tag for tag in tags if tag in excluded_tags])

View file

@ -25,13 +25,16 @@ Feature: Change entry times in journal
Scenario Outline: Change flag changes prompted entries Scenario Outline: Change flag changes prompted entries
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 -1" When we run "jrnl --short"
Then the output should contain "2020-09-24 09:14 The third entry finally" 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 When we run "jrnl --change-time '2022-04-23 10:30'" and enter
Y Y
N N
Y Y
When we run "jrnl -99 --short" When we run "jrnl --short"
Then the output should be Then the output should be
2020-08-31 14:32 A second entry in what I hope to be a long series. 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. 2022-04-23 10:30 Entry the first.

View file

@ -231,13 +231,15 @@ def mock_user_input(request, password_input, stdin_input):
def _mock_user_input(): def _mock_user_input():
# user_input needs to be here because we don't know it until cli_run starts # user_input needs to be here because we don't know it until cli_run starts
user_input = get_fixture(request, "all_input", None) user_input = get_fixture(request, "all_input", 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 = iter(user_input.splitlines()) user_input = iter(user_input.splitlines())
def mock_console_input(**kwargs): 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 return password_input
if isinstance(user_input, Iterable): 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 return "" if input_line == r"\n" else input_line
# exceptions # 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 = Mock(wraps=Console(stderr=True))
mock_console.input = Mock(side_effect=mock_console_input) mock_console.input = Mock(side_effect=mock_console_input)

View file

@ -77,7 +77,7 @@ def spy_wrapper(wrapped_function):
def get_fixture(request, name, default=None): def get_fixture(request, name, default=None):
result = default try:
if name in request.node.fixturenames: return request.getfixturevalue(name)
result = request.getfixturevalue(name) except LookupError:
return result return default