zstdlib 0.10.13__tar.gz → 0.10.15__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.13 → zstdlib-0.10.15}/PKG-INFO +1 -1
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_ip_lock.py +13 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/__init__.py +3 -5
- zstdlib-0.10.15/zstdlib/exc/__init__.py +5 -0
- zstdlib-0.10.13/zstdlib/exc_capture.py → zstdlib-0.10.15/zstdlib/exc/capture.py +4 -4
- zstdlib-0.10.15/zstdlib/exc/pop_frames.py +79 -0
- zstdlib-0.10.15/zstdlib/exc/raise_.py +26 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/hybridmethod.py +1 -1
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/io.py +2 -2
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/ip_lock.py +12 -15
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/prompt.py +6 -6
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib.egg-info/SOURCES.txt +4 -2
- zstdlib-0.10.13/tests/test_exc_capture.py +0 -96
- {zstdlib-0.10.13 → zstdlib-0.10.15}/LICENSE +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/README.md +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/pyproject.toml +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/setup.cfg +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/__init__.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/log/base.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_enum.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_hybridmethod.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_io.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_keyed_instance.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_prompt.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_singleton.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/tests/test_util.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/ansi.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/frozen.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/keyed_instance.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/log/cute.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/log/trace.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/macos.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/not_set.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/signal_cm.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/singleton.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib/util.py +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.13 → zstdlib-0.10.15}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -185,26 +185,34 @@ class TestGlobalProcessLock(unittest.TestCase):
|
|
|
185
185
|
def test_sole_owner(self) -> None:
|
|
186
186
|
with mk_gipl() as lock:
|
|
187
187
|
self.assertFalse(lock.acquired)
|
|
188
|
+
self.assertEqual(lock.hold_count, 0)
|
|
188
189
|
# Can acquire existing file
|
|
189
190
|
self.assertTrue(lock.acquire(timeout_per=0))
|
|
190
191
|
self.assertTrue(lock.acquired)
|
|
192
|
+
self.assertEqual(lock.hold_count, 1)
|
|
191
193
|
# Re-acquisition, count == 2
|
|
192
194
|
self.assertTrue(lock.acquire(timeout_per=0))
|
|
193
195
|
self.assertTrue(lock.acquired)
|
|
196
|
+
self.assertEqual(lock.hold_count, 2)
|
|
194
197
|
# Release 1/2
|
|
195
198
|
lock.release()
|
|
196
199
|
self.assertTrue(lock.acquired)
|
|
200
|
+
self.assertEqual(lock.hold_count, 1)
|
|
197
201
|
# Release 2/2
|
|
198
202
|
lock.release()
|
|
199
203
|
self.assertFalse(lock.acquired)
|
|
204
|
+
self.assertEqual(lock.hold_count, 0)
|
|
200
205
|
# Release 3/2
|
|
201
206
|
with self.assertRaises(NotAcquiredError):
|
|
202
207
|
lock.release()
|
|
203
208
|
self.assertFalse(lock.acquired)
|
|
209
|
+
self.assertEqual(lock.hold_count, 0)
|
|
204
210
|
# CM exit, lock file removed by NTF
|
|
205
211
|
# Fresh acquire on non-existing file
|
|
206
212
|
lock.acquire(timeout_per=0)
|
|
213
|
+
self.assertTrue(lock.acquired)
|
|
207
214
|
lock.release()
|
|
215
|
+
self.assertFalse(lock.acquired)
|
|
208
216
|
|
|
209
217
|
def test_global(self) -> None:
|
|
210
218
|
with mk_gipl() as lock:
|
|
@@ -259,6 +267,7 @@ class TestIPLocks(unittest.TestCase):
|
|
|
259
267
|
# pylint: disable=protected-access
|
|
260
268
|
self.assertIs(lock._gipl, lock2._gipl)
|
|
261
269
|
self.assertFalse(lock._gipl.acquired)
|
|
270
|
+
self.assertEqual(lock._gipl.hold_count, 0)
|
|
262
271
|
with enter(lock):
|
|
263
272
|
|
|
264
273
|
def chk() -> None:
|
|
@@ -317,13 +326,17 @@ class TestIPLocks(unittest.TestCase):
|
|
|
317
326
|
# pylint: enable=protected-access
|
|
318
327
|
with mk_lock(IPLock) as lock, enter(lock):
|
|
319
328
|
self.assertTrue(lock.acquired)
|
|
329
|
+
self.assertEqual(lock.hold_count, 1)
|
|
320
330
|
self.assertFalse(lock.acquire(timeout_per=2))
|
|
321
331
|
self.assertTrue(lock.acquired)
|
|
332
|
+
self.assertEqual(lock.hold_count, 1)
|
|
322
333
|
self.assertFalse(lock.acquired)
|
|
323
334
|
del lock
|
|
324
335
|
with mk_lock(RIPLock) as rlock, enter(rlock), enter(rlock):
|
|
325
336
|
self.assertTrue(rlock.acquired)
|
|
337
|
+
self.assertEqual(rlock.hold_count, 2)
|
|
326
338
|
self.assertFalse(rlock.acquired)
|
|
339
|
+
self.assertEqual(rlock.hold_count, 0)
|
|
327
340
|
del rlock
|
|
328
341
|
|
|
329
342
|
with mk_lock(IPLock) as lock, self.assertRaises(LockPathInUseError):
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
__version__ = "0.10.
|
|
1
|
+
__version__ = "0.10.15"
|
|
2
2
|
|
|
3
3
|
from .prompt import prompt_until, prompt_for, yn_prompt
|
|
4
4
|
from .ip_lock import GlobalIPLock, IPLock, RIPLock
|
|
5
|
-
from .exc_capture import ExcCapture, ExcDelay
|
|
6
5
|
from .keyed_instance import KeyedInstance
|
|
7
6
|
from .hybridmethod import hybridmethod
|
|
8
7
|
from .not_set import NotSetType, NotSet
|
|
@@ -11,12 +10,10 @@ from .singleton import Singleton
|
|
|
11
10
|
from .signal_cm import signal_cm
|
|
12
11
|
from .enum import Enum, auto
|
|
13
12
|
from .util import normpath
|
|
14
|
-
from . import macos, lazy, log, io
|
|
13
|
+
from . import macos, lazy, log, exc, io
|
|
15
14
|
|
|
16
15
|
__all__ = (
|
|
17
16
|
"Enum",
|
|
18
|
-
"ExcCapture",
|
|
19
|
-
"ExcDelay",
|
|
20
17
|
"Freezable",
|
|
21
18
|
"GlobalIPLock",
|
|
22
19
|
"IPLock",
|
|
@@ -26,6 +23,7 @@ __all__ = (
|
|
|
26
23
|
"RIPLock",
|
|
27
24
|
"Singleton",
|
|
28
25
|
"auto",
|
|
26
|
+
"exc",
|
|
29
27
|
"frozen",
|
|
30
28
|
"hybridmethod",
|
|
31
29
|
"io",
|
|
@@ -2,13 +2,13 @@ from contextlib import AbstractContextManager, contextmanager
|
|
|
2
2
|
from collections.abc import Callable, Iterator
|
|
3
3
|
from typing import Self
|
|
4
4
|
|
|
5
|
-
__all__ = ("
|
|
5
|
+
__all__ = ("Capture", "Delay")
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
type EXC_T = type[BaseException] | tuple[type[BaseException]]
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class Capture:
|
|
12
12
|
"""A class that exposes a context manager which captures and suppresses any raised exception of a given type / tuple of types"""
|
|
13
13
|
|
|
14
14
|
# In python3.15 use sentinel
|
|
@@ -62,8 +62,8 @@ class ExcCapture:
|
|
|
62
62
|
return self.NoResult
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
class
|
|
66
|
-
"""A context manager subclass of
|
|
65
|
+
class Delay(Capture):
|
|
66
|
+
"""A context manager subclass of Capture that raises on exit if errors are captured"""
|
|
67
67
|
|
|
68
68
|
__slots__ = ("_msg", "armed")
|
|
69
69
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from types import TracebackType
|
|
2
|
+
from typing import Self
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
__all__ = ("PopFrames",)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PopFrames:
|
|
9
|
+
"""
|
|
10
|
+
A context manager used to pop traceback frames from an exception;
|
|
11
|
+
Note that python traceback frames are added as each call exception propgation unwinds the call stack
|
|
12
|
+
Thus you can only pop frames between the frame PopFrames lives in and where the exceptions was raised
|
|
13
|
+
MRO superclasses are not supported
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__slots__ = ("_furthest_n", "_n")
|
|
17
|
+
|
|
18
|
+
def __init__(self, n: int = 0, *, furthest_n: int = 0) -> None:
|
|
19
|
+
self._validate(n, furthest_n)
|
|
20
|
+
self._furthest_n: int = furthest_n
|
|
21
|
+
self._n = n
|
|
22
|
+
|
|
23
|
+
def __enter__(self) -> Self:
|
|
24
|
+
return self
|
|
25
|
+
|
|
26
|
+
def __exit__(
|
|
27
|
+
self, _: type[BaseException] | None, exc: BaseException | None, _2: TracebackType | None
|
|
28
|
+
) -> None:
|
|
29
|
+
if isinstance(exc, BaseException):
|
|
30
|
+
self.modify(exc, self._n, furthest_n=self._furthest_n)
|
|
31
|
+
elif exc is not None:
|
|
32
|
+
raise TypeError("exc is not a BaseException | None")
|
|
33
|
+
|
|
34
|
+
@classmethod
|
|
35
|
+
def modify(cls, exc: BaseException, n: int, furthest_n: int = 0) -> None:
|
|
36
|
+
"""Modify the traceback frames of exc; removes the n most recently entered frames
|
|
37
|
+
If foo calls bar calls baz which raises, n=2 removes (baz, raise)
|
|
38
|
+
from the traceback and furthest_n=1 removes foo from the traceback
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
exc: The exception to modify
|
|
42
|
+
n: The number of frames to remove, referse to the most recently entered frames
|
|
43
|
+
furthest_n: The number of frames to remove, referse to the least recently entered frames
|
|
44
|
+
"""
|
|
45
|
+
cls._validate(n, furthest_n)
|
|
46
|
+
if not isinstance(exc, BaseException):
|
|
47
|
+
raise TypeError("exc is not a BaseException")
|
|
48
|
+
if n == furthest_n == 0:
|
|
49
|
+
return
|
|
50
|
+
# Record the old traceback
|
|
51
|
+
frames: list[TracebackType] = []
|
|
52
|
+
tb = exc.__traceback__
|
|
53
|
+
while tb is not None:
|
|
54
|
+
frames.append(tb)
|
|
55
|
+
tb = tb.tb_next
|
|
56
|
+
# Install the new traceback
|
|
57
|
+
new: TracebackType | None = None
|
|
58
|
+
for f in reversed(frames[furthest_n if furthest_n else None : -n if n else None]):
|
|
59
|
+
new = TracebackType(new, f.tb_frame, f.tb_lasti, f.tb_lineno)
|
|
60
|
+
exc.__traceback__ = new
|
|
61
|
+
|
|
62
|
+
@classmethod
|
|
63
|
+
def active(cls, n: int = 0, *, reraise: bool, furthest_n: int = 0) -> None:
|
|
64
|
+
"""Remove traceback frames from an active exception, will reraise unless False"""
|
|
65
|
+
e = sys.exc_info()
|
|
66
|
+
if e[0] is None:
|
|
67
|
+
raise RuntimeError("No active exception")
|
|
68
|
+
cls.modify(e[1], n, furthest_n=furthest_n)
|
|
69
|
+
if reraise:
|
|
70
|
+
raise # noqa: PLE0704 # pylint: disable=misplaced-bare-raise
|
|
71
|
+
|
|
72
|
+
# Private helpers
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def _validate(n: int, furthest_n: int) -> None:
|
|
76
|
+
if not isinstance(n, int) or not isinstance(furthest_n, int):
|
|
77
|
+
raise TypeError("Number of frames to pop must be type int")
|
|
78
|
+
if n < 0 or furthest_n < 0:
|
|
79
|
+
raise ValueError("May not pop a negative number of frames")
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import Never
|
|
3
|
+
|
|
4
|
+
from ..not_set import NotSetType, NotSet
|
|
5
|
+
from .pop_frames import PopFrames
|
|
6
|
+
|
|
7
|
+
__all__ = ("raise_",)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def raise_[**P, R: BaseException](
|
|
11
|
+
e: BaseException,
|
|
12
|
+
from_: Callable[P, R] | R | None | NotSetType = NotSet,
|
|
13
|
+
/,
|
|
14
|
+
*args: P.args,
|
|
15
|
+
**kwargs: P.kwargs,
|
|
16
|
+
) -> Never:
|
|
17
|
+
"""Raise e from from_; if from_ isn't an exception, from_=from_(*args, **kwargs)"""
|
|
18
|
+
if not isinstance(from_, BaseException | None | NotSetType):
|
|
19
|
+
if not callable(from_):
|
|
20
|
+
raise TypeError("from_ must be callable")
|
|
21
|
+
from_ = from_(*args, **kwargs)
|
|
22
|
+
with PopFrames(1):
|
|
23
|
+
if from_ is NotSet:
|
|
24
|
+
raise e
|
|
25
|
+
assert isinstance(from_, BaseException | None)
|
|
26
|
+
raise e from from_
|
|
@@ -39,7 +39,7 @@ class hybridmethod[T, R, **P]: # Name aligns with @staticmethod and such
|
|
|
39
39
|
self._name = name
|
|
40
40
|
|
|
41
41
|
@overload
|
|
42
|
-
def __get__(self, instance: T, owner: type[T] | None =
|
|
42
|
+
def __get__(self, instance: T, owner: type[T] | None = ..., /) -> Callable[P, R]: ...
|
|
43
43
|
|
|
44
44
|
@overload
|
|
45
45
|
def __get__(self, instance: None, owner: type[T], /) -> Callable[P, R]: ...
|
|
@@ -202,11 +202,11 @@ class BinaryIO(_IOWrapperBase[bytes]):
|
|
|
202
202
|
|
|
203
203
|
|
|
204
204
|
@overload
|
|
205
|
-
def io(raw: IO[str], binary: bool | None =
|
|
205
|
+
def io(raw: IO[str], binary: bool | None = ...) -> TextIO: ...
|
|
206
206
|
|
|
207
207
|
|
|
208
208
|
@overload
|
|
209
|
-
def io(raw: IO[bytes], binary: bool | None =
|
|
209
|
+
def io(raw: IO[bytes], binary: bool | None = ...) -> BinaryIO: ...
|
|
210
210
|
|
|
211
211
|
|
|
212
212
|
def io[T: (str, bytes)](raw: IO[T], binary: bool | None = None) -> TextIO | BinaryIO:
|
|
@@ -32,6 +32,8 @@ class LockHungError(RuntimeError):
|
|
|
32
32
|
class AbstractIPLock(ABC):
|
|
33
33
|
"""An abstract interprocess lock that uses a Path for IPC synchronization"""
|
|
34
34
|
|
|
35
|
+
_rc: int # Instance varaible for subclasses to define
|
|
36
|
+
|
|
35
37
|
# Abstract Methods
|
|
36
38
|
|
|
37
39
|
@property
|
|
@@ -40,9 +42,15 @@ class AbstractIPLock(ABC):
|
|
|
40
42
|
"""The path this lock is synchronized across processes with"""
|
|
41
43
|
|
|
42
44
|
@property
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
def acquired(self) -> int:
|
|
46
|
+
"""Return True if the lock has been acquired; an alias for bool(self.hold_count)"""
|
|
47
|
+
return bool(self.hold_count)
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def hold_count(self) -> int:
|
|
51
|
+
"""Return the lock hold count / how many times this lock must be released"""
|
|
52
|
+
assert self._rc >= 0
|
|
53
|
+
return self._rc
|
|
46
54
|
|
|
47
55
|
@abstractmethod
|
|
48
56
|
def _acquire(self, blocking: bool, timeout_per: float | None) -> bool:
|
|
@@ -148,12 +156,6 @@ class GlobalIPLock(KeyedInstance, AbstractIPLock):
|
|
|
148
156
|
"""The path the lock is synchronized on"""
|
|
149
157
|
return self._path
|
|
150
158
|
|
|
151
|
-
@property
|
|
152
|
-
@override
|
|
153
|
-
def acquired(self) -> bool:
|
|
154
|
-
"""Return true if acquired"""
|
|
155
|
-
return bool(self._rc)
|
|
156
|
-
|
|
157
159
|
@override
|
|
158
160
|
def _acquire(self, blocking: bool, timeout_per: float | None) -> bool:
|
|
159
161
|
ret: bool = True
|
|
@@ -204,6 +206,7 @@ class _IPLock(AbstractIPLock):
|
|
|
204
206
|
"""
|
|
205
207
|
Construct an inter process lock syncronized by gipl (or GlobalIPLock.new(gipl) if str | Path)
|
|
206
208
|
If a lock of a different reentrancy setting already exists for this gipl, raise LockPathInUseError
|
|
209
|
+
args / kwargs are exclusively for super.__init__
|
|
207
210
|
"""
|
|
208
211
|
super().__init__(*args, **kwargs) # For MRO superclasses
|
|
209
212
|
if isinstance(gipl, Path | str):
|
|
@@ -229,12 +232,6 @@ class _IPLock(AbstractIPLock):
|
|
|
229
232
|
"""The path the lock is synchronized on"""
|
|
230
233
|
return self._gipl.path
|
|
231
234
|
|
|
232
|
-
@property
|
|
233
|
-
@override
|
|
234
|
-
def acquired(self) -> bool:
|
|
235
|
-
"""Return true if locked"""
|
|
236
|
-
return bool(self._rc) # Might return False during .release() after rc -=1, before .release()
|
|
237
|
-
|
|
238
235
|
@override
|
|
239
236
|
def _acquire(self, blocking: bool, timeout_per: float | None) -> bool:
|
|
240
237
|
ret = False
|
|
@@ -10,9 +10,9 @@ def prompt_until(
|
|
|
10
10
|
msg: str,
|
|
11
11
|
until: str | Iterable[str],
|
|
12
12
|
*,
|
|
13
|
-
ignore_case: bool =
|
|
14
|
-
eof: Literal[False] =
|
|
15
|
-
ctrl_c: Literal[False] =
|
|
13
|
+
ignore_case: bool = ...,
|
|
14
|
+
eof: Literal[False] = ...,
|
|
15
|
+
ctrl_c: Literal[False] = ...,
|
|
16
16
|
) -> str: ...
|
|
17
17
|
|
|
18
18
|
|
|
@@ -21,9 +21,9 @@ def prompt_until(
|
|
|
21
21
|
msg: str,
|
|
22
22
|
until: str | Iterable[str],
|
|
23
23
|
*,
|
|
24
|
-
ignore_case: bool =
|
|
25
|
-
eof: bool =
|
|
26
|
-
ctrl_c: bool =
|
|
24
|
+
ignore_case: bool = ...,
|
|
25
|
+
eof: bool = ...,
|
|
26
|
+
ctrl_c: bool = ...,
|
|
27
27
|
) -> str | None: ...
|
|
28
28
|
|
|
29
29
|
|
|
@@ -4,7 +4,6 @@ pyproject.toml
|
|
|
4
4
|
tests/__init__.py
|
|
5
5
|
tests/test_ansi.py
|
|
6
6
|
tests/test_enum.py
|
|
7
|
-
tests/test_exc_capture.py
|
|
8
7
|
tests/test_frozen.py
|
|
9
8
|
tests/test_hybridmethod.py
|
|
10
9
|
tests/test_io.py
|
|
@@ -22,7 +21,6 @@ tests/log/test_trace.py
|
|
|
22
21
|
zstdlib/__init__.py
|
|
23
22
|
zstdlib/ansi.py
|
|
24
23
|
zstdlib/enum.py
|
|
25
|
-
zstdlib/exc_capture.py
|
|
26
24
|
zstdlib/frozen.py
|
|
27
25
|
zstdlib/hybridmethod.py
|
|
28
26
|
zstdlib/io.py
|
|
@@ -41,6 +39,10 @@ zstdlib.egg-info/SOURCES.txt
|
|
|
41
39
|
zstdlib.egg-info/dependency_links.txt
|
|
42
40
|
zstdlib.egg-info/requires.txt
|
|
43
41
|
zstdlib.egg-info/top_level.txt
|
|
42
|
+
zstdlib/exc/__init__.py
|
|
43
|
+
zstdlib/exc/capture.py
|
|
44
|
+
zstdlib/exc/pop_frames.py
|
|
45
|
+
zstdlib/exc/raise_.py
|
|
44
46
|
zstdlib/log/__init__.py
|
|
45
47
|
zstdlib/log/cute.py
|
|
46
48
|
zstdlib/log/trace.py
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
|
2
|
-
import unittest
|
|
3
|
-
|
|
4
|
-
from zstdlib import ExcCapture, ExcDelay
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class TestLazy(unittest.TestCase):
|
|
8
|
-
|
|
9
|
-
def test_capture(self) -> None:
|
|
10
|
-
# Capture nothing
|
|
11
|
-
rt = ExcCapture(RuntimeError)
|
|
12
|
-
with rt.capture():
|
|
13
|
-
pass
|
|
14
|
-
self.assertEqual(len(rt.errors), 0)
|
|
15
|
-
# Capture only Runtime
|
|
16
|
-
with rt.capture():
|
|
17
|
-
raise RuntimeError()
|
|
18
|
-
self.assertEqual(len(rt.errors), 1)
|
|
19
|
-
with self.assertRaises(ValueError), rt.capture():
|
|
20
|
-
raise ValueError()
|
|
21
|
-
self.assertEqual(len(rt.errors), 1)
|
|
22
|
-
# previous
|
|
23
|
-
with rt.capture():
|
|
24
|
-
pass
|
|
25
|
-
self.assertIs(rt.previous, None)
|
|
26
|
-
test_err = RuntimeError("test")
|
|
27
|
-
with rt.capture():
|
|
28
|
-
raise test_err
|
|
29
|
-
self.assertEqual(rt.previous, test_err)
|
|
30
|
-
# capture's exc_t
|
|
31
|
-
rt = ExcCapture(RuntimeError)
|
|
32
|
-
with self.assertRaises(RuntimeError), rt.capture(ValueError):
|
|
33
|
-
raise RuntimeError()
|
|
34
|
-
self.assertEqual(len(rt.errors), 0)
|
|
35
|
-
with rt.capture(ValueError):
|
|
36
|
-
raise ValueError()
|
|
37
|
-
self.assertEqual(len(rt.errors), 1)
|
|
38
|
-
del rt
|
|
39
|
-
# exc_t = None
|
|
40
|
-
non = ExcCapture()
|
|
41
|
-
with self.assertRaises(RuntimeError), non.capture(ValueError):
|
|
42
|
-
raise RuntimeError()
|
|
43
|
-
self.assertEqual(len(non.errors), 0)
|
|
44
|
-
with self.assertRaises(ValueError), non.capture():
|
|
45
|
-
pass
|
|
46
|
-
self.assertEqual(len(non.errors), 0)
|
|
47
|
-
with non.capture(RuntimeError):
|
|
48
|
-
raise RuntimeError()
|
|
49
|
-
self.assertEqual(len(non.errors), 1)
|
|
50
|
-
# run_fn
|
|
51
|
-
ke = ExcCapture(KeyError)
|
|
52
|
-
self.assertEqual(ke.run_fn({0: 5}.__getitem__, 0), 5)
|
|
53
|
-
self.assertEqual(len(ke.errors), 0)
|
|
54
|
-
self.assertIs(ke.run_fn({}.__getitem__, 0), ke.NoResult)
|
|
55
|
-
self.assertEqual(len(ke.errors), 1)
|
|
56
|
-
|
|
57
|
-
def test_delay(self) -> None:
|
|
58
|
-
# No raise
|
|
59
|
-
with ExcDelay("msg", RuntimeError) as capture, capture():
|
|
60
|
-
pass
|
|
61
|
-
# Raise
|
|
62
|
-
ed = ExcDelay("msg", RuntimeError)
|
|
63
|
-
try:
|
|
64
|
-
with ed as capture:
|
|
65
|
-
with capture():
|
|
66
|
-
raise RuntimeError()
|
|
67
|
-
with capture():
|
|
68
|
-
raise RuntimeError()
|
|
69
|
-
self.assertTrue(False)
|
|
70
|
-
except BaseExceptionGroup as grp:
|
|
71
|
-
self.assertIsInstance(grp, ExceptionGroup) # Test auto-conversion
|
|
72
|
-
self.assertEqual(len(grp.exceptions), 2)
|
|
73
|
-
self.assertEqual(len(ed.errors), 2)
|
|
74
|
-
# No block error
|
|
75
|
-
with self.assertRaises(ValueError), ExcDelay("msg", RuntimeError) as capture, capture():
|
|
76
|
-
raise ValueError()
|
|
77
|
-
with self.assertRaises(ValueError), ExcDelay("msg", RuntimeError) as capture:
|
|
78
|
-
with capture():
|
|
79
|
-
raise RuntimeError()
|
|
80
|
-
raise ValueError()
|
|
81
|
-
# msg
|
|
82
|
-
_ = ExcDelay("")
|
|
83
|
-
with self.assertRaises(TypeError):
|
|
84
|
-
ExcDelay(RuntimeError) # type: ignore[arg-type]
|
|
85
|
-
# armed
|
|
86
|
-
with ExcDelay("", RuntimeError, armed=False) as capture, capture():
|
|
87
|
-
raise RuntimeError()
|
|
88
|
-
with ExcDelay("", RuntimeError, armed=True) as capture, capture():
|
|
89
|
-
capture.armed = False
|
|
90
|
-
raise RuntimeError()
|
|
91
|
-
with self.assertRaises(ExceptionGroup), ExcDelay("", RuntimeError, armed=True) as capture, capture():
|
|
92
|
-
raise RuntimeError()
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if __name__ == "__main__":
|
|
96
|
-
unittest.main()
|
|
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
|