From 42fa177c0979788a14b188451a399422e8ee9036 Mon Sep 17 00:00:00 2001 From: Jiri Kyjovsky Date: Fri, 26 Aug 2022 13:18:02 +0200 Subject: [PATCH] Fix(navigate): save the path you are returning from to the stack not the path you are returning to :facepalm: --- dirstory/cli/navigate.py | 3 ++- test/unit/test_cli.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dirstory/cli/navigate.py b/dirstory/cli/navigate.py index 3a847d3..e2cd766 100644 --- a/dirstory/cli/navigate.py +++ b/dirstory/cli/navigate.py @@ -1,3 +1,4 @@ +import os from pathlib import Path from typing import Optional @@ -15,7 +16,7 @@ def back_or_forward( if curr_path is None: break - file_stack.push(path=curr_path, is_forward=not is_forward) + file_stack.push(path=Path(os.getcwd()), is_forward=not is_forward) return curr_path diff --git a/test/unit/test_cli.py b/test/unit/test_cli.py index d09ed19..2cdb617 100644 --- a/test/unit/test_cli.py +++ b/test/unit/test_cli.py @@ -33,9 +33,12 @@ class TestNavigate: pytest.param(3, False, Path("/here\n")), ], ) + @patch("os.getcwd") @patch.object(FileStack, "pop") @patch.object(FileStack, "push") - def test_back_or_forward(self, mock_push, mock_pop, size, is_forward, expected): + def test_back_or_forward( + self, mock_push, mock_pop, mock_getcwd, size, is_forward, expected + ): mocked_pop_ret_vals = [ Path("/some\n"), Path("/path\n"), @@ -43,6 +46,7 @@ def test_back_or_forward(self, mock_push, mock_pop, size, is_forward, expected): Path("/dragon\n"), ] mock_pop.side_effect = mocked_pop_ret_vals + mock_getcwd.side_effect = mocked_pop_ret_vals result = back_or_forward(FileStack(ppid=123), size, is_forward)