Git Product home page Git Product logo

misc-utils-py's Introduction

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.

misc-utils-py's People

Contributors

dbradf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.