Misc utilities for python projects
Project description
miscutils
Utilities for working with python projects.
Usage
logging_config
Default configuration for structlog.
Configure json logging at the INFO level:
from miscutils.logging_config import default_logging, LogFormat, Verbosity
default_logging(Verbosity.INFO, LogFormat.JSON)
Configure text logging at the DEBUG level:
from miscutils.logging_config import default_logging, LogFormat, Verbosity
default_logging(Verbosity.DEBUG, LogFormat.TEXT)
Configure text logging at the DEBUG level and filter out external loggers:
from miscutils.logging_config import default_logging, LogFormat, Verbosity
default_logging(Verbosity.DEBUG, LogFormat.TEXT, ["extern_logger_1"])
Log timing information for a function
Decorator to add timing information to the logs:
from miscutils.timer import timer
import structlog
@timer(structlog.get_logger(__name__))
def some_function():
pass
Create a namespace relative patch
Create namespace relative patches:
import some_package.sub_package.another_package as under_test
from miscutils.testing import relative_patch_maker
patch = relative_patch_maker(under_test.__name__)
class TestStuff:
#equivalent to @unittest.mock.patch("some_package.sub_package.another_package.something_to_patch")
@patch("something_to_patch")
def test_something(self, patched):
under_test.something()
patched.assert_called_once()
#equivalent to @unittest.mock.patch("some_package.sub_package.another_package.something_else_to_patch")
@patch("something_else_to_patch")
def test_something(self, patched):
under_test.something()
patched.assert_called_once()
Testing
Testing is done via pytest.
$ pip install -r requirements.txt
$ pytest
To get code coverage information, you can run pytest directly.
$ pip install -r requirements.txt
$ pytest --cov=src --cov-report=html
This will generate an html coverage report in htmlcov/
directory.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
misc-utils-py-0.1.2.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for misc_utils_py-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 692fd19d9464d5f1410f24558ec7635aa8bc0dc7e342721db896e60544564177 |
|
MD5 | ed33413053a0a093cbccb0a088a272bb |
|
BLAKE2b-256 | d9b5c8d0cce6662746773f61e58e36f734f3ebe7efcc687e4f9f32bf88e69ecf |