dycw-utilities 0.162.5__py3-none-any.whl → 0.162.6__py3-none-any.whl
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.
- {dycw_utilities-0.162.5.dist-info → dycw_utilities-0.162.6.dist-info}/METADATA +1 -1
- {dycw_utilities-0.162.5.dist-info → dycw_utilities-0.162.6.dist-info}/RECORD +8 -8
- utilities/__init__.py +1 -1
- utilities/testbook.py +11 -7
- utilities/text.py +33 -18
- {dycw_utilities-0.162.5.dist-info → dycw_utilities-0.162.6.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.162.5.dist-info → dycw_utilities-0.162.6.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.162.5.dist-info → dycw_utilities-0.162.6.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=gjPlIBqtxGUVmb6pZvmbsEfu_kDvff1JWcZUUza19AQ,60
|
2
2
|
utilities/aeventkit.py,sha256=ddoleSwW9zdc2tjX5Ge0pMKtYwV_JMxhHYOxnWX2AGM,12609
|
3
3
|
utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
|
4
4
|
utilities/asyncio.py,sha256=PUedzQ5deqlSECQ33sam9cRzI9TnygHz3FdOqWJWPTM,15288
|
@@ -69,8 +69,8 @@ utilities/sqlalchemy_polars.py,sha256=JCGhB37raSR7fqeWV5dTsciRTMVzIdVT9YSqKT0piT
|
|
69
69
|
utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
|
70
70
|
utilities/string.py,sha256=shmBK87zZwzGyixuNuXCiUbqzfeZ9xlrFwz6JTaRvDk,582
|
71
71
|
utilities/tempfile.py,sha256=HxB2BF28CcecDJLQ3Bx2Ej-Pb6RJc6W9ngSpB9CnP4k,2018
|
72
|
-
utilities/testbook.py,sha256=
|
73
|
-
utilities/text.py,sha256=
|
72
|
+
utilities/testbook.py,sha256=j1KmaVbrX9VrbeMgtPh5gk55myAsn3dyRUn7jGbPbRk,1294
|
73
|
+
utilities/text.py,sha256=oMARu9HA3lY-NNRxPsz0Ld7L1ki7VKO_hmWYARYt0xY,13476
|
74
74
|
utilities/threading.py,sha256=GvBOp4CyhHfN90wGXZuA2VKe9fGzMaEa7oCl4f3nnPU,1009
|
75
75
|
utilities/timer.py,sha256=oXfTii6ymu57niP0BDGZjFD55LEHi2a19kqZKiTgaFQ,2588
|
76
76
|
utilities/traceback.py,sha256=1k5JgumSMaqAGLd0dZ36CtPS0EGaglxTr29r2Dz4D60,9457
|
@@ -88,8 +88,8 @@ utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
|
|
88
88
|
utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
89
89
|
utilities/pytest_plugins/pytest_randomly.py,sha256=B1qYVlExGOxTywq2r1SMi5o7btHLk2PNdY_b1p98dkE,409
|
90
90
|
utilities/pytest_plugins/pytest_regressions.py,sha256=9v8kAXDM2ycIXJBimoiF4EgrwbUvxTycFWJiGR_GHhM,1466
|
91
|
-
dycw_utilities-0.162.
|
92
|
-
dycw_utilities-0.162.
|
93
|
-
dycw_utilities-0.162.
|
94
|
-
dycw_utilities-0.162.
|
95
|
-
dycw_utilities-0.162.
|
91
|
+
dycw_utilities-0.162.6.dist-info/METADATA,sha256=zXFVqk-andgkMkvkEddzxk1O5hfu6j0oe-b5iEeRVAE,1696
|
92
|
+
dycw_utilities-0.162.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
93
|
+
dycw_utilities-0.162.6.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
|
94
|
+
dycw_utilities-0.162.6.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
95
|
+
dycw_utilities-0.162.6.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/testbook.py
CHANGED
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Any
|
|
6
6
|
from testbook import testbook
|
7
7
|
|
8
8
|
from utilities.pytest import throttle
|
9
|
+
from utilities.text import pascal_case
|
9
10
|
|
10
11
|
if TYPE_CHECKING:
|
11
12
|
from collections.abc import Callable
|
@@ -15,16 +16,19 @@ if TYPE_CHECKING:
|
|
15
16
|
|
16
17
|
def build_notebook_tester(
|
17
18
|
path: PathLike, /, *, throttle: Delta | None = None, on_try: bool = False
|
18
|
-
) ->
|
19
|
-
"""Build the notebook
|
20
|
-
|
19
|
+
) -> type[Any]:
|
20
|
+
"""Build the notebook tester class."""
|
21
|
+
path = Path(path)
|
22
|
+
name = f"Test{pascal_case(path.stem)}"
|
21
23
|
notebooks = [
|
22
24
|
path_i
|
23
|
-
for path_i in
|
25
|
+
for path_i in path.rglob("**/*.ipynb")
|
24
26
|
if all(p != ".ipynb_checkpoints" for p in path_i.parts)
|
25
27
|
]
|
26
28
|
namespace = {
|
27
|
-
f"test_{p.stem}": _build_test_method(
|
29
|
+
f"test_{p.stem.replace('-', '_')}": _build_test_method(
|
30
|
+
p, delta=throttle, on_try=on_try
|
31
|
+
)
|
28
32
|
for p in notebooks
|
29
33
|
}
|
30
34
|
return type(name, (), namespace)
|
@@ -33,14 +37,14 @@ def build_notebook_tester(
|
|
33
37
|
def _build_test_method(
|
34
38
|
path: Path, /, *, delta: Delta | None = None, on_try: bool = False
|
35
39
|
) -> Callable[..., Any]:
|
40
|
+
@testbook(path, execute=True)
|
36
41
|
def method(self: Any, tb: Any) -> None:
|
37
42
|
_ = (self, tb) # pragma: no cover
|
38
43
|
|
39
44
|
if delta is not None:
|
40
45
|
method = throttle(delta=delta, on_try=on_try)(method)
|
41
46
|
|
42
|
-
|
43
|
-
return tbook(method)
|
47
|
+
return method
|
44
48
|
|
45
49
|
|
46
50
|
__all__ = ["build_notebook_tester"]
|
utilities/text.py
CHANGED
@@ -6,7 +6,7 @@ from collections.abc import Callable
|
|
6
6
|
from dataclasses import dataclass
|
7
7
|
from itertools import chain
|
8
8
|
from os import getpid
|
9
|
-
from re import IGNORECASE,
|
9
|
+
from re import IGNORECASE, VERBOSE, escape, search
|
10
10
|
from textwrap import dedent
|
11
11
|
from threading import get_ident
|
12
12
|
from time import time_ns
|
@@ -77,6 +77,21 @@ class ParseNoneError(Exception):
|
|
77
77
|
##
|
78
78
|
|
79
79
|
|
80
|
+
def pascal_case(text: str, /) -> str:
|
81
|
+
"""Convert text to pascal case."""
|
82
|
+
parts = _SPLIT_TEXT.findall(text)
|
83
|
+
parts = [p for p in parts if len(p) >= 1]
|
84
|
+
parts = list(map(_pascal_case_one, parts))
|
85
|
+
return "".join(parts)
|
86
|
+
|
87
|
+
|
88
|
+
def _pascal_case_one(text: str, /) -> str:
|
89
|
+
return text if text.isupper() else text.title()
|
90
|
+
|
91
|
+
|
92
|
+
##
|
93
|
+
|
94
|
+
|
80
95
|
def repr_encode(obj: Any, /) -> bytes:
|
81
96
|
"""Return the representation of the object encoded as bytes."""
|
82
97
|
return repr(obj).encode()
|
@@ -85,25 +100,24 @@ def repr_encode(obj: Any, /) -> bytes:
|
|
85
100
|
##
|
86
101
|
|
87
102
|
|
88
|
-
_ACRONYM_PATTERN = re.compile(r"([A-Z\d]+)(?=[A-Z\d]|$)")
|
89
|
-
_SPACES_PATTERN = re.compile(r"\s+")
|
90
|
-
_SPLIT_PATTERN = re.compile(r"([\-_]*[A-Z][^A-Z]*[\-_]*)")
|
91
|
-
|
92
|
-
|
93
103
|
def snake_case(text: str, /) -> str:
|
94
104
|
"""Convert text into snake case."""
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
leading = bool(search(r"^_", text))
|
106
|
+
trailing = bool(search(r"_$", text))
|
107
|
+
parts = _SPLIT_TEXT.findall(text)
|
108
|
+
parts = (p for p in parts if len(p) >= 1)
|
109
|
+
parts = chain([""] if leading else [], parts, [""] if trailing else [])
|
110
|
+
return "_".join(parts).lower()
|
111
|
+
|
112
|
+
|
113
|
+
_SPLIT_TEXT = re.compile(
|
114
|
+
r"""
|
115
|
+
[A-Z]+(?=[A-Z][a-z0-9]) | # all caps followed by Upper+lower or digit (API in APIResponse2)
|
116
|
+
[A-Z]?[a-z]+[0-9]* | # normal words with optional trailing digits (Text123)
|
117
|
+
[A-Z]+[0-9]* | # consecutive caps with optional trailing digits (ID2)
|
118
|
+
""",
|
119
|
+
flags=VERBOSE,
|
120
|
+
)
|
107
121
|
|
108
122
|
##
|
109
123
|
|
@@ -503,6 +517,7 @@ __all__ = [
|
|
503
517
|
"join_strs",
|
504
518
|
"parse_bool",
|
505
519
|
"parse_none",
|
520
|
+
"pascal_case",
|
506
521
|
"repr_encode",
|
507
522
|
"secret_str",
|
508
523
|
"snake_case",
|
File without changes
|
File without changes
|
File without changes
|