surety 0.0.1__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.
Files changed (63) hide show
  1. surety-0.0.1/.github/workflows/publish.yml +30 -0
  2. surety-0.0.1/.github/workflows/pylint.yml +24 -0
  3. surety-0.0.1/.github/workflows/release.yml +41 -0
  4. surety-0.0.1/.github/workflows/test.yml +39 -0
  5. surety-0.0.1/.gitignore +207 -0
  6. surety-0.0.1/.pylintrc +44 -0
  7. surety-0.0.1/LICENSE +21 -0
  8. surety-0.0.1/PKG-INFO +42 -0
  9. surety-0.0.1/README.md +24 -0
  10. surety-0.0.1/pyproject.toml +43 -0
  11. surety-0.0.1/pytest.ini +3 -0
  12. surety-0.0.1/requirements/common.txt +2 -0
  13. surety-0.0.1/requirements/test.txt +4 -0
  14. surety-0.0.1/setup.cfg +4 -0
  15. surety-0.0.1/src/__init__.py +0 -0
  16. surety-0.0.1/src/surety/__init__.py +0 -0
  17. surety-0.0.1/src/surety/process/__init__.py +0 -0
  18. surety-0.0.1/src/surety/process/common.py +112 -0
  19. surety-0.0.1/src/surety/process/dictionary.py +409 -0
  20. surety-0.0.1/src/surety/sdk/__init__.py +7 -0
  21. surety-0.0.1/src/surety/sdk/array.py +112 -0
  22. surety-0.0.1/src/surety/sdk/base_enum.py +31 -0
  23. surety-0.0.1/src/surety/sdk/dates.py +55 -0
  24. surety-0.0.1/src/surety/sdk/dictionary.py +198 -0
  25. surety-0.0.1/src/surety/sdk/fakeable.py +142 -0
  26. surety-0.0.1/src/surety/sdk/field.py +80 -0
  27. surety-0.0.1/src/surety/sdk/types.py +195 -0
  28. surety-0.0.1/src/surety.egg-info/PKG-INFO +42 -0
  29. surety-0.0.1/src/surety.egg-info/SOURCES.txt +61 -0
  30. surety-0.0.1/src/surety.egg-info/dependency_links.txt +1 -0
  31. surety-0.0.1/src/surety.egg-info/requires.txt +2 -0
  32. surety-0.0.1/src/surety.egg-info/top_level.txt +1 -0
  33. surety-0.0.1/tests/__init__.py +0 -0
  34. surety-0.0.1/tests/data.py +67 -0
  35. surety-0.0.1/tests/process/__init__.py +0 -0
  36. surety-0.0.1/tests/process/test_dictionary.py +44 -0
  37. surety-0.0.1/tests/process/test_is_callable_with_strict_args.py +37 -0
  38. surety-0.0.1/tests/sdk/__init__.py +0 -0
  39. surety-0.0.1/tests/sdk/test_array.py +66 -0
  40. surety-0.0.1/tests/sdk/test_base_enum.py +55 -0
  41. surety-0.0.1/tests/sdk/test_dates.py +36 -0
  42. surety-0.0.1/tests/sdk/test_dictionary.py +103 -0
  43. surety-0.0.1/tests/sdk/test_fakeable.py +59 -0
  44. surety-0.0.1/tests/sdk/test_field.py +42 -0
  45. surety-0.0.1/tests/sdk/test_types.py +169 -0
  46. surety-0.0.1/tests/test_data_generators/__init__.py +0 -0
  47. surety-0.0.1/tests/test_data_generators/test_full_param.py +11 -0
  48. surety-0.0.1/tests/test_data_generators/test_full_value.py +45 -0
  49. surety-0.0.1/tests/test_data_generators/test_generate.py +91 -0
  50. surety-0.0.1/tests/test_data_generators/test_generated.py +70 -0
  51. surety-0.0.1/tests/test_data_generators/test_instance.py +29 -0
  52. surety-0.0.1/tests/test_data_generators/test_name.py +22 -0
  53. surety-0.0.1/tests/test_data_generators/test_required_param.py +27 -0
  54. surety-0.0.1/tests/test_data_generators/test_value.py +69 -0
  55. surety-0.0.1/tests/test_data_generators/test_with_values.py +112 -0
  56. surety-0.0.1/tests/test_instances/__init__.py +0 -0
  57. surety-0.0.1/tests/test_instances/test_allowed_none_param.py +21 -0
  58. surety-0.0.1/tests/test_instances/test_full_param.py +9 -0
  59. surety-0.0.1/tests/test_instances/test_generated.py +17 -0
  60. surety-0.0.1/tests/test_instances/test_instance.py +25 -0
  61. surety-0.0.1/tests/test_instances/test_name.py +17 -0
  62. surety-0.0.1/tests/test_instances/test_required_param.py +21 -0
  63. surety-0.0.1/tests/test_instances/test_value.py +17 -0
@@ -0,0 +1,30 @@
1
+ name: Upload Python Package
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows: ["Create Release"]
6
+ types: [completed]
7
+
8
+ jobs:
9
+ deploy:
10
+
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ with:
16
+ fetch-depth: 0
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v2
19
+ with:
20
+ python-version: '3.x'
21
+ - name: Install dependencies
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ pip install build
25
+ - name: Build package
26
+ run: python -m build
27
+ - name: Publish package
28
+ uses: pypa/gh-action-pypi-publish@release/v1
29
+ with:
30
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,24 @@
1
+ name: Pylint
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ python-version: ["3.8", "3.9", "3.10"]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Python ${{ matrix.python-version }}
14
+ uses: actions/setup-python@v2
15
+ with:
16
+ python-version: ${{ matrix.python-version }}
17
+ - name: Install dependencies
18
+ run: |
19
+ python -m pip install --upgrade pip
20
+ pip install pylint
21
+ pip install -r requirements/test.txt
22
+ - name: Analysing the code with pylint
23
+ run:
24
+ python -m pylint *
@@ -0,0 +1,41 @@
1
+ name: Create Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ tag-and-release:
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.12"
23
+
24
+ - run: pip install build setuptools-scm
25
+
26
+ - name: Build package
27
+ run: python -m build
28
+
29
+ - name: Create tag
30
+ id: tag
31
+ uses: anothrNick/github-tag-action@1.67.0
32
+ env:
33
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34
+ DEFAULT_BUMP: patch
35
+ WITH_V: true
36
+
37
+ - name: Create GitHub Release
38
+ uses: softprops/action-gh-release@v2
39
+ with:
40
+ tag_name: ${{ steps.tag.outputs.new_tag }}
41
+ files: dist/*
@@ -0,0 +1,39 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ permissions: write-all
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v4
17
+ with:
18
+ python-version: '3.9'
19
+ cache: 'pip'
20
+ - name: Install dependencies
21
+ run: |
22
+ python -m pip install --upgrade pip
23
+ pip install -r requirements/test.txt
24
+ - name: Running tests
25
+ run: |
26
+ pytest --cache-clear --junitxml ./test-report.xml --cov-report term-missing:skip-covered --cov src > pytest-coverage.txt
27
+
28
+ - name: Pytest coverage comment
29
+ if: always()
30
+ uses: MishaKav/pytest-coverage-comment@main
31
+ with:
32
+ pytest-coverage-path: ./pytest-coverage.txt
33
+ junitxml-path: ./test-report.xml
34
+
35
+ - name: Publish test report
36
+ if: always()
37
+ uses: elenakulgavaya/pytest-report-action@v1.3
38
+ with:
39
+ path: test-report.xml
@@ -0,0 +1,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
surety-0.0.1/.pylintrc ADDED
@@ -0,0 +1,44 @@
1
+ [MASTER]
2
+ init-hook='import sys; sys.path.append("./src")'
3
+ ignore=LICENSE,
4
+ pyproject.toml,
5
+ README.md,
6
+ README.rst,
7
+ requirements/,
8
+ pytest.ini,
9
+ setup.cfg,
10
+ pytest-coverage.txt,
11
+ test-report.xml
12
+ ignore-paths=dist,
13
+ fild.egg-info,
14
+ docs
15
+
16
+ py-version=3.7
17
+ suggestion-mode=yes
18
+
19
+ [MESSAGES CONTROL]
20
+ disable=missing-function-docstring,
21
+ missing-class-docstring,
22
+ missing-module-docstring
23
+
24
+ [BASIC]
25
+ good-names=i,
26
+ j,
27
+ k,
28
+ ex,
29
+ tz,
30
+ Run,
31
+ _
32
+
33
+ [DESIGN]
34
+ max-args=10
35
+ max-attributes=7
36
+ max-bool-expr=5
37
+ max-branches=12
38
+ max-locals=15
39
+ max-parents=7
40
+ max-positional-arguments=10
41
+ max-public-methods=20
42
+ max-returns=6
43
+ max-statements=50
44
+ min-public-methods=0
surety-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elena Kulgavaya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
surety-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: surety
3
+ Version: 0.0.1
4
+ Summary: Contract-driven service interaction modeling and test generation.
5
+ Author-email: Elena Kulgavaya <elena.kulgavaya@gmail.com>
6
+ License: MIT
7
+ Project-URL: Bug Tracker, https://github.com/elenakulgavaya/fild/issues
8
+ Keywords: testing,automation,python,pytest plugin
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: Faker==11.3.0
16
+ Requires-Dist: pytz==2021.3
17
+ Dynamic: license-file
18
+
19
+ # Surety
20
+
21
+ AI-native contract testing for modern engineering teams.
22
+
23
+ Generate contracts from real traffic.
24
+ Detect breaking changes with semantic intelligence.
25
+ Measure API contract health.
26
+
27
+ ---
28
+
29
+ ## Why Surety?
30
+
31
+ Contract testing validates your APIs.
32
+ Surety understands them.
33
+
34
+ Most tools answer:
35
+ "Is this change valid?"
36
+
37
+ Surety answers:
38
+ "Is this contract healthy?"
39
+
40
+ ## Keywords
41
+
42
+ AI contract testing, API contract validation, microservices testing, JSON schema validation, breaking change detection.
surety-0.0.1/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Surety
2
+
3
+ AI-native contract testing for modern engineering teams.
4
+
5
+ Generate contracts from real traffic.
6
+ Detect breaking changes with semantic intelligence.
7
+ Measure API contract health.
8
+
9
+ ---
10
+
11
+ ## Why Surety?
12
+
13
+ Contract testing validates your APIs.
14
+ Surety understands them.
15
+
16
+ Most tools answer:
17
+ "Is this change valid?"
18
+
19
+ Surety answers:
20
+ "Is this contract healthy?"
21
+
22
+ ## Keywords
23
+
24
+ AI contract testing, API contract validation, microservices testing, JSON schema validation, breaking change detection.
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=42",
4
+ "setuptools-scm",
5
+ "wheel",
6
+ "Faker==11.3.0",
7
+ "pytz==2021.3",
8
+ ]
9
+ build-backend = "setuptools.build_meta"
10
+
11
+ [project]
12
+ name = "surety"
13
+ description = "Contract-driven service interaction modeling and test generation."
14
+ requires-python = ">=3.7"
15
+ readme = "README.md"
16
+ license = { text = "MIT" }
17
+ authors = [
18
+ {name="Elena Kulgavaya", email="elena.kulgavaya@gmail.com"}
19
+ ]
20
+ dynamic = ["version"]
21
+ keywords = ["testing", "automation", "python", "pytest plugin"]
22
+ dependencies = [
23
+ "Faker==11.3.0",
24
+ "pytz==2021.3",
25
+ ]
26
+ classifiers = [
27
+ "Programming Language :: Python :: 3",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Operating System :: OS Independent",
30
+ ]
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
34
+
35
+ [tool.setuptools.package-dir]
36
+ "" = "src"
37
+
38
+ [tool.setuptools_scm]
39
+ version_scheme = "guess-next-dev"
40
+ local_scheme = "no-local-version"
41
+
42
+ [project.urls]
43
+ "Bug Tracker" = "https://github.com/elenakulgavaya/fild/issues"
@@ -0,0 +1,3 @@
1
+ [pytest]
2
+ addopts = --doctest-modules
3
+ pythonpath = src
@@ -0,0 +1,2 @@
1
+ Faker==11.3.0
2
+ pytz==2021.3
@@ -0,0 +1,4 @@
1
+ -r common.txt
2
+
3
+ pytest==7.4.2
4
+ pytest-cov==4.1.0
surety-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
File without changes
File without changes
@@ -0,0 +1,112 @@
1
+ import inspect
2
+
3
+ from collections.abc import Mapping
4
+
5
+
6
+ def filter_dict(function_or_value, dict_to_filter):
7
+ """
8
+ Filter by value
9
+ >>> filter_dict(123, {'a': 123, 'b': 1234})
10
+ {'b': 1234}
11
+
12
+ Filter by value not applicable
13
+ >>> filter_dict(123, {'a': 1234, 'b': 5123})
14
+ {'a': 1234, 'b': 5123}
15
+
16
+ Embedded filter by value
17
+ >>> filter_dict(123, {'a': {'c': 123}, 'b': 1234})
18
+ {'b': 1234}
19
+
20
+ Embedded with extra by value
21
+ >>> filter_dict(123, {'a': {'c': 123, 'd': 432}, 'b': 1234})
22
+ {'a': {'d': 432}, 'b': 1234}
23
+
24
+ Embedded mixed filter
25
+ >>> filter_dict(123, {'a': {'c': 123, 'd': 432}, 'b': 123, 'e': 'test'})
26
+ {'a': {'d': 432}, 'e': 'test'}
27
+
28
+ Filter by callable
29
+ >>> filter_dict(lambda x: x % 2 == 0, {'a': 532, 'b': 891})
30
+ {'a': 532}
31
+
32
+ Filter by callable not applicable
33
+ >>> filter_dict(lambda x: x % 2 == 0, {'a': 538, 'b': 8})
34
+ {'a': 538, 'b': 8}
35
+
36
+ Embedded filter by callable
37
+ >>> filter_dict(lambda x: bool(x), {'a': {'c': False}, 'b': 'test'})
38
+ {'b': 'test'}
39
+
40
+ Embedded with extra by callable
41
+ >>> filter_dict(
42
+ ... lambda x: 'a' in x, {'a': {'c': 'ba', 'd': 'tt'}, 'b': 'd'})
43
+ {'a': {'c': 'ba'}}
44
+
45
+ Embedded mixed filter
46
+ >>> filter_dict(
47
+ ... lambda x: bool(x), {'a': {'c': True, 'd': 0}, 'b': 'test', 'e': []}
48
+ ... )
49
+ {'a': {'c': True}, 'b': 'test'}
50
+
51
+ """
52
+ func = function_or_value
53
+
54
+ if not callable(function_or_value):
55
+ def new_func(value):
56
+ return value != function_or_value
57
+
58
+ func = new_func
59
+
60
+ result = {}
61
+
62
+ for key, value in dict_to_filter.items():
63
+ if isinstance(value, Mapping):
64
+ value = filter_dict(func, value)
65
+
66
+ if value:
67
+ result[key] = value
68
+
69
+ elif func(value):
70
+ result[key] = value
71
+
72
+ return result
73
+
74
+
75
+ def exclude_none_from_kwargs(kwargs):
76
+ """
77
+ Remove single None value
78
+ >>> exclude_none_from_kwargs({'a': None, 'b': 1234})
79
+ {'b': 1234}
80
+
81
+ Remove multiple None value
82
+ >>> exclude_none_from_kwargs({'a': None, 'b': 1234, 'c': None})
83
+ {'b': 1234}
84
+
85
+ Remove all None values
86
+ >>> exclude_none_from_kwargs({'a': None, 'c': None})
87
+ {}
88
+
89
+ Do nothing when there is no None value
90
+ >>> exclude_none_from_kwargs({'a': 123, 'b': 1234})
91
+ {'a': 123, 'b': 1234}
92
+ """
93
+ return {k: v for k, v in kwargs.items() if v is not None}
94
+
95
+
96
+ def is_callable_with_strict_args(func, args_count=1):
97
+ if not callable(func):
98
+ return False
99
+
100
+ if hasattr(func, 'func'):
101
+ func = func.func
102
+
103
+ if not inspect.isfunction(func):
104
+ raise TypeError(f'Expected function, got {type(func)}')
105
+
106
+ argspec = inspect.getfullargspec(func)
107
+
108
+ if argspec.varkw is None and len(argspec.args) == args_count:
109
+ return True
110
+
111
+ raise TypeError(f'Expected callable with {args_count} args. '
112
+ f'Got: "{func.__name__}" func with {argspec}')