wizlib 3.1.3__tar.gz → 3.1.5__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.

Potentially problematic release.


This version of wizlib might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wizlib
3
- Version: 3.1.3
3
+ Version: 3.1.5
4
4
  Summary: Framework for flexible and powerful command-line applications
5
5
  License: MIT
6
6
  Author: Steampunk Wizard
@@ -43,4 +43,3 @@ WizLib wraps the built-in ArgumentParser with a set of functions, classes, and c
43
43
  Logo by [Freepik](https://www.freepik.com/?_gl=1*1y9rvc9*test_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*test_ga_523JXC6VL7*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..*fp_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*fp_ga_1ZY8468CQB*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..)
44
44
 
45
45
 
46
-
@@ -24,4 +24,3 @@ WizLib wraps the built-in ArgumentParser with a set of functions, classes, and c
24
24
 
25
25
  Logo by [Freepik](https://www.freepik.com/?_gl=1*1y9rvc9*test_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*test_ga_523JXC6VL7*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..*fp_ga*Mjc1MTIzODYxLjE2ODA3OTczNTg.*fp_ga_1ZY8468CQB*MTY4MDc5NzM1OC4xLjEuMTY4MDc5NzQxNS4zLjAuMA..)
26
26
 
27
-
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "wizlib"
3
- version = "3.1.3"
3
+ version = "3.1.5"
4
4
  description = "Framework for flexible and powerful command-line applications"
5
5
  authors = ["Steampunk Wizard <wizlib@steampunkwizard.ca>"]
6
6
  license = "MIT"
@@ -0,0 +1,21 @@
1
+ # Primitive i/o functions referenced elsewhere, useful for test patching (a
2
+ # sort of dependency injection
3
+
4
+ import sys
5
+
6
+ import readchar
7
+
8
+
9
+ ISATTY = sys.stdin.isatty()
10
+
11
+
12
+ def isatty():
13
+ return ISATTY
14
+
15
+
16
+ def stream():
17
+ return '' if ISATTY else sys.stdin.read()
18
+
19
+
20
+ def ttyin():
21
+ return readchar.readkey()
@@ -1,13 +1,17 @@
1
+ # In a non-interactive, non-testing mode, route input from stdin to the output.
2
+ # When testing, read from the object provided (probably a StreamIO)
3
+
1
4
  from pathlib import Path
2
5
  import sys
3
6
 
4
7
  from wizlib.handler import Handler
5
8
  from wizlib.parser import WizParser
6
-
7
- INTERACTIVE = sys.stdin.isatty()
9
+ import wizlib.io
8
10
 
9
11
 
10
12
  class StreamHandler(Handler):
13
+ """Handle non-interactive input, such as via a pipe in a shell. Only runs
14
+ when not in a tty."""
11
15
 
12
16
  name = 'stream'
13
17
  text: str = ''
@@ -15,8 +19,8 @@ class StreamHandler(Handler):
15
19
  def __init__(self, file=None, stdin=True):
16
20
  if file:
17
21
  self.text = Path(file).read_text()
18
- elif stdin and (not INTERACTIVE):
19
- self.text = sys.stdin.read()
22
+ elif not wizlib.io.isatty():
23
+ self.text = wizlib.io.stream()
20
24
 
21
25
  def __str__(self):
22
26
  return self.text
@@ -0,0 +1,36 @@
1
+ # Patch inputs and outputs for easy testing
2
+
3
+ from io import StringIO
4
+ from unittest import TestCase
5
+ from unittest.mock import Mock, patch
6
+
7
+
8
+ class WizLibTestCase(TestCase):
9
+ """Wrap your test cases in this class to use the patches correctly"""
10
+
11
+ def setUp(self):
12
+ self.notty = patch('wizlib.io.isatty', Mock(return_value=False))
13
+ self.notty.start()
14
+
15
+ def tearDown(self):
16
+ self.notty.stop()
17
+
18
+ @staticmethod
19
+ def patch_stream(val: str):
20
+ """Patch stream input such as pipes for stream handler"""
21
+ mock = Mock(return_value=val)
22
+ return patch('wizlib.io.stream', mock)
23
+
24
+ @staticmethod
25
+ def patch_ttyin(val: str):
26
+ """Patch input typed by a user in shell ui"""
27
+ mock = Mock(side_effect=val)
28
+ return patch('wizlib.io.ttyin', mock)
29
+
30
+ @staticmethod
31
+ def patcherr(): # pragma: nocover
32
+ return patch('sys.stderr', StringIO())
33
+
34
+ @staticmethod
35
+ def patchout(): # pragma: nocover
36
+ return patch('sys.stdout', StringIO())
@@ -2,10 +2,8 @@ from enum import Enum
2
2
  import sys
3
3
  import re
4
4
 
5
- from readchar import readkey
6
-
7
5
  from wizlib.ui.shell import S
8
-
6
+ import wizlib.io
9
7
 
10
8
  if (sys.platform == "win32"):
11
9
  import ctypes
@@ -89,7 +87,7 @@ class ShellLineEditor: # pragma: nocover
89
87
  write(S.RESET)
90
88
  while True:
91
89
  self.write_fill()
92
- key = readkey()
90
+ key = wizlib.io.ttyin()
93
91
  self.clear_fill()
94
92
  if key == S.RETURN:
95
93
  break
@@ -1,13 +1,10 @@
1
1
  from enum import StrEnum
2
2
  import sys
3
3
 
4
- from readchar import readkey
5
-
6
4
  from wizlib.ui import UI, Chooser, Emphasis
7
5
  from wizlib.ui.shell.line_editor import ShellLineEditor
8
6
  from wizlib.ui.shell import S
9
-
10
- INTERACTIVE = sys.stdin.isatty()
7
+ import wizlib.io
11
8
 
12
9
  COLOR = {
13
10
  Emphasis.INFO: S.BLUE,
@@ -38,13 +35,11 @@ class ShellUI(UI):
38
35
  sys.stderr.flush()
39
36
 
40
37
  def get_option(self, chooser: Chooser):
41
- """Get a choice from the user with a single keystroke"""
38
+ """Get a choice from the user with a single keystroke. Only works when
39
+ in a tty."""
42
40
  while True:
43
41
  self.ask(chooser.prompt_string)
44
- if INTERACTIVE:
45
- key = readkey()
46
- else:
47
- key = sys.stdin.read(1)
42
+ key = wizlib.io.ttyin()
48
43
  out = chooser.default if key == '\n' else \
49
44
  key if key.isprintable() else ''
50
45
  choice = chooser.choice_by_key(key)
@@ -59,8 +54,7 @@ class ShellUI(UI):
59
54
  """Allow the user to input an arbitrary line of text, with possible tab
60
55
  completion"""
61
56
  self.ask(prompt)
62
- if INTERACTIVE:
63
- value = ShellLineEditor(choices, default).edit()
64
- else:
65
- value = input()
57
+ value = ShellLineEditor(choices, default).edit()
58
+ # else:
59
+ # value = input()
66
60
  return value
@@ -1,8 +0,0 @@
1
- from unittest.mock import Mock, patch
2
-
3
-
4
- RK = 'wizlib.ui.shell.line_editor.readkey'
5
-
6
-
7
- def mock_keys(keys: str):
8
- return patch(RK, Mock(side_effect=keys))
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