winipedia-utils 0.2.10__py3-none-any.whl → 0.2.18__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.
Potentially problematic release.
This version of winipedia-utils might be problematic. Click here for more details.
- winipedia_utils/concurrent/concurrent.py +245 -245
- winipedia_utils/concurrent/multiprocessing.py +130 -130
- winipedia_utils/concurrent/multithreading.py +93 -93
- winipedia_utils/consts.py +21 -21
- winipedia_utils/data/__init__.py +1 -1
- winipedia_utils/data/dataframe/__init__.py +1 -1
- winipedia_utils/data/dataframe/cleaning.py +378 -378
- winipedia_utils/data/structures/__init__.py +1 -1
- winipedia_utils/data/structures/dicts.py +16 -16
- winipedia_utils/git/__init__.py +1 -1
- winipedia_utils/git/gitignore/__init__.py +1 -1
- winipedia_utils/git/gitignore/gitignore.py +136 -136
- winipedia_utils/git/pre_commit/__init__.py +1 -1
- winipedia_utils/git/pre_commit/config.py +70 -70
- winipedia_utils/git/pre_commit/hooks.py +127 -109
- winipedia_utils/git/pre_commit/run_hooks.py +49 -49
- winipedia_utils/iterating/__init__.py +1 -1
- winipedia_utils/iterating/iterate.py +29 -29
- winipedia_utils/logging/ansi.py +6 -6
- winipedia_utils/logging/config.py +64 -64
- winipedia_utils/logging/logger.py +26 -26
- winipedia_utils/modules/class_.py +119 -119
- winipedia_utils/modules/function.py +101 -101
- winipedia_utils/modules/module.py +379 -379
- winipedia_utils/modules/package.py +390 -390
- winipedia_utils/oop/mixins/meta.py +333 -333
- winipedia_utils/oop/mixins/mixin.py +37 -37
- winipedia_utils/os/__init__.py +1 -1
- winipedia_utils/os/os.py +63 -63
- winipedia_utils/projects/__init__.py +1 -1
- winipedia_utils/projects/poetry/__init__.py +1 -1
- winipedia_utils/projects/poetry/config.py +117 -117
- winipedia_utils/projects/poetry/poetry.py +31 -31
- winipedia_utils/projects/project.py +48 -48
- winipedia_utils/resources/__init__.py +1 -1
- winipedia_utils/resources/svgs/__init__.py +1 -1
- winipedia_utils/resources/svgs/download_arrow.svg +2 -2
- winipedia_utils/resources/svgs/exit_fullscreen_icon.svg +5 -5
- winipedia_utils/resources/svgs/fullscreen_icon.svg +2 -2
- winipedia_utils/resources/svgs/menu_icon.svg +3 -3
- winipedia_utils/resources/svgs/pause_icon.svg +3 -3
- winipedia_utils/resources/svgs/play_icon.svg +16 -16
- winipedia_utils/resources/svgs/plus_icon.svg +23 -23
- winipedia_utils/resources/svgs/svg.py +15 -15
- winipedia_utils/security/__init__.py +1 -1
- winipedia_utils/security/cryptography.py +29 -29
- winipedia_utils/security/keyring.py +70 -70
- winipedia_utils/setup.py +47 -47
- winipedia_utils/testing/assertions.py +23 -23
- winipedia_utils/testing/convention.py +177 -177
- winipedia_utils/testing/create_tests.py +297 -297
- winipedia_utils/testing/fixtures.py +28 -28
- winipedia_utils/testing/tests/base/fixtures/__init__.py +1 -1
- winipedia_utils/testing/tests/base/fixtures/fixture.py +6 -6
- winipedia_utils/testing/tests/base/fixtures/scopes/class_.py +33 -33
- winipedia_utils/testing/tests/base/fixtures/scopes/function.py +7 -7
- winipedia_utils/testing/tests/base/fixtures/scopes/module.py +33 -33
- winipedia_utils/testing/tests/base/fixtures/scopes/package.py +7 -7
- winipedia_utils/testing/tests/base/fixtures/scopes/session.py +296 -296
- winipedia_utils/testing/tests/base/utils/utils.py +111 -111
- winipedia_utils/testing/tests/conftest.py +32 -32
- winipedia_utils/text/string.py +126 -126
- winipedia_utils-0.2.18.dist-info/METADATA +715 -0
- winipedia_utils-0.2.18.dist-info/RECORD +80 -0
- {winipedia_utils-0.2.10.dist-info → winipedia_utils-0.2.18.dist-info}/licenses/LICENSE +21 -21
- winipedia_utils/testing/tests/test_0.py +0 -8
- winipedia_utils-0.2.10.dist-info/METADATA +0 -355
- winipedia_utils-0.2.10.dist-info/RECORD +0 -81
- {winipedia_utils-0.2.10.dist-info → winipedia_utils-0.2.18.dist-info}/WHEEL +0 -0
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
"""Testing conventions and utilities.
|
|
2
|
-
|
|
3
|
-
This module provides functions and constants for managing test naming conventions,
|
|
4
|
-
mapping between test objects and their corresponding implementation objects,
|
|
5
|
-
and utilities for test discovery and validation.
|
|
6
|
-
|
|
7
|
-
Returns:
|
|
8
|
-
Various utility functions and constants for testing conventions.
|
|
9
|
-
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
from collections.abc import Callable, Iterable
|
|
13
|
-
from types import ModuleType
|
|
14
|
-
from typing import Any
|
|
15
|
-
|
|
16
|
-
from winipedia_utils.modules.module import (
|
|
17
|
-
get_isolated_obj_name,
|
|
18
|
-
import_obj_from_importpath,
|
|
19
|
-
make_obj_importpath,
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
TEST_FUNCTION_PREFIX = "test_"
|
|
23
|
-
|
|
24
|
-
TEST_CLASS_PREFIX = "Test"
|
|
25
|
-
|
|
26
|
-
TEST_MODULE_PREFIX = TEST_FUNCTION_PREFIX
|
|
27
|
-
|
|
28
|
-
TEST_PREFIXES = [TEST_FUNCTION_PREFIX, TEST_CLASS_PREFIX, TEST_MODULE_PREFIX]
|
|
29
|
-
|
|
30
|
-
TESTS_PACKAGE_NAME = "tests"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def get_right_test_prefix(obj: Callable[..., Any] | type | ModuleType) -> str:
|
|
34
|
-
"""Get the appropriate test prefix for an object based on its type.
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
obj: The object to get the test prefix for (function, class, or module)
|
|
38
|
-
|
|
39
|
-
Returns:
|
|
40
|
-
The appropriate test prefix string for the given object type
|
|
41
|
-
|
|
42
|
-
"""
|
|
43
|
-
if isinstance(obj, ModuleType):
|
|
44
|
-
return TEST_MODULE_PREFIX
|
|
45
|
-
if isinstance(obj, type):
|
|
46
|
-
return TEST_CLASS_PREFIX
|
|
47
|
-
return TEST_FUNCTION_PREFIX
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def make_test_obj_name(obj: Callable[..., Any] | type | ModuleType) -> str:
|
|
51
|
-
"""Create a test name for an object by adding the appropriate prefix.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
obj: The object to create a test name for
|
|
55
|
-
|
|
56
|
-
Returns:
|
|
57
|
-
The test name with the appropriate prefix
|
|
58
|
-
|
|
59
|
-
"""
|
|
60
|
-
prefix = get_right_test_prefix(obj)
|
|
61
|
-
name = get_isolated_obj_name(obj)
|
|
62
|
-
return prefix + name
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def reverse_make_test_obj_name(test_name: str) -> str:
|
|
66
|
-
"""Extract the original object name from a test name by removing the prefix.
|
|
67
|
-
|
|
68
|
-
Args:
|
|
69
|
-
test_name: The test name to extract the original name from
|
|
70
|
-
|
|
71
|
-
Returns:
|
|
72
|
-
The original object name without the test prefix
|
|
73
|
-
|
|
74
|
-
Raises:
|
|
75
|
-
ValueError: If the test name doesn't start with any of the expected prefixes
|
|
76
|
-
|
|
77
|
-
"""
|
|
78
|
-
for prefix in TEST_PREFIXES:
|
|
79
|
-
if test_name.startswith(prefix):
|
|
80
|
-
return test_name.removeprefix(prefix)
|
|
81
|
-
msg = f"{test_name=} is expected to start with one of {TEST_PREFIXES=}"
|
|
82
|
-
raise ValueError(msg)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def make_test_obj_importpath_from_obj(
|
|
86
|
-
obj: Callable[..., Any] | type | ModuleType,
|
|
87
|
-
) -> str:
|
|
88
|
-
"""Create an import path for a test object based on the original object.
|
|
89
|
-
|
|
90
|
-
Args:
|
|
91
|
-
obj: The original object to create a test import path for
|
|
92
|
-
|
|
93
|
-
Returns:
|
|
94
|
-
The import path for the corresponding test object
|
|
95
|
-
|
|
96
|
-
"""
|
|
97
|
-
parts = make_obj_importpath(obj).split(".")
|
|
98
|
-
test_name = make_test_obj_name(obj)
|
|
99
|
-
test_parts = [
|
|
100
|
-
(TEST_MODULE_PREFIX if part[0].islower() else TEST_CLASS_PREFIX) + part
|
|
101
|
-
for part in parts
|
|
102
|
-
]
|
|
103
|
-
test_parts[-1] = test_name
|
|
104
|
-
test_parts.insert(0, TESTS_PACKAGE_NAME)
|
|
105
|
-
return ".".join(test_parts)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def make_obj_importpath_from_test_obj(
|
|
109
|
-
test_obj: Callable[..., Any] | type | ModuleType,
|
|
110
|
-
) -> str:
|
|
111
|
-
"""Create an import path for an original object based on its test object.
|
|
112
|
-
|
|
113
|
-
Args:
|
|
114
|
-
test_obj: The test object to create an original import path for
|
|
115
|
-
|
|
116
|
-
Returns:
|
|
117
|
-
The import path for the corresponding original object
|
|
118
|
-
|
|
119
|
-
"""
|
|
120
|
-
test_parts = make_obj_importpath(test_obj).split(".")
|
|
121
|
-
test_parts = test_parts[1:]
|
|
122
|
-
parts = [reverse_make_test_obj_name(part) for part in test_parts]
|
|
123
|
-
return ".".join(parts)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
def get_test_obj_from_obj(
|
|
127
|
-
obj: Callable[..., Any] | type | ModuleType,
|
|
128
|
-
) -> Callable[..., Any] | type | ModuleType:
|
|
129
|
-
"""Get the test object corresponding to an original object.
|
|
130
|
-
|
|
131
|
-
Args:
|
|
132
|
-
obj: The original object to get the test object for
|
|
133
|
-
|
|
134
|
-
Returns:
|
|
135
|
-
The corresponding test object
|
|
136
|
-
|
|
137
|
-
"""
|
|
138
|
-
test_obj_path = make_test_obj_importpath_from_obj(obj)
|
|
139
|
-
return import_obj_from_importpath(test_obj_path)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def get_obj_from_test_obj(
|
|
143
|
-
test_obj: Callable[..., Any] | type | ModuleType,
|
|
144
|
-
) -> Callable[..., Any] | type | ModuleType:
|
|
145
|
-
"""Get the original object corresponding to a test object.
|
|
146
|
-
|
|
147
|
-
Args:
|
|
148
|
-
test_obj: The test object to get the original object for
|
|
149
|
-
|
|
150
|
-
Returns:
|
|
151
|
-
The corresponding original object
|
|
152
|
-
|
|
153
|
-
"""
|
|
154
|
-
obj_importpath = make_obj_importpath_from_test_obj(test_obj)
|
|
155
|
-
return import_obj_from_importpath(obj_importpath)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def make_untested_summary_error_msg(
|
|
159
|
-
untested_objs: Iterable[str],
|
|
160
|
-
) -> str:
|
|
161
|
-
"""Create an error message summarizing untested objects.
|
|
162
|
-
|
|
163
|
-
Args:
|
|
164
|
-
untested_objs: Collection of import paths for untested objects
|
|
165
|
-
|
|
166
|
-
Returns:
|
|
167
|
-
A formatted error message listing all untested objects
|
|
168
|
-
|
|
169
|
-
"""
|
|
170
|
-
msg = """
|
|
171
|
-
Found untested objects:
|
|
172
|
-
"""
|
|
173
|
-
for untested in untested_objs:
|
|
174
|
-
msg += f"""
|
|
175
|
-
- {untested}
|
|
176
|
-
"""
|
|
177
|
-
return msg
|
|
1
|
+
"""Testing conventions and utilities.
|
|
2
|
+
|
|
3
|
+
This module provides functions and constants for managing test naming conventions,
|
|
4
|
+
mapping between test objects and their corresponding implementation objects,
|
|
5
|
+
and utilities for test discovery and validation.
|
|
6
|
+
|
|
7
|
+
Returns:
|
|
8
|
+
Various utility functions and constants for testing conventions.
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from collections.abc import Callable, Iterable
|
|
13
|
+
from types import ModuleType
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from winipedia_utils.modules.module import (
|
|
17
|
+
get_isolated_obj_name,
|
|
18
|
+
import_obj_from_importpath,
|
|
19
|
+
make_obj_importpath,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
TEST_FUNCTION_PREFIX = "test_"
|
|
23
|
+
|
|
24
|
+
TEST_CLASS_PREFIX = "Test"
|
|
25
|
+
|
|
26
|
+
TEST_MODULE_PREFIX = TEST_FUNCTION_PREFIX
|
|
27
|
+
|
|
28
|
+
TEST_PREFIXES = [TEST_FUNCTION_PREFIX, TEST_CLASS_PREFIX, TEST_MODULE_PREFIX]
|
|
29
|
+
|
|
30
|
+
TESTS_PACKAGE_NAME = "tests"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_right_test_prefix(obj: Callable[..., Any] | type | ModuleType) -> str:
|
|
34
|
+
"""Get the appropriate test prefix for an object based on its type.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
obj: The object to get the test prefix for (function, class, or module)
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The appropriate test prefix string for the given object type
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
if isinstance(obj, ModuleType):
|
|
44
|
+
return TEST_MODULE_PREFIX
|
|
45
|
+
if isinstance(obj, type):
|
|
46
|
+
return TEST_CLASS_PREFIX
|
|
47
|
+
return TEST_FUNCTION_PREFIX
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def make_test_obj_name(obj: Callable[..., Any] | type | ModuleType) -> str:
|
|
51
|
+
"""Create a test name for an object by adding the appropriate prefix.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
obj: The object to create a test name for
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
The test name with the appropriate prefix
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
prefix = get_right_test_prefix(obj)
|
|
61
|
+
name = get_isolated_obj_name(obj)
|
|
62
|
+
return prefix + name
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def reverse_make_test_obj_name(test_name: str) -> str:
|
|
66
|
+
"""Extract the original object name from a test name by removing the prefix.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
test_name: The test name to extract the original name from
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
The original object name without the test prefix
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
ValueError: If the test name doesn't start with any of the expected prefixes
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
for prefix in TEST_PREFIXES:
|
|
79
|
+
if test_name.startswith(prefix):
|
|
80
|
+
return test_name.removeprefix(prefix)
|
|
81
|
+
msg = f"{test_name=} is expected to start with one of {TEST_PREFIXES=}"
|
|
82
|
+
raise ValueError(msg)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def make_test_obj_importpath_from_obj(
|
|
86
|
+
obj: Callable[..., Any] | type | ModuleType,
|
|
87
|
+
) -> str:
|
|
88
|
+
"""Create an import path for a test object based on the original object.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
obj: The original object to create a test import path for
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
The import path for the corresponding test object
|
|
95
|
+
|
|
96
|
+
"""
|
|
97
|
+
parts = make_obj_importpath(obj).split(".")
|
|
98
|
+
test_name = make_test_obj_name(obj)
|
|
99
|
+
test_parts = [
|
|
100
|
+
(TEST_MODULE_PREFIX if part[0].islower() else TEST_CLASS_PREFIX) + part
|
|
101
|
+
for part in parts
|
|
102
|
+
]
|
|
103
|
+
test_parts[-1] = test_name
|
|
104
|
+
test_parts.insert(0, TESTS_PACKAGE_NAME)
|
|
105
|
+
return ".".join(test_parts)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def make_obj_importpath_from_test_obj(
|
|
109
|
+
test_obj: Callable[..., Any] | type | ModuleType,
|
|
110
|
+
) -> str:
|
|
111
|
+
"""Create an import path for an original object based on its test object.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
test_obj: The test object to create an original import path for
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
The import path for the corresponding original object
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
test_parts = make_obj_importpath(test_obj).split(".")
|
|
121
|
+
test_parts = test_parts[1:]
|
|
122
|
+
parts = [reverse_make_test_obj_name(part) for part in test_parts]
|
|
123
|
+
return ".".join(parts)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def get_test_obj_from_obj(
|
|
127
|
+
obj: Callable[..., Any] | type | ModuleType,
|
|
128
|
+
) -> Callable[..., Any] | type | ModuleType:
|
|
129
|
+
"""Get the test object corresponding to an original object.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
obj: The original object to get the test object for
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
The corresponding test object
|
|
136
|
+
|
|
137
|
+
"""
|
|
138
|
+
test_obj_path = make_test_obj_importpath_from_obj(obj)
|
|
139
|
+
return import_obj_from_importpath(test_obj_path)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def get_obj_from_test_obj(
|
|
143
|
+
test_obj: Callable[..., Any] | type | ModuleType,
|
|
144
|
+
) -> Callable[..., Any] | type | ModuleType:
|
|
145
|
+
"""Get the original object corresponding to a test object.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
test_obj: The test object to get the original object for
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
The corresponding original object
|
|
152
|
+
|
|
153
|
+
"""
|
|
154
|
+
obj_importpath = make_obj_importpath_from_test_obj(test_obj)
|
|
155
|
+
return import_obj_from_importpath(obj_importpath)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def make_untested_summary_error_msg(
|
|
159
|
+
untested_objs: Iterable[str],
|
|
160
|
+
) -> str:
|
|
161
|
+
"""Create an error message summarizing untested objects.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
untested_objs: Collection of import paths for untested objects
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
A formatted error message listing all untested objects
|
|
168
|
+
|
|
169
|
+
"""
|
|
170
|
+
msg = """
|
|
171
|
+
Found untested objects:
|
|
172
|
+
"""
|
|
173
|
+
for untested in untested_objs:
|
|
174
|
+
msg += f"""
|
|
175
|
+
- {untested}
|
|
176
|
+
"""
|
|
177
|
+
return msg
|