Skip to content

Commit

Permalink
Merge branch '9320' into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Jul 6, 2021
2 parents 2b62b4e + c2e4820 commit 00d28e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sphinx/cmd/quickstart.py
Expand Up @@ -95,6 +95,12 @@ def is_path(x: str) -> str:
return x


def is_path_or_empty(x: str) -> str:
if x == '':
return x
return is_path(x)


def allow_empty(x: str) -> str:
return x

Expand Down Expand Up @@ -223,7 +229,7 @@ def ask_user(d: Dict) -> None:
print(__('sphinx-quickstart will not overwrite existing Sphinx projects.'))
print()
d['path'] = do_prompt(__('Please enter a new root path (or just Enter to exit)'),
'', is_path)
'', is_path_or_empty)
if not d['path']:
sys.exit(1)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_quickstart.py
Expand Up @@ -10,6 +10,7 @@

import time
from io import StringIO
from os import path

import pytest

Expand Down Expand Up @@ -250,3 +251,18 @@ def test_extensions(tempdir):
ns = {}
exec(conffile.read_text(), ns)
assert ns['extensions'] == ['foo', 'bar', 'baz']


def test_exits_when_existing_confpy(monkeypatch):
# The code detects existing conf.py with path.isfile()
# so we mock it as True with pytest's monkeypatch
def mock_isfile(path):
return True
monkeypatch.setattr(path, 'isfile', mock_isfile)

qs.term_input = mock_input({
'Please enter a new root path (or just Enter to exit)': ''
})
d = {}
with pytest.raises(SystemExit):
qs.ask_user(d)

0 comments on commit 00d28e1

Please sign in to comment.