zstdlib 0.10.6__tar.gz → 0.10.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zstdlib-0.10.6/zstdlib.egg-info → zstdlib-0.10.7}/PKG-INFO +1 -1
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_prompt.py +28 -8
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/__init__.py +3 -2
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/prompt.py +14 -9
- {zstdlib-0.10.6 → zstdlib-0.10.7/zstdlib.egg-info}/PKG-INFO +1 -1
- {zstdlib-0.10.6 → zstdlib-0.10.7}/LICENSE +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/README.md +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/pyproject.toml +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/setup.cfg +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/__init__.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/log/base.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_enum.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_exc_capture.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_hybridmethod.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_io.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/tests/test_singleton.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/ansi.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/exc_capture.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/frozen.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/hybridmethod.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/io.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/macos.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/not_set.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib/singleton.py +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib.egg-info/SOURCES.txt +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.6 → zstdlib-0.10.7}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -4,14 +4,13 @@ import unittest
|
|
|
4
4
|
|
|
5
5
|
from zstdlib.prompt import prompt_until, prompt_for, yn_prompt
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
mock_input = lambda *x: patch("builtins.input", side_effect=x)
|
|
9
8
|
mock_print = lambda: patch("builtins.print")
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
def want_have(mock_p: MagicMock, msg: str, n: int) -> tuple[list[str], list[str]]:
|
|
13
12
|
if any(len(i.args) != 1 or i.kwargs for i in mock_p.call_args_list):
|
|
14
|
-
|
|
13
|
+
raise ValueError("Unexpected print output")
|
|
15
14
|
return [i.args[0] for i in mock_p.call_args_list], [msg] * n
|
|
16
15
|
|
|
17
16
|
|
|
@@ -53,7 +52,7 @@ class TestPromptUntil(unittest.TestCase):
|
|
|
53
52
|
|
|
54
53
|
|
|
55
54
|
class TestPromptFor(unittest.TestCase):
|
|
56
|
-
out = "
|
|
55
|
+
out = "Continue? [continue] "
|
|
57
56
|
|
|
58
57
|
def test_basic(self) -> None:
|
|
59
58
|
with mock_print() as stdout, mock_input("test", "test", "cOntinue") as stdout:
|
|
@@ -69,8 +68,9 @@ class TestPromptFor(unittest.TestCase):
|
|
|
69
68
|
self.assertFalse(prompt_for(eof=True))
|
|
70
69
|
self.assertEqual(*want_have(stdout, self.out, 2))
|
|
71
70
|
|
|
71
|
+
|
|
72
72
|
class TestYNPrompt(unittest.TestCase):
|
|
73
|
-
out = "
|
|
73
|
+
out = "Continue? [yn] "
|
|
74
74
|
|
|
75
75
|
def test_basic(self) -> None:
|
|
76
76
|
with mock_print() as stdout, mock_input("test", "yes", "y") as stdout:
|
|
@@ -80,13 +80,33 @@ class TestYNPrompt(unittest.TestCase):
|
|
|
80
80
|
self.assertIs(yn_prompt(), False)
|
|
81
81
|
self.assertEqual(*want_have(stdout, self.out, 3))
|
|
82
82
|
|
|
83
|
-
def
|
|
84
|
-
out = "
|
|
83
|
+
def test_not_short(self) -> None:
|
|
84
|
+
out = "Continue? [yes/no] "
|
|
85
85
|
with mock_print() as stdout, mock_input("test", "y", "yes") as stdout:
|
|
86
|
-
self.assertTrue(yn_prompt(
|
|
86
|
+
self.assertTrue(yn_prompt(short=False))
|
|
87
87
|
self.assertEqual(*want_have(stdout, out, 3))
|
|
88
88
|
with mock_print() as stdout, mock_input("test", "n", "no") as stdout:
|
|
89
|
-
self.assertFalse(yn_prompt(
|
|
89
|
+
self.assertFalse(yn_prompt(short=False))
|
|
90
|
+
self.assertEqual(*want_have(stdout, out, 3))
|
|
91
|
+
|
|
92
|
+
def test_empty(self) -> None:
|
|
93
|
+
with mock_print() as stdout, mock_input("test", "") as stdout:
|
|
94
|
+
with self.assertRaises(StopIteration):
|
|
95
|
+
yn_prompt()
|
|
96
|
+
self.assertEqual(*want_have(stdout, self.out, 3))
|
|
97
|
+
with mock_print() as stdout, mock_input("test", "") as stdout:
|
|
98
|
+
self.assertFalse(yn_prompt(empty_ok=True))
|
|
99
|
+
self.assertEqual(*want_have(stdout, self.out, 2))
|
|
100
|
+
|
|
101
|
+
def test_empty_not_short(self) -> None:
|
|
102
|
+
out = "Continue? [yes/no] "
|
|
103
|
+
with mock_print() as stdout, mock_input("test", "") as stdout:
|
|
104
|
+
with self.assertRaises(StopIteration):
|
|
105
|
+
yn_prompt(short=False)
|
|
106
|
+
self.assertEqual(*want_have(stdout, out, 3))
|
|
107
|
+
with mock_print() as stdout, mock_input("test", "") as stdout:
|
|
108
|
+
with self.assertRaises(StopIteration):
|
|
109
|
+
yn_prompt(short=False, empty_ok=True)
|
|
90
110
|
self.assertEqual(*want_have(stdout, out, 3))
|
|
91
111
|
|
|
92
112
|
def test_eof(self) -> None:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
__version__ = "0.10.
|
|
1
|
+
__version__ = "0.10.7"
|
|
2
2
|
|
|
3
|
+
from .prompt import prompt_until, prompt_for, yn_prompt
|
|
3
4
|
from .exc_capture import ExcCapture, ExcDelay
|
|
4
|
-
from .prompt import prompt_for, yn_prompt
|
|
5
5
|
from .hybridmethod import hybridmethod
|
|
6
6
|
from .not_set import NotSetType, NotSet
|
|
7
7
|
from .frozen import Freezable, frozen
|
|
@@ -26,6 +26,7 @@ __all__ = (
|
|
|
26
26
|
"log",
|
|
27
27
|
"macos",
|
|
28
28
|
"prompt_for",
|
|
29
|
+
"prompt_until",
|
|
29
30
|
"signal_cm",
|
|
30
31
|
"yn_prompt",
|
|
31
32
|
)
|
|
@@ -4,6 +4,7 @@ from shlex import quote
|
|
|
4
4
|
|
|
5
5
|
__all__ = ("prompt_for", "prompt_until", "yn_prompt")
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
@overload
|
|
8
9
|
def prompt_until(
|
|
9
10
|
msg: str,
|
|
@@ -54,20 +55,22 @@ def prompt_until(
|
|
|
54
55
|
|
|
55
56
|
|
|
56
57
|
def prompt_for(
|
|
57
|
-
continue_str: str = "continue",
|
|
58
58
|
*,
|
|
59
|
+
msg: str = "Continue?",
|
|
60
|
+
key: str = "continue",
|
|
59
61
|
ignore_case: bool = True,
|
|
60
62
|
eof: bool = False,
|
|
61
63
|
ctrl_c: bool = False,
|
|
62
64
|
) -> bool:
|
|
63
65
|
"""
|
|
64
|
-
Prompt the user to contine by entering
|
|
66
|
+
Prompt the user with msg to contine by entering key, whitespace is stripped
|
|
65
67
|
If eof/ctrl_c, interpret EOFError/KeyboardInterrupt as commands to return False
|
|
68
|
+
Returns True otherwise
|
|
66
69
|
"""
|
|
67
70
|
ret = prompt_until(
|
|
68
|
-
f"
|
|
71
|
+
f"{msg} [{quote(key)}] ",
|
|
69
72
|
ignore_case=ignore_case,
|
|
70
|
-
until={
|
|
73
|
+
until={key},
|
|
71
74
|
eof=eof,
|
|
72
75
|
ctrl_c=ctrl_c,
|
|
73
76
|
)
|
|
@@ -75,19 +78,21 @@ def prompt_for(
|
|
|
75
78
|
|
|
76
79
|
|
|
77
80
|
def yn_prompt(
|
|
78
|
-
msg: str = "
|
|
81
|
+
msg: str = "Continue?",
|
|
79
82
|
*,
|
|
83
|
+
empty_ok: bool = False,
|
|
80
84
|
eof: bool = False,
|
|
81
85
|
ctrl_c: bool = False,
|
|
82
|
-
|
|
86
|
+
short: bool = True,
|
|
83
87
|
) -> bool:
|
|
84
88
|
"""
|
|
85
|
-
Prompt the user to select from [yn]
|
|
89
|
+
Prompt the user to select from [yn] if short else [yes/no], whitespace is stripped
|
|
86
90
|
If eof/ctrl_c, interpret EOFError/KeyboardInterrupt as commands to return False
|
|
91
|
+
If empty_ok, "" is considered the same as "n"; empty_ok is a nop when not short
|
|
87
92
|
"""
|
|
88
93
|
return prompt_until(
|
|
89
|
-
f"{msg} [{"
|
|
90
|
-
until=("
|
|
94
|
+
f"{msg} [{"yn" if short else "yes/no"}] ",
|
|
95
|
+
until=(("y", "n") + (("",) if empty_ok else ())) if short else ("yes", "no"),
|
|
91
96
|
eof=eof,
|
|
92
97
|
ctrl_c=ctrl_c,
|
|
93
98
|
) in ("y", "yes")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|