From 74e5a5510bf5a77d80bca81a5608360e39ba2154 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Thu, 15 Jul 2021 14:16:04 +0800 Subject: [PATCH 01/23] FilenamePrompt uses os.path.expanduser --- qutebrowser/mainwindow/prompt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index c8cbe572b..7597da76c 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -649,6 +649,7 @@ class FilenamePrompt(_BasePrompt): if os.altsep is not None: separators += os.altsep + path = os.path.expanduser(path) dirname = os.path.dirname(path) basename = os.path.basename(path) if not tabbed: From aa13ebde7f1ace8e579871e10677581a007fb126 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Thu, 15 Jul 2021 14:50:52 +0800 Subject: [PATCH 02/23] Fixed path changing to /home/user --- qutebrowser/mainwindow/prompt.py | 47 ++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 7597da76c..87b0f5798 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -616,6 +616,8 @@ class FilenamePrompt(_BasePrompt): self._init_texts(question) self._init_key_label() + self._expands_user = False + self._lineedit = LineEdit(self) if question.default: self._lineedit.setText(question.default) @@ -645,11 +647,17 @@ class FilenamePrompt(_BasePrompt): @pyqtSlot(str) def _set_fileview_root(self, path, *, tabbed=False): """Set the root path for the file display.""" - separators = os.sep + self._separators = os.sep if os.altsep is not None: - separators += os.altsep + self._separators += os.altsep + + # If the path is not the same as the path with expanduser set a boolean + if os.path.expanduser(path) != path: + path = os.path.expanduser(path) + self._expands_user = True + elif not self._expands_user: + self._expands_user = False - path = os.path.expanduser(path) dirname = os.path.dirname(path) basename = os.path.basename(path) if not tabbed: @@ -658,12 +666,12 @@ class FilenamePrompt(_BasePrompt): try: if not path: pass - elif path in separators and os.path.isdir(path): + elif path in self._separators and os.path.isdir(path): # Input "/" -> don't strip anything pass - elif path[-1] in separators and os.path.isdir(path): + elif path[-1] in self._separators and os.path.isdir(path): # Input like /foo/bar/ -> show /foo/bar/ contents - path = path.rstrip(separators) + path = path.rstrip(self._separators) elif os.path.isdir(dirname) and not tabbed: # Input like /foo/ba -> show /foo contents path = dirname @@ -698,6 +706,33 @@ class FilenamePrompt(_BasePrompt): # On Windows, when we have C:\foo and tab over .., we get C:\ path = path.rstrip(os.sep) + c_sep = 0 + self._index_end = 0 + for i in range(len(path)): + if path[i] in self._separators: + c_sep += 1 + + self._index_end = i + + if c_sep == 3: + break + + # If the path is not the same as the path with expanduser set a boolean + if os.path.expanduser(path) != path: + path = os.path.expanduser(path) + self._expands_user = True + elif not self._expands_user: + self._expands_user = False + + if self._expands_user: + self._expands_user = True + print(path[:self._index_end]) + path = path[:self._index_end].replace(os.path.expanduser('~'), '~') + path[self._index_end:] + else: + self._expands_user = False + + print(path) + log.prompt.debug('Inserting path {}'.format(path)) self._lineedit.setText(path) self._lineedit.setFocus() From f3e42cb9b590df2ea67344ac9fe357a533ea011e Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Thu, 15 Jul 2021 15:53:08 +0800 Subject: [PATCH 03/23] Fixed formatting and used enumerate --- qutebrowser/mainwindow/prompt.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 87b0f5798..f8fc91ad1 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -617,6 +617,7 @@ class FilenamePrompt(_BasePrompt): self._init_key_label() self._expands_user = False + self._index_end = 0 self._lineedit = LineEdit(self) if question.default: @@ -707,13 +708,12 @@ class FilenamePrompt(_BasePrompt): path = path.rstrip(os.sep) c_sep = 0 - self._index_end = 0 - for i in range(len(path)): - if path[i] in self._separators: + for i, character in enumerate(path): + if character in self._separators: c_sep += 1 - + self._index_end = i - + if c_sep == 3: break @@ -727,11 +727,10 @@ class FilenamePrompt(_BasePrompt): if self._expands_user: self._expands_user = True print(path[:self._index_end]) - path = path[:self._index_end].replace(os.path.expanduser('~'), '~') + path[self._index_end:] + path = (path[:self._index_end].replace(os.path.expanduser('~'), '~') + + path[self._index_end:]) else: self._expands_user = False - - print(path) log.prompt.debug('Inserting path {}'.format(path)) self._lineedit.setText(path) From fea644adee43b198abcae33218abe0d7fd27e1a9 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Thu, 15 Jul 2021 16:50:47 +0800 Subject: [PATCH 04/23] Fixed formatting --- qutebrowser/mainwindow/prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index f8fc91ad1..aba994f8b 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -727,7 +727,7 @@ class FilenamePrompt(_BasePrompt): if self._expands_user: self._expands_user = True print(path[:self._index_end]) - path = (path[:self._index_end].replace(os.path.expanduser('~'), '~') + + path = (path[:self._index_end].replace(os.path.expanduser('~'), '~') + path[self._index_end:]) else: self._expands_user = False From 48b1878f91f35875a8ddd7d1b3d8bb23bb8cbdee Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 16:35:00 +0800 Subject: [PATCH 05/23] Simplified unnecessary logic --- qutebrowser/mainwindow/prompt.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index aba994f8b..5bf152600 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -717,16 +717,7 @@ class FilenamePrompt(_BasePrompt): if c_sep == 3: break - # If the path is not the same as the path with expanduser set a boolean - if os.path.expanduser(path) != path: - path = os.path.expanduser(path) - self._expands_user = True - elif not self._expands_user: - self._expands_user = False - if self._expands_user: - self._expands_user = True - print(path[:self._index_end]) path = (path[:self._index_end].replace(os.path.expanduser('~'), '~') + path[self._index_end:]) else: From 8bfdf71f02b5591880e0d5e45c51d1fdacaaef06 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 16:36:37 +0800 Subject: [PATCH 06/23] Removed self._index_end --- qutebrowser/mainwindow/prompt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 5bf152600..59cbaa4c3 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -617,7 +617,6 @@ class FilenamePrompt(_BasePrompt): self._init_key_label() self._expands_user = False - self._index_end = 0 self._lineedit = LineEdit(self) if question.default: @@ -708,18 +707,19 @@ class FilenamePrompt(_BasePrompt): path = path.rstrip(os.sep) c_sep = 0 + index_end_home = 0 for i, character in enumerate(path): if character in self._separators: c_sep += 1 - self._index_end = i + index_end_home = i if c_sep == 3: break if self._expands_user: - path = (path[:self._index_end].replace(os.path.expanduser('~'), '~') + - path[self._index_end:]) + path = (path[:index_end_home].replace(os.path.expanduser('~'), '~') + + path[index_end_home:]) else: self._expands_user = False From 8ba7864ba83e1ba1bedfb975abbd4f7456922eef Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 17:19:18 +0800 Subject: [PATCH 07/23] Made code more concise, will add tests --- qutebrowser/mainwindow/prompt.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 59cbaa4c3..0a03e5c08 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -655,8 +655,6 @@ class FilenamePrompt(_BasePrompt): if os.path.expanduser(path) != path: path = os.path.expanduser(path) self._expands_user = True - elif not self._expands_user: - self._expands_user = False dirname = os.path.dirname(path) basename = os.path.basename(path) @@ -706,20 +704,8 @@ class FilenamePrompt(_BasePrompt): # On Windows, when we have C:\foo and tab over .., we get C:\ path = path.rstrip(os.sep) - c_sep = 0 - index_end_home = 0 - for i, character in enumerate(path): - if character in self._separators: - c_sep += 1 - - index_end_home = i - - if c_sep == 3: - break - if self._expands_user: - path = (path[:index_end_home].replace(os.path.expanduser('~'), '~') + - path[index_end_home:]) + path = path.replace(os.path.expanduser('~'), '~', 1) else: self._expands_user = False From f23492de8a659af2248d2c473d1a0fe7a7d14290 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 19:57:31 +0800 Subject: [PATCH 08/23] Made seperators local variable removed redundant if --- qutebrowser/mainwindow/prompt.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 0a03e5c08..084ddb97a 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -706,8 +706,6 @@ class FilenamePrompt(_BasePrompt): if self._expands_user: path = path.replace(os.path.expanduser('~'), '~', 1) - else: - self._expands_user = False log.prompt.debug('Inserting path {}'.format(path)) self._lineedit.setText(path) From c113a5c1aac833aee94751eaffcc8c005fd0150e Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 19:57:43 +0800 Subject: [PATCH 09/23] Made seperators local variable removed redundant if (forgot to save file) --- qutebrowser/mainwindow/prompt.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 084ddb97a..59e4a2cda 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -647,9 +647,9 @@ class FilenamePrompt(_BasePrompt): @pyqtSlot(str) def _set_fileview_root(self, path, *, tabbed=False): """Set the root path for the file display.""" - self._separators = os.sep + separators = os.sep if os.altsep is not None: - self._separators += os.altsep + separators += os.altsep # If the path is not the same as the path with expanduser set a boolean if os.path.expanduser(path) != path: @@ -664,12 +664,12 @@ class FilenamePrompt(_BasePrompt): try: if not path: pass - elif path in self._separators and os.path.isdir(path): + elif path in separators and os.path.isdir(path): # Input "/" -> don't strip anything pass - elif path[-1] in self._separators and os.path.isdir(path): + elif path[-1] in separators and os.path.isdir(path): # Input like /foo/bar/ -> show /foo/bar/ contents - path = path.rstrip(self._separators) + path = path.rstrip(separators) elif os.path.isdir(dirname) and not tabbed: # Input like /foo/ba -> show /foo contents path = dirname From ed4fa433dadbe5fac91be180bc3ee3fcd64322fc Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 20:27:53 +0800 Subject: [PATCH 10/23] Created test --- tests/unit/mainwindow/test_prompt.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index 5b774bdaa..b5caa387a 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -18,6 +18,7 @@ # along with qutebrowser. If not, see . import os +from pathlib import Path import pytest from PyQt5.QtCore import Qt @@ -130,3 +131,14 @@ class TestFileCompletion: """With / as path, show root contents.""" prompt = get_prompt('/') assert prompt._file_model.rootPath() == '/' + + def test_expand_user(self, qtbot, get_prompt): + prompt = get_prompt('/') + prompt._lineedit.setText('') + qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) + # The path currently seen by the file_model should be the same as os.path.expanduser('~') + assert str(Path(prompt._file_model.rootPath()) / prompt._to_complete) == os.path.expanduser('~') + # The first character on the lineedit should remain ~ + prompt.item_focus('next') + prompt.item_focus('next') + assert prompt._lineedit.text()[0] == '~' From 1dc7d58b5a8113c999e701513387b573020ca93f Mon Sep 17 00:00:00 2001 From: jso8910 <60021163+jso8910@users.noreply.github.com> Date: Mon, 19 Jul 2021 20:47:45 +0800 Subject: [PATCH 11/23] Update tests/unit/mainwindow/test_prompt.py Co-authored-by: Florian Bruhin --- tests/unit/mainwindow/test_prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index b5caa387a..afe44373e 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -137,7 +137,7 @@ class TestFileCompletion: prompt._lineedit.setText('') qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) # The path currently seen by the file_model should be the same as os.path.expanduser('~') - assert str(Path(prompt._file_model.rootPath()) / prompt._to_complete) == os.path.expanduser('~') + assert Path(prompt._file_model.rootPath()) / prompt._to_complete == pathlib.Path.home() # The first character on the lineedit should remain ~ prompt.item_focus('next') prompt.item_focus('next') From bac6f58beb7e4f2bb1a2cf1722f71fe0d0f00f37 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 20:49:52 +0800 Subject: [PATCH 12/23] Slightly changed suggestion from test --- tests/unit/mainwindow/test_prompt.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index afe44373e..01de196b0 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -18,7 +18,7 @@ # along with qutebrowser. If not, see . import os -from pathlib import Path +import pathlib import pytest from PyQt5.QtCore import Qt @@ -134,10 +134,9 @@ class TestFileCompletion: def test_expand_user(self, qtbot, get_prompt): prompt = get_prompt('/') - prompt._lineedit.setText('') - qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) + prompt._lineedit.setText('~') # The path currently seen by the file_model should be the same as os.path.expanduser('~') - assert Path(prompt._file_model.rootPath()) / prompt._to_complete == pathlib.Path.home() + assert pathlib.Path(prompt._file_model.rootPath()) / prompt._to_complete == pathlib.Path.home() # The first character on the lineedit should remain ~ prompt.item_focus('next') prompt.item_focus('next') From 82236ddcc298c7b816a81f4e3e85fc9e0a54b646 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 20:58:36 +0800 Subject: [PATCH 13/23] Changed home directory in test_expand_user --- tests/unit/mainwindow/test_prompt.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index 01de196b0..10bbec385 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -131,10 +131,20 @@ class TestFileCompletion: """With / as path, show root contents.""" prompt = get_prompt('/') assert prompt._file_model.rootPath() == '/' - - def test_expand_user(self, qtbot, get_prompt): + + def test_expand_user(self, qtbot, get_prompt, monkeypatch, tmp_path): + testdir = tmp_path / 'test' + for directory in ['bar', 'bat', 'foo']: + (testdir / directory).mkdir(parents=True) + + homedir = str(testdir) + monkeypatch.setenv('HOME', homedir) # POSIX + monkeypatch.setenv('USERPROFILE', homedir) # Windows + print(pathlib.Path.home()) + assert str(pathlib.Path.home()) == homedir prompt = get_prompt('/') - prompt._lineedit.setText('~') + prompt._lineedit.setText('') + qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) # The path currently seen by the file_model should be the same as os.path.expanduser('~') assert pathlib.Path(prompt._file_model.rootPath()) / prompt._to_complete == pathlib.Path.home() # The first character on the lineedit should remain ~ From aed9a19b45558b08726859b173db64ccd56775a6 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 21:07:17 +0800 Subject: [PATCH 14/23] Suggestions --- tests/unit/mainwindow/test_prompt.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index 10bbec385..fafc32d58 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -133,19 +133,18 @@ class TestFileCompletion: assert prompt._file_model.rootPath() == '/' def test_expand_user(self, qtbot, get_prompt, monkeypatch, tmp_path): - testdir = tmp_path / 'test' for directory in ['bar', 'bat', 'foo']: - (testdir / directory).mkdir(parents=True) - - homedir = str(testdir) + (tmp_path / directory).mkdir() + + homedir = str(tmp_path) monkeypatch.setenv('HOME', homedir) # POSIX monkeypatch.setenv('USERPROFILE', homedir) # Windows - print(pathlib.Path.home()) assert str(pathlib.Path.home()) == homedir + prompt = get_prompt('/') prompt._lineedit.setText('') + # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) - # The path currently seen by the file_model should be the same as os.path.expanduser('~') assert pathlib.Path(prompt._file_model.rootPath()) / prompt._to_complete == pathlib.Path.home() # The first character on the lineedit should remain ~ prompt.item_focus('next') From a64f0e7172aa1b618dac3dd25a50dd1b6b28d37c Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 21:40:55 +0800 Subject: [PATCH 15/23] Added more tests. Some bits are a bit crude. --- tests/unit/mainwindow/test_prompt.py | 41 ++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index fafc32d58..f3cd743e7 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -131,22 +131,51 @@ class TestFileCompletion: """With / as path, show root contents.""" prompt = get_prompt('/') assert prompt._file_model.rootPath() == '/' - - def test_expand_user(self, qtbot, get_prompt, monkeypatch, tmp_path): - for directory in ['bar', 'bat', 'foo']: - (tmp_path / directory).mkdir() - + + @pytest.fixture + def home_path(self, monkeypatch, tmp_path): homedir = str(tmp_path) monkeypatch.setenv('HOME', homedir) # POSIX monkeypatch.setenv('USERPROFILE', homedir) # Windows assert str(pathlib.Path.home()) == homedir + return tmp_path + + def test_expand_user(self, qtbot, get_prompt, home_path): + for directory in ['bar', 'bat', 'foo']: + (home_path / directory).mkdir() prompt = get_prompt('/') prompt._lineedit.setText('') # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) - assert pathlib.Path(prompt._file_model.rootPath()) / prompt._to_complete == pathlib.Path.home() + assert (pathlib.Path(prompt._file_model.rootPath()) / + prompt._to_complete) == pathlib.Path.home() # The first character on the lineedit should remain ~ prompt.item_focus('next') prompt.item_focus('next') assert prompt._lineedit.text()[0] == '~' + + def test_expand_once(self, qtbot, get_prompt, home_path): + pathlib.Path(str(home_path) + str(home_path)).mkdir(parents=True) + + prompt = get_prompt('/') + prompt._lineedit.setText('~' + str(home_path)) + # _set_fileview_root isn't run unless there is an actual keypress + qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) + # The second instance of home_path shouldn't be replaced with ~ + assert prompt._lineedit.text()[:-1] == '~' + str(home_path) + + def test_dont_contract(self, qtbot, get_prompt, home_path): + for directory in ['bar', 'bat', 'foo']: + (home_path / directory).mkdir() + + prompt = get_prompt('/') + prompt._lineedit.setText(str(home_path)) + # _set_fileview_root isn't run unless there is an actual keypress + qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) + + prompt.item_focus('next') + prompt.item_focus('next') + # If $HOME is contracted to `~` this test will fail as that is unexpected + assert (prompt._lineedit.text() != + prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) \ No newline at end of file From a7f4e3d2badb02da1ea26e556714c555aff87bbf Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 21:42:22 +0800 Subject: [PATCH 16/23] Changed variable name --- qutebrowser/mainwindow/prompt.py | 6 +++--- tests/unit/mainwindow/test_prompt.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 59e4a2cda..607682b37 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -616,7 +616,7 @@ class FilenamePrompt(_BasePrompt): self._init_texts(question) self._init_key_label() - self._expands_user = False + self._user_expanded = False self._lineedit = LineEdit(self) if question.default: @@ -654,7 +654,7 @@ class FilenamePrompt(_BasePrompt): # If the path is not the same as the path with expanduser set a boolean if os.path.expanduser(path) != path: path = os.path.expanduser(path) - self._expands_user = True + self._user_expanded = True dirname = os.path.dirname(path) basename = os.path.basename(path) @@ -704,7 +704,7 @@ class FilenamePrompt(_BasePrompt): # On Windows, when we have C:\foo and tab over .., we get C:\ path = path.rstrip(os.sep) - if self._expands_user: + if self._user_expanded: path = path.replace(os.path.expanduser('~'), '~', 1) log.prompt.debug('Inserting path {}'.format(path)) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index f3cd743e7..86bb02271 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -178,4 +178,4 @@ class TestFileCompletion: prompt.item_focus('next') # If $HOME is contracted to `~` this test will fail as that is unexpected assert (prompt._lineedit.text() != - prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) \ No newline at end of file + prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) From bd763a20825cb9e34576a2b0418b28370b0a9cdb Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 21:46:22 +0800 Subject: [PATCH 17/23] Fixed styles in test_prompt --- tests/unit/mainwindow/test_prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index 86bb02271..ea85ccb48 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -131,7 +131,7 @@ class TestFileCompletion: """With / as path, show root contents.""" prompt = get_prompt('/') assert prompt._file_model.rootPath() == '/' - + @pytest.fixture def home_path(self, monkeypatch, tmp_path): homedir = str(tmp_path) From dcc179289b03f0b4e973e8e1d28fd8ff3b732b6f Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Mon, 19 Jul 2021 22:48:46 +0800 Subject: [PATCH 18/23] Should've fixed tests --- tests/unit/mainwindow/test_prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index ea85ccb48..e015648a2 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -156,7 +156,7 @@ class TestFileCompletion: assert prompt._lineedit.text()[0] == '~' def test_expand_once(self, qtbot, get_prompt, home_path): - pathlib.Path(str(home_path) + str(home_path)).mkdir(parents=True) + home_path.joinpath(*home_path.parts[1:]).mkdir(parents=True) prompt = get_prompt('/') prompt._lineedit.setText('~' + str(home_path)) From da8583fa9f4ee0c40ae188719adf251925bba20b Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Tue, 20 Jul 2021 00:11:48 +0800 Subject: [PATCH 19/23] Temporary fix (?) for tests --- tests/unit/mainwindow/test_prompt.py | 35 +++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index e015648a2..5c855872f 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -147,13 +147,14 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText('') # _set_fileview_root isn't run unless there is an actual keypress - qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) - assert (pathlib.Path(prompt._file_model.rootPath()) / - prompt._to_complete) == pathlib.Path.home() - # The first character on the lineedit should remain ~ - prompt.item_focus('next') - prompt.item_focus('next') - assert prompt._lineedit.text()[0] == '~' + with qtbot.waitSignal(prompt._file_model.directoryLoaded) as blocker: + qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) + assert (pathlib.Path(prompt._file_model.rootPath()) / + prompt._to_complete) == pathlib.Path.home() + # The first character on the lineedit should remain ~ + prompt.item_focus('next') + prompt.item_focus('next') + assert prompt._lineedit.text()[0] == '~' def test_expand_once(self, qtbot, get_prompt, home_path): home_path.joinpath(*home_path.parts[1:]).mkdir(parents=True) @@ -161,9 +162,10 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText('~' + str(home_path)) # _set_fileview_root isn't run unless there is an actual keypress - qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) - # The second instance of home_path shouldn't be replaced with ~ - assert prompt._lineedit.text()[:-1] == '~' + str(home_path) + with qtbot.waitSignal(prompt._file_model.directoryLoaded) as blocker: + qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) + # The second instance of home_path shouldn't be replaced with ~ + assert prompt._lineedit.text()[:-1] == '~' + str(home_path) def test_dont_contract(self, qtbot, get_prompt, home_path): for directory in ['bar', 'bat', 'foo']: @@ -172,10 +174,11 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText(str(home_path)) # _set_fileview_root isn't run unless there is an actual keypress - qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) + with qtbot.waitSignal(prompt._file_model.directoryLoaded) as blocker: + qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) - prompt.item_focus('next') - prompt.item_focus('next') - # If $HOME is contracted to `~` this test will fail as that is unexpected - assert (prompt._lineedit.text() != - prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) + prompt.item_focus('next') + prompt.item_focus('next') + # If $HOME is contracted to `~` this test will fail as that is unexpected + assert (prompt._lineedit.text() != + prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) From f6b2b378d1818a6b12e64e8f7e87092a3f08172f Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Tue, 20 Jul 2021 00:13:00 +0800 Subject: [PATCH 20/23] Forgot to move comments into with --- tests/unit/mainwindow/test_prompt.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index 5c855872f..1ce714dcb 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -146,8 +146,8 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText('') - # _set_fileview_root isn't run unless there is an actual keypress - with qtbot.waitSignal(prompt._file_model.directoryLoaded) as blocker: + with qtbot.waitSignal(prompt._file_model.directoryLoaded): + # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) assert (pathlib.Path(prompt._file_model.rootPath()) / prompt._to_complete) == pathlib.Path.home() @@ -161,8 +161,8 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText('~' + str(home_path)) - # _set_fileview_root isn't run unless there is an actual keypress - with qtbot.waitSignal(prompt._file_model.directoryLoaded) as blocker: + with qtbot.waitSignal(prompt._file_model.directoryLoaded): + # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) # The second instance of home_path shouldn't be replaced with ~ assert prompt._lineedit.text()[:-1] == '~' + str(home_path) @@ -173,8 +173,8 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText(str(home_path)) - # _set_fileview_root isn't run unless there is an actual keypress - with qtbot.waitSignal(prompt._file_model.directoryLoaded) as blocker: + with qtbot.waitSignal(prompt._file_model.directoryLoaded): + # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) prompt.item_focus('next') From 59a33f6fd75e4d6011b2819e99c5f8b0bfe08296 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Tue, 20 Jul 2021 00:21:29 +0800 Subject: [PATCH 21/23] Edited misc script to include waitSignal in qtbot commands --- scripts/dev/misc_checks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/dev/misc_checks.py b/scripts/dev/misc_checks.py index bae51e372..354b1ee96 100644 --- a/scripts/dev/misc_checks.py +++ b/scripts/dev/misc_checks.py @@ -189,6 +189,7 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]: 'mouseMove', 'mouseDClick', 'keySequence', + 'waitSignal', } qtbot_excludes = '|'.join(qtbot_methods) From 2219b0f0ac8be43f8d19169e9559696a3666e569 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Tue, 20 Jul 2021 00:36:15 +0800 Subject: [PATCH 22/23] Fixed camel casing and changed indentation --- scripts/dev/misc_checks.py | 1 - tests/unit/mainwindow/test_prompt.py | 34 +++++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/scripts/dev/misc_checks.py b/scripts/dev/misc_checks.py index 354b1ee96..bae51e372 100644 --- a/scripts/dev/misc_checks.py +++ b/scripts/dev/misc_checks.py @@ -189,7 +189,6 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]: 'mouseMove', 'mouseDClick', 'keySequence', - 'waitSignal', } qtbot_excludes = '|'.join(qtbot_methods) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index 1ce714dcb..aac96fc31 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -146,26 +146,28 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText('') - with qtbot.waitSignal(prompt._file_model.directoryLoaded): + with qtbot.wait_signal(prompt._file_model.directoryLoaded): # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) - assert (pathlib.Path(prompt._file_model.rootPath()) / - prompt._to_complete) == pathlib.Path.home() - # The first character on the lineedit should remain ~ - prompt.item_focus('next') - prompt.item_focus('next') - assert prompt._lineedit.text()[0] == '~' + + assert (pathlib.Path(prompt._file_model.rootPath()) / + prompt._to_complete) == pathlib.Path.home() + # The first character on the lineedit should remain ~ + prompt.item_focus('next') + prompt.item_focus('next') + assert prompt._lineedit.text()[0] == '~' def test_expand_once(self, qtbot, get_prompt, home_path): home_path.joinpath(*home_path.parts[1:]).mkdir(parents=True) prompt = get_prompt('/') prompt._lineedit.setText('~' + str(home_path)) - with qtbot.waitSignal(prompt._file_model.directoryLoaded): + with qtbot.wait_signal(prompt._file_model.directoryLoaded): # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) - # The second instance of home_path shouldn't be replaced with ~ - assert prompt._lineedit.text()[:-1] == '~' + str(home_path) + + # The second instance of home_path shouldn't be replaced with ~ + assert prompt._lineedit.text()[:-1] == '~' + str(home_path) def test_dont_contract(self, qtbot, get_prompt, home_path): for directory in ['bar', 'bat', 'foo']: @@ -173,12 +175,12 @@ class TestFileCompletion: prompt = get_prompt('/') prompt._lineedit.setText(str(home_path)) - with qtbot.waitSignal(prompt._file_model.directoryLoaded): + with qtbot.wait_signal(prompt._file_model.directoryLoaded): # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) - prompt.item_focus('next') - prompt.item_focus('next') - # If $HOME is contracted to `~` this test will fail as that is unexpected - assert (prompt._lineedit.text() != - prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) + prompt.item_focus('next') + prompt.item_focus('next') + # If $HOME is contracted to `~` this test will fail as that is unexpected + assert (prompt._lineedit.text() != + prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) From ce2c48b972a96390d9de6fb6cfae6c7ad93f04d1 Mon Sep 17 00:00:00 2001 From: Jason Rosenzweig Date: Tue, 20 Jul 2021 00:51:28 +0800 Subject: [PATCH 23/23] Seeing if indenting more fixes --- tests/unit/mainwindow/test_prompt.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/unit/mainwindow/test_prompt.py b/tests/unit/mainwindow/test_prompt.py index aac96fc31..6277b9424 100644 --- a/tests/unit/mainwindow/test_prompt.py +++ b/tests/unit/mainwindow/test_prompt.py @@ -150,12 +150,12 @@ class TestFileCompletion: # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_AsciiTilde) - assert (pathlib.Path(prompt._file_model.rootPath()) / - prompt._to_complete) == pathlib.Path.home() - # The first character on the lineedit should remain ~ - prompt.item_focus('next') - prompt.item_focus('next') - assert prompt._lineedit.text()[0] == '~' + assert (pathlib.Path(prompt._file_model.rootPath()) / + prompt._to_complete) == pathlib.Path.home() + # The first character on the lineedit should remain ~ + prompt.item_focus('next') + prompt.item_focus('next') + assert prompt._lineedit.text()[0] == '~' def test_expand_once(self, qtbot, get_prompt, home_path): home_path.joinpath(*home_path.parts[1:]).mkdir(parents=True) @@ -166,8 +166,8 @@ class TestFileCompletion: # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) - # The second instance of home_path shouldn't be replaced with ~ - assert prompt._lineedit.text()[:-1] == '~' + str(home_path) + # The second instance of home_path shouldn't be replaced with ~ + assert prompt._lineedit.text()[:-1] == '~' + str(home_path) def test_dont_contract(self, qtbot, get_prompt, home_path): for directory in ['bar', 'bat', 'foo']: @@ -179,8 +179,8 @@ class TestFileCompletion: # _set_fileview_root isn't run unless there is an actual keypress qtbot.keyPress(prompt._lineedit, Qt.Key_Slash) - prompt.item_focus('next') - prompt.item_focus('next') - # If $HOME is contracted to `~` this test will fail as that is unexpected - assert (prompt._lineedit.text() != - prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1)) + prompt.item_focus('next') + prompt.item_focus('next') + # If $HOME is contracted to `~` this test will fail as that is unexpected + assert (prompt._lineedit.text() != + prompt._lineedit.text().replace(os.path.expanduser('~'), '~', 1))